Skip to content
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

Remove or move some Delta Lake product tests #18808

Merged
merged 6 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ public void testRenameColumn()
throw new SkipException("TODO: test not implemented yet");
}

@Override
public void testRenameColumnWithComment()
{
try (TestTable table = new TestTable(
getQueryRunner()::execute,
"test_rename_column_",
"(id INT NOT NULL, col INT COMMENT 'test column comment') WITH (engine = 'MergeTree', order_by = ARRAY['id'])")) {
assertThat(getColumnComment(table.getName(), "col")).isEqualTo("test column comment");

assertUpdate("ALTER TABLE " + table.getName() + " RENAME COLUMN col TO renamed_col");
assertThat(getColumnComment(table.getName(), "renamed_col")).isEqualTo("test column comment");
}
}

@Override
public void testAddColumnWithCommentSpecialCharacter(String comment)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,35 @@ public void testWriterAfterRenameColumnWithColumnMappingMode(String columnMappin
assertUpdate("DROP TABLE " + tableName);
}

/**
* @see deltalake.case_sensitive
*/
@Test
public void testRequiresQueryPartitionFilterWithUppercaseColumnName()
throws Exception
{
String tableName = "test_require_partition_filter_" + randomNameSuffix();
Path tableLocation = Files.createTempFile(tableName, null);
copyDirectoryContents(new File(Resources.getResource("deltalake/case_sensitive").toURI()).toPath(), tableLocation);

assertUpdate("CALL system.register_table('%s', '%s', '%s')".formatted(getSession().getSchema().orElseThrow(), tableName, tableLocation.toUri()));
assertQueryReturnsEmptyResult("SELECT * FROM " + tableName);

assertUpdate("INSERT INTO " + tableName + " VALUES (1, 11), (2, 22)", 2);

assertQuery("SELECT * FROM " + tableName, "VALUES (1, 11), (2, 22)");

Session session = Session.builder(getSession())
.setCatalogSessionProperty(getSession().getCatalog().orElseThrow(), "query_partition_filter_required", "true")
.build();

assertQuery(format("SELECT * FROM %s WHERE \"part\" = 11", tableName), "VALUES (1, 11)");
assertQuery(format("SELECT * FROM %s WHERE \"PART\" = 11", tableName), "VALUES (1, 11)");
assertQuery(format("SELECT * FROM %s WHERE \"Part\" = 11", tableName), "VALUES (1, 11)");

assertUpdate("DROP TABLE " + tableName);
}

