- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.4k
Support Iceberg Identifier fields #27026
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|  | @@ -1485,6 +1485,72 @@ public void testMetadataDeleteAfterCommitEnabled() | |||||
| assertUpdate("DROP TABLE " + tableName); | ||||||
| } | ||||||
|  | ||||||
| @Test | ||||||
| public void testCreateTableWithIdentifierFields() | ||||||
| { | ||||||
| try (TestTable table = newTrinoTable("test_identifier_fields", | ||||||
| "(id BIGINT NOT NULL, name VARCHAR NOT NULL) WITH (identifier_fields = ARRAY['id'])")) { | ||||||
|  | ||||||
| BaseTable icebergTable = loadTable(table.getName()); | ||||||
| assertThat((String) computeScalar("SHOW CREATE TABLE " + table.getName())) | ||||||
| .contains("identifier_fields = ARRAY['id']"); | ||||||
| Set<String> identifierFieldNames = icebergTable.schema().identifierFieldNames(); | ||||||
| assertThat(identifierFieldNames).containsExactlyInAnyOrder("id"); | ||||||
|  | ||||||
| assertUpdate("ALTER TABLE " + table.getName() + " SET PROPERTIES identifier_fields = ARRAY['name']"); | ||||||
| icebergTable = loadTable(table.getName()); | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (testing): Test assertion expects 'id' and 'area' as identifier fields after update, but the update sets 'name' and 'area'. Please confirm which fields should be identifiers after the update and update the assertion to match. | ||||||
| assertThat((String) computeScalar("SHOW CREATE TABLE " + table.getName())) | ||||||
| .contains("identifier_fields = ARRAY['name']"); | ||||||
| identifierFieldNames = icebergTable.schema().identifierFieldNames(); | ||||||
| assertThat(identifierFieldNames).containsExactlyInAnyOrder("name"); | ||||||
| } | ||||||
| } | ||||||
|  | ||||||
| @Test | ||||||
| public void testCreateTableWithMutilIdentifierFields() | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick (typo): Typo in test name: 'Mutil' should be 'Multi'. Rename the test to 'testCreateTableWithMultiIdentifierFields' for consistency. 
        Suggested change
       
 | ||||||
| { | ||||||
| try (TestTable table = newTrinoTable("test_identifier_fields", | ||||||
| "(id BIGINT NOT NULL, name VARCHAR NOT NULL, area INT NOT NULL) WITH (identifier_fields = ARRAY['id','name'])")) { | ||||||
| BaseTable icebergTable = loadTable(table.getName()); | ||||||
| assertThat((String) computeScalar("SHOW CREATE TABLE " + table.getName())) | ||||||
| .containsAnyOf("identifier_fields = ARRAY['id','name']", "identifier_fields = ARRAY['name','id']"); | ||||||
| Set<String> identifierFieldNames = icebergTable.schema().identifierFieldNames(); | ||||||
| assertThat(identifierFieldNames).containsExactlyInAnyOrder("id", "name"); | ||||||
|  | ||||||
| assertUpdate("ALTER TABLE " + table.getName() + " SET PROPERTIES identifier_fields = ARRAY['name','area']"); | ||||||
| icebergTable = loadTable(table.getName()); | ||||||
| assertThat((String) computeScalar("SHOW CREATE TABLE " + table.getName())) | ||||||
| .containsAnyOf("identifier_fields = ARRAY['name','area']", "identifier_fields = ARRAY['area', 'name']"); | ||||||
| identifierFieldNames = icebergTable.schema().identifierFieldNames(); | ||||||
| assertThat(identifierFieldNames).containsExactlyInAnyOrder("id", "area"); | ||||||
| } | ||||||
| } | ||||||
|  | ||||||
| @Test | ||||||
| public void testUpdateIdentifierFields() | ||||||
| { | ||||||
| try (TestTable table = newTrinoTable("test_identifier_fields", | ||||||
| "(id BIGINT NOT NULL, name VARCHAR NOT NULL, area INT)")) { | ||||||
| BaseTable icebergTable = loadTable(table.getName()); | ||||||
|  | ||||||
| Set<String> identifierFieldNames = icebergTable.schema().identifierFieldNames(); | ||||||
| assertThat(identifierFieldNames).isEmpty(); | ||||||
|  | ||||||
| assertThat(query("ALTER TABLE " + table.getName() + " SET PROPERTIES identifier_fields = ARRAY['not_exist_col']")) | ||||||
| .failure() | ||||||
| .hasMessage("Field 'not_exist_col' does not exist"); | ||||||
|  | ||||||
| assertThat(query("ALTER TABLE " + table.getName() + " SET PROPERTIES identifier_fields = ARRAY['area']")) | ||||||
| .failure() | ||||||
| .hasMessage("Identifier field 'area' cannot be optional"); | ||||||
|  | ||||||
| assertUpdate("ALTER TABLE " + table.getName() + " SET PROPERTIES identifier_fields = ARRAY[]"); | ||||||
| icebergTable.refresh(); | ||||||
| identifierFieldNames = icebergTable.schema().identifierFieldNames(); | ||||||
| assertThat(identifierFieldNames).isEmpty(); | ||||||
| } | ||||||
| } | ||||||
|  | ||||||
| @Test | ||||||
| void testAnalyzeNoSnapshot() | ||||||
| { | ||||||
|  | ||||||
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.
suggestion: Consider validating identifier fields for duplicates before updating.
The code does not verify that identifierFields contains unique field names. Adding this check will help prevent bugs from duplicate entries.