-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Support inserting into Delta Lake table having invariants #16136
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 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 |
|---|---|---|
|
|
@@ -160,13 +160,22 @@ public void testWritesLockInvalidContents(String writeStatement, String expected | |
| } | ||
|
|
||
| @Test | ||
| public void testReadingTableWithDeltaColumnInvariant() | ||
| public void testDeltaColumnInvariant() | ||
| { | ||
| assertThat(getQueryRunner().execute("SELECT * FROM invariants").getRowCount()).isEqualTo(1); | ||
| assertThatThrownBy(() -> query("INSERT INTO invariants VALUES(2)")) | ||
| .hasMessageContaining("Inserts are not supported for tables with delta invariants"); | ||
| assertThatThrownBy(() -> query("UPDATE invariants SET dummy = 3 WHERE dummy = 1")) | ||
| .hasMessageContaining("Updates are not supported for tables with delta invariants"); | ||
| String tableName = "test_invariants_" + randomNameSuffix(); | ||
| hiveMinioDataLake.copyResources("databricks/invariants", tableName); | ||
| assertUpdate("CALL system.register_table('%s', '%s', '%s')".formatted(SCHEMA, tableName, getLocationForTable(bucketName, tableName))); | ||
|
|
||
| assertQuery("SELECT * FROM " + tableName, "VALUES 1"); | ||
| assertUpdate("INSERT INTO " + tableName + " VALUES(2)", 1); | ||
| assertQuery("SELECT * FROM " + tableName, "VALUES (1), (2)"); | ||
|
|
||
| assertThatThrownBy(() -> query("INSERT INTO " + tableName + " VALUES(3)")) | ||
| .hasMessageContaining("Check constraint violation: (\"dummy\" < 3)"); | ||
| assertThatThrownBy(() -> query("UPDATE " + tableName + " SET dummy = 3 WHERE dummy = 1")) | ||
| .hasMessageContaining("Updating a table with a check constraint is not supported"); | ||
|
|
||
| assertQuery("SELECT * FROM " + tableName, "VALUES (1), (2)"); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -180,15 +189,18 @@ public void testSchemaEvolutionOnTableWithColumnInvariant() | |
| tableName, | ||
| getLocationForTable(bucketName, tableName))); | ||
|
|
||
| assertThatThrownBy(() -> query("INSERT INTO invariants VALUES(2)")) | ||
| .hasMessageContaining("Inserts are not supported for tables with delta invariants"); | ||
|
Comment on lines
183
to
184
Member
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. How was that working? Shouldn't it be failing with table not found?
Member
Author
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. Not sure if I understand the question correctly. The previous table name was |
||
| assertThatThrownBy(() -> query("INSERT INTO " + tableName + " VALUES(3)")) | ||
| .hasMessageContaining("Check constraint violation: (\"dummy\" < 3)"); | ||
|
|
||
| assertUpdate("ALTER TABLE " + tableName + " ADD COLUMN c INT"); | ||
| assertUpdate("COMMENT ON COLUMN " + tableName + ".c IS 'example column comment'"); | ||
| assertUpdate("COMMENT ON TABLE " + tableName + " IS 'example table comment'"); | ||
|
|
||
| assertThatThrownBy(() -> query("INSERT INTO " + tableName + " VALUES(2, 2)")) | ||
|
ebyhr marked this conversation as resolved.
Outdated
|
||
| .hasMessageContaining("Inserts are not supported for tables with delta invariants"); | ||
| assertThatThrownBy(() -> query("INSERT INTO " + tableName + " VALUES(3, 30)")) | ||
| .hasMessageContaining("Check constraint violation: (\"dummy\" < 3)"); | ||
|
|
||
| assertUpdate("INSERT INTO " + tableName + " VALUES(2, 20)", 1); | ||
| assertQuery("SELECT * FROM " + tableName, "VALUES (1, NULL), (2, 20)"); | ||
| } | ||
|
|
||
| @DataProvider | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.