-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Core: Implement BaseMetastoreCatalog.registerTable() #5037
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
Changes from 4 commits
97c5a88
2654ec4
3a18e8b
a7d4b53
65a33be
984115b
58e6385
1cc00f3
8f9d9c9
d2ac693
ec18ade
3ef237a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,9 @@ | |
| import org.apache.iceberg.TableOperations; | ||
| import org.apache.iceberg.avro.AvroSchemaUtil; | ||
| import org.apache.iceberg.catalog.TableIdentifier; | ||
| import org.apache.iceberg.exceptions.AlreadyExistsException; | ||
| import org.apache.iceberg.exceptions.CommitFailedException; | ||
| import org.apache.iceberg.exceptions.NotFoundException; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
| import org.apache.iceberg.types.Types; | ||
| import org.assertj.core.api.Assertions; | ||
|
|
@@ -56,6 +58,7 @@ | |
| import org.projectnessie.model.ImmutableTableReference; | ||
| import org.projectnessie.model.LogResponse.LogEntry; | ||
| import org.projectnessie.model.Operation; | ||
| import org.projectnessie.model.Tag; | ||
|
|
||
| import static org.apache.iceberg.TableMetadataParser.getFileExtension; | ||
| import static org.apache.iceberg.types.Types.NestedField.optional; | ||
|
|
@@ -385,6 +388,81 @@ public void testDropTable() throws IOException { | |
| verifyCommitMetadata(); | ||
| } | ||
|
|
||
| private void testRegister(TableIdentifier identifier, String metadataVersionFiles) { | ||
|
||
| Assertions.assertThat(catalog.registerTable(identifier, "file:" + metadataVersionFiles)).isNotNull(); | ||
| Table newTable = catalog.loadTable(identifier); | ||
| Assertions.assertThat(newTable).isNotNull(); | ||
| TableOperations ops = ((HasTableOperations) newTable).operations(); | ||
| String metadataLocation = ((NessieTableOperations) ops).currentMetadataLocation(); | ||
| Assertions.assertThat("file:" + metadataVersionFiles).isEqualTo(metadataLocation); | ||
| Assertions.assertThat(catalog.dropTable(identifier, false)).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRegisterTableWithGivenBranch() { | ||
| List<String> metadataVersionFiles = metadataVersionFiles(TABLE_NAME); | ||
| Assertions.assertThat(1).isEqualTo(metadataVersionFiles.size()); | ||
| ImmutableTableReference tableReference = | ||
| ImmutableTableReference.builder().reference("main").name(TABLE_NAME).build(); | ||
| TableIdentifier identifier = TableIdentifier.of(DB_NAME, tableReference.toString()); | ||
| testRegister(identifier, metadataVersionFiles.get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRegisterTableNegativeScenarios() throws NessieConflictException, NessieNotFoundException { | ||
Mehul2500 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Mehul2500 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| List<String> metadataVersionFiles = metadataVersionFiles(TABLE_NAME); | ||
| Assertions.assertThat(1).isEqualTo(metadataVersionFiles.size()); | ||
| // Case 1: Branch does not exist | ||
| Assertions.assertThatThrownBy( | ||
| () -> catalog.registerTable( | ||
| TableIdentifier.of(DB_NAME, "`" + TABLE_NAME + "`@default"), | ||
| "file:" + metadataVersionFiles.get(0))) | ||
| .isInstanceOf(IllegalArgumentException.class) | ||
| .hasMessage("Nessie ref 'default' does not exist"); | ||
| // Case 2: Table Already Exists | ||
| Assertions.assertThatThrownBy(() -> catalog.registerTable(TABLE_IDENTIFIER, "file:" + metadataVersionFiles.get(0))) | ||
| .isInstanceOf(AlreadyExistsException.class) | ||
| .hasMessage("Table already exists: db.tbl"); | ||
| // Case 3: Registering using a tag | ||
| api.createReference().sourceRefName(BRANCH).reference(Tag.of("tag_1", catalog.currentHash())).create(); | ||
| Assertions.assertThatThrownBy( | ||
| () -> catalog.registerTable( | ||
| TableIdentifier.of(DB_NAME, "`" + TABLE_NAME + "`@tag_1"), | ||
Mehul2500 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "file:" + metadataVersionFiles.get(0))) | ||
| .isInstanceOf(IllegalArgumentException.class) | ||
| .hasMessage("You can only mutate tables when using a branch without a hash or timestamp."); | ||
| // Case 4: non-null metadata path with null metadata location | ||
| Assertions.assertThat(catalog.dropTable(TABLE_IDENTIFIER, false)).isTrue(); | ||
| Assertions.assertThatThrownBy( | ||
| () -> catalog.registerTable(TABLE_IDENTIFIER, "file:" + metadataVersionFiles.get(0) + "invalidName")) | ||
| .isInstanceOf(NotFoundException.class); | ||
| // Case 5: null identifier | ||
| Assertions.assertThatThrownBy( | ||
| () -> catalog.registerTable(null, "file:" + metadataVersionFiles.get(0) + "invalidName")) | ||
| .isInstanceOf(IllegalArgumentException.class) | ||
| .hasMessage("Invalid identifier: null"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRegisterTableWithDefaultBranch() { | ||
| List<String> metadataVersionFiles = metadataVersionFiles(TABLE_NAME); | ||
| Assertions.assertThat(1).isEqualTo(metadataVersionFiles.size()); | ||
| Assertions.assertThat(catalog.dropTable(TABLE_IDENTIFIER, false)).isTrue(); | ||
| testRegister(TABLE_IDENTIFIER, metadataVersionFiles.get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRegisterTableMoreThanOneBranch() { | ||
Mehul2500 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| List<String> metadataVersionFiles = metadataVersionFiles(TABLE_NAME); | ||
| Assertions.assertThat(1).isEqualTo(metadataVersionFiles.size()); | ||
| ImmutableTableReference tableReference = | ||
| ImmutableTableReference.builder().reference("main").name(TABLE_NAME).build(); | ||
| TableIdentifier identifier = TableIdentifier.of(DB_NAME, tableReference.toString()); | ||
| testRegister(identifier, metadataVersionFiles.get(0)); | ||
| Assertions.assertThat(catalog.dropTable(TABLE_IDENTIFIER, false)).isTrue(); | ||
| testRegister(TABLE_IDENTIFIER, metadataVersionFiles.get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExistingTableUpdate() { | ||
| Table icebergTable = catalog.loadTable(TABLE_IDENTIFIER); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.