-
Notifications
You must be signed in to change notification settings - Fork 5
Add view support in GlueSync #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e0c421e
testing views
a218c75
just ugprade gluesync
a61ca70
version
bf91062
also add view sync in batch
e28e850
changelog
07d0e87
Review comments
7bc484f
changelog
df6443a
Add to shading
99b6b7d
description
b494c3f
Fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| import com.hotels.hcommon.hive.metastore.iterator.PartitionIterator; | ||
|
|
||
| public class GlueSyncCli { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(GlueSyncCli.class); | ||
|
|
||
| private static final String THRIFT_CONNECTION_URI = System.getenv("THRIFT_CONNECTION_URI"); | ||
|
|
@@ -108,9 +109,10 @@ public void syncAll(CommandLine cmd) throws TException { | |
|
|
||
| boolean continueOnError = cmd.hasOption("continueOnError"); | ||
| boolean deleteGluePartitions = !cmd.hasOption("keep-glue-partitions"); | ||
| boolean syncOnlyViews = cmd.hasOption("sync-only-views"); | ||
|
|
||
| logger.debug("Additional parameters: continueOnError={}, deleteGluePartitions={}", continueOnError, | ||
| deleteGluePartitions); | ||
| logger.debug("Additional parameters: continueOnError={}, deleteGluePartitions={}, syncOnlyViews={}", | ||
| continueOnError, deleteGluePartitions, syncOnlyViews); | ||
|
|
||
| boolean hadError = false; | ||
| for (String dbName : metastoreClient.getAllDatabases()) { | ||
|
|
@@ -120,7 +122,7 @@ public void syncAll(CommandLine cmd) throws TException { | |
| if (tableName.matches(tableRegex)) { | ||
| try { | ||
| logger.info("Syncing table: {} in database: {}", tableName, dbName); | ||
| syncTable(dbName, tableName, deleteGluePartitions, verbose); | ||
| syncTable(dbName, tableName, deleteGluePartitions, syncOnlyViews, verbose); | ||
| } catch (Exception e) { | ||
| hadError = true; | ||
| logger.error("Error syncing table: {} in database: {}: {}", tableName, dbName, e.getMessage()); | ||
|
|
@@ -139,8 +141,8 @@ public void syncAll(CommandLine cmd) throws TException { | |
| } | ||
| } | ||
|
|
||
| private void syncTable(String dbName, String tableName, boolean deleteGluePartitions, boolean verbose) | ||
| throws TException { | ||
| private void syncTable(String dbName, String tableName, boolean deleteGluePartitions, boolean syncOnlyViews, | ||
|
||
| boolean verbose) throws TException { | ||
| Database database = metastoreClient.getDatabase(dbName); | ||
|
|
||
| if (!glueDatabaseService.exists(database)) { | ||
|
|
@@ -150,6 +152,14 @@ private void syncTable(String dbName, String tableName, boolean deleteGluePartit | |
|
|
||
| Table table = metastoreClient.getTable(dbName, tableName); | ||
|
|
||
| if (syncOnlyViews) { | ||
| String type = table.getTableType(); | ||
| if (type != null && !type.equalsIgnoreCase("VIRTUAL_VIEW")) { | ||
| logger.info("Table {}.{} is not a view, skipping as syncOnlyViews flag is active", dbName, tableName); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| CreateTableEvent createTableEvent = new CreateTableEvent(table, true, null); | ||
| apiaryGlueSync.onCreateTable(createTableEvent); | ||
|
|
||
|
|
@@ -176,5 +186,4 @@ protected Iterator<Partition> createPartitionIterator(IMetaStoreClient metastore | |
| throws org.apache.hadoop.hive.metastore.api.MetaException, org.apache.thrift.TException { | ||
| return new PartitionIterator(metastoreClient, table, DEFAULT_PARTITION_BATCH_SIZE); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we make this a bit more flexible:
sync-types=[view,table,database]There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or just support view, table and [view,table] for both