/**
* @see deltalake.case_sensitive
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,40 @@ public void testRenameColumn()
.hasMessageContaining("Cannot rename column in table using column mapping mode NONE");
}

@Override
public void testRenameColumnWithComment()
{
// Override because the connector doesn't support renaming columns with 'none' column mapping
// There are some tests in in io.trino.tests.product.deltalake.TestDeltaLakeColumnMappingMode
assertThatThrownBy(super::testRenameColumnWithComment)
.hasMessageContaining("Cannot rename column in table using column mapping mode NONE");
}

@Test(dataProvider = "columnMappingModeDataProvider")
public void testDeltaRenameColumnWithComment(ColumnMappingMode mode)
{
if (mode == ColumnMappingMode.NONE) {
throw new SkipException("The connector doesn't support renaming columns with 'none' column mapping");
}

String tableName = "test_rename_column_" + randomNameSuffix();
assertUpdate("" +
"CREATE TABLE " + tableName +
"(col INT COMMENT 'test column comment', part INT COMMENT 'test partition comment')" +
"WITH (" +
"partitioned_by = ARRAY['part']," +
"location = 's3://" + bucketName + "/databricks-compatibility-test-" + tableName + "'," +
"column_mapping_mode = '" + mode + "')");

assertUpdate("ALTER TABLE " + tableName + " RENAME COLUMN col TO new_col");
assertEquals(getColumnComment(tableName, "new_col"), "test column comment");

assertUpdate("ALTER TABLE " + tableName + " RENAME COLUMN part TO new_part");
assertEquals(getColumnComment(tableName, "new_part"), "test partition comment");

assertUpdate("DROP TABLE " + tableName);
}

@Override
public void testAlterTableRenameColumnToLongName()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1657,38 +1657,6 @@ public void testDropNonLowercaseColumnWithColumnMappingMode(String mode)
}
}

@Test(groups = {DELTA_LAKE_DATABRICKS, DELTA_LAKE_OSS, DELTA_LAKE_EXCLUDE_91, DELTA_LAKE_EXCLUDE_104, PROFILE_SPECIFIC_TESTS})
@Flaky(issue = DATABRICKS_COMMUNICATION_FAILURE_ISSUE, match = DATABRICKS_COMMUNICATION_FAILURE_MATCH)
public void testUnsupportedDropColumnWithColumnMappingModeNone()
{
String tableName = "test_unsupported_drop_column_" + randomNameSuffix();

onDelta().executeQuery("" +
"CREATE TABLE default." + tableName +
" (id INT, data INT, part STRING)" +
" USING delta " +
" PARTITIONED BY (part) " +
" LOCATION 's3://" + bucketName + "/databricks-compatibility-test-" + tableName + "'" +
" TBLPROPERTIES ('delta.columnMapping.mode' = 'none')");

try {
onDelta().executeQuery("INSERT INTO default." + tableName + " VALUES (1, 10, 'part#1')");

assertQueryFailure(() -> onTrino().executeQuery("ALTER TABLE delta.default." + tableName + " DROP COLUMN part"))
.hasMessageContaining("Cannot drop column from table using column mapping mode NONE");
assertQueryFailure(() -> onDelta().executeQuery("ALTER TABLE default." + tableName + " DROP COLUMN part"))
.hasMessageContaining("DROP COLUMN is not supported for your Delta table");

assertThat(onTrino().executeQuery("SELECT * FROM delta.default." + tableName))
.containsOnly(row(1, 10, "part#1"));
assertThat(onDelta().executeQuery("SELECT * FROM default." + tableName))
.containsOnly(row(1, 10, "part#1"));
}
finally {
dropDeltaTableWithRetry("default." + tableName);
}
}

@Test(groups = {DELTA_LAKE_DATABRICKS, DELTA_LAKE_OSS, DELTA_LAKE_EXCLUDE_91, DELTA_LAKE_EXCLUDE_104, PROFILE_SPECIFIC_TESTS}, dataProvider = "columnMappingDataProvider")
@Flaky(issue = DATABRICKS_COMMUNICATION_FAILURE_ISSUE, match = DATABRICKS_COMMUNICATION_FAILURE_MATCH)
public void testTrinoRenameColumnWithColumnMappingMode(String mode)
Expand Down Expand Up @@ -1805,33 +1773,6 @@ public void testTrinoExtendedStatisticsRenameColumnWithColumnMappingMode(String
}
}

@Test(groups = {DELTA_LAKE_DATABRICKS, DELTA_LAKE_OSS, DELTA_LAKE_EXCLUDE_91, DELTA_LAKE_EXCLUDE_104, PROFILE_SPECIFIC_TESTS}, dataProvider = "columnMappingDataProvider")
@Flaky(issue = DATABRICKS_COMMUNICATION_FAILURE_ISSUE, match = DATABRICKS_COMMUNICATION_FAILURE_MATCH)
public void testRenameColumnWithComment(String mode)
{
String tableName = "test_rename_column_with_comment_" + randomNameSuffix();

onDelta().executeQuery("" +
"CREATE TABLE default." + tableName +
" (col INT COMMENT 'test column comment', part INT COMMENT 'test partition comment')" +
" USING delta" +
" PARTITIONED BY (part)" +
" LOCATION 's3://" + bucketName + "/databricks-compatibility-test-" + tableName + "'" +
" TBLPROPERTIES ('delta.columnMapping.mode' = '" + mode + "')");
try {
onTrino().executeQuery("ALTER TABLE delta.default." + tableName + " RENAME COLUMN col TO new_col");
assertEquals(getColumnCommentOnTrino("default", tableName, "new_col"), "test column comment");
assertEquals(getColumnCommentOnDelta("default", tableName, "new_col"), "test column comment");

onTrino().executeQuery("ALTER TABLE delta.default." + tableName + " RENAME COLUMN part TO new_part");
assertEquals(getColumnCommentOnTrino("default", tableName, "new_part"), "test partition comment");
assertEquals(getColumnCommentOnDelta("default", tableName, "new_part"), "test partition comment");
}
finally {
dropDeltaTableWithRetry(tableName);
}
}

@Test(groups = {DELTA_LAKE_DATABRICKS, DELTA_LAKE_OSS, DELTA_LAKE_EXCLUDE_91, DELTA_LAKE_EXCLUDE_104, PROFILE_SPECIFIC_TESTS}, dataProvider = "columnMappingDataProvider")
@Flaky(issue = DATABRICKS_COMMUNICATION_FAILURE_ISSUE, match = DATABRICKS_COMMUNICATION_FAILURE_MATCH)
public void testRenameNonLowercaseColumn(String mode)
Expand Down Expand Up @@ -1880,42 +1821,6 @@ public void testRenameNonLowercaseColumn(String mode)
}
}

@Test(groups = {DELTA_LAKE_DATABRICKS, DELTA_LAKE_OSS, DELTA_LAKE_EXCLUDE_91, DELTA_LAKE_EXCLUDE_104, PROFILE_SPECIFIC_TESTS})
@Flaky(issue = DATABRICKS_COMMUNICATION_FAILURE_ISSUE, match = DATABRICKS_COMMUNICATION_FAILURE_MATCH)
public void testUnsupportedRenameColumnWithColumnMappingModeNone()
{
String tableName = "test_unsupported_rename_column_" + randomNameSuffix();

onDelta().executeQuery("" +
"CREATE TABLE default." + tableName +
" (id INT, data INT)" +
" USING delta " +
" LOCATION 's3://" + bucketName + "/databricks-compatibility-test-" + tableName + "'" +
" TBLPROPERTIES ('delta.columnMapping.mode' = 'none')");

try {
onDelta().executeQuery("INSERT INTO default." + tableName + " VALUES (1, 10)");

assertQueryFailure(() -> onTrino().executeQuery("ALTER TABLE delta.default." + tableName + " RENAME COLUMN data TO new_data"))
.hasMessageContaining("Cannot rename column in table using column mapping mode NONE");
assertQueryFailure(() -> onDelta().executeQuery("ALTER TABLE default." + tableName + " RENAME COLUMN data TO new_data"))
.hasMessageContaining(" Column rename is not supported for your Delta table");

assertThat(onTrino().executeQuery("DESCRIBE delta.default." + tableName))
.containsOnly(
row("id", "integer", "", ""),
row("data", "integer", "", ""));

assertThat(onTrino().executeQuery("SELECT * FROM delta.default." + tableName))
.containsOnly(row(1, 10));
assertThat(onDelta().executeQuery("SELECT * FROM default." + tableName))
.containsOnly(row(1, 10));
}
finally {
dropDeltaTableWithRetry(tableName);
}
}

@DataProvider
public Object[][] columnMappingDataProvider()
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2818,6 +2818,19 @@ public void testRenameColumn()
assertFalse(getQueryRunner().tableExists(getSession(), tableName));
}

@Test
public void testRenameColumnWithComment()
{
skipTestUnless(hasBehavior(SUPPORTS_RENAME_COLUMN) && hasBehavior(SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT));

try (TestTable table = new TestTable(getQueryRunner()::execute, "test_rename_column_", "(col INT COMMENT 'test column comment')")) {
assertThat(getColumnComment(table.getName(), "col")).isEqualTo("test column comment");

assertUpdate("ALTER TABLE " + table.getName() + " RENAME COLUMN col TO renamed_col");
assertThat(getColumnComment(table.getName(), "renamed_col")).isEqualTo("test column comment");
}
}

@Test
public void testRenameRowField()
{
Expand Down
Loading