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

Disallow creating Delta tables partitioned by all columns #18354

Merged
merged 1 commit into from
Jul 24, 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 @@ -1078,6 +1078,9 @@ private static void checkPartitionColumns(List<ColumnMetadata> columns, List<Str
if (!invalidPartitionNames.isEmpty()) {
throw new TrinoException(DELTA_LAKE_INVALID_SCHEMA, "Table property 'partition_by' contained column names which do not exist: " + invalidPartitionNames);
}
if (columns.size() == partitionColumnNames.size()) {
throw new TrinoException(DELTA_LAKE_INVALID_SCHEMA, "Using all columns for partition columns is unsupported");
}
}

private void checkColumnTypes(List<ColumnMetadata> columnMetadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,24 @@ public void testPartitionColumnOrderIsDifferentFromTableDefinition()
assertQuery("SELECT * FROM " + tableName, "VALUES (1, 'first#1', 'second#1'), (2, 'first#2', NULL), (3, NULL, 'second#3'), (4, NULL, NULL)");
}

@Test
public void testCreateTableWithAllPartitionColumns()
{
String tableName = "test_create_table_all_partition_columns_" + randomNameSuffix();
assertQueryFails(
"CREATE TABLE " + tableName + "(part INT) WITH (partitioned_by = ARRAY['part'])",
"Using all columns for partition columns is unsupported");
}

@Test
public void testCreateTableAsSelectAllPartitionColumns()
{
String tableName = "test_create_table_all_partition_columns_" + randomNameSuffix();
assertQueryFails(
"CREATE TABLE " + tableName + " WITH (partitioned_by = ARRAY['part']) AS SELECT 1 part",
"Using all columns for partition columns is unsupported");
}

@Test
public void testCreateTableWithUnsupportedPartitionType()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,43 @@ public void testCreateTableWithUnsupportedPartitionType()
dropDeltaTableWithRetry("default." + tableName);
}
}

@Test(groups = {DELTA_LAKE_DATABRICKS, PROFILE_SPECIFIC_TESTS})
@Flaky(issue = DATABRICKS_COMMUNICATION_FAILURE_ISSUE, match = DATABRICKS_COMMUNICATION_FAILURE_MATCH)
public void testCreateTableAsSelectWithAllPartitionColumns()
{
String tableName = "test_dl_ctas_with_all_partition_columns_" + randomNameSuffix();
String tableDirectory = "databricks-compatibility-test-" + tableName;

try {
assertThatThrownBy(() -> onTrino().executeQuery("" +
"CREATE TABLE delta.default." + tableName + " " +
"WITH (partitioned_by = ARRAY['part'], location = 's3://" + bucketName + "/" + tableDirectory + "')" +
"AS SELECT 1 part"))
.hasMessageContaining("Using all columns for partition columns is unsupported");
assertThatThrownBy(() -> onTrino().executeQuery("" +
"CREATE TABLE delta.default." + tableName + " " +
"WITH (partitioned_by = ARRAY['part', 'another_part'], location = 's3://" + bucketName + "/" + tableDirectory + "')" +
"AS SELECT 1 part, 2 another_part"))
.hasMessageContaining("Using all columns for partition columns is unsupported");

assertThatThrownBy(() -> onDelta().executeQuery("" +
"CREATE TABLE default." + tableName + " " +
"USING DELTA " +
"PARTITIONED BY (part)" +
"LOCATION 's3://" + bucketName + "/" + tableDirectory + "'" +
"AS SELECT 1 part"))
.hasMessageContaining("Cannot use all columns for partition columns");
assertThatThrownBy(() -> onDelta().executeQuery("" +
"CREATE TABLE default." + tableName + " " +
"USING DELTA " +
"PARTITIONED BY (part, another_part)" +
"LOCATION 's3://" + bucketName + "/" + tableDirectory + "'" +
"SELECT 1 part, 2 another_part"))
.hasMessageContaining("Cannot use all columns for partition columns");
}
finally {
dropDeltaTableWithRetry("default." + tableName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,41 @@ public void testCreateTableWithUnsupportedPartitionType()
}
}

@Test(groups = {DELTA_LAKE_DATABRICKS, PROFILE_SPECIFIC_TESTS})
@Flaky(issue = DATABRICKS_COMMUNICATION_FAILURE_ISSUE, match = DATABRICKS_COMMUNICATION_FAILURE_MATCH)
public void testCreateTableWithAllPartitionColumns()
{
String tableName = "test_dl_create_table_with_all_partition_columns_" + randomNameSuffix();
String tableDirectory = "databricks-compatibility-test-" + tableName;

try {
assertThatThrownBy(() -> onTrino().executeQuery("" +
"CREATE TABLE delta.default." + tableName + "(part int)" +
"WITH (partitioned_by = ARRAY['part'], location = 's3://" + bucketName + "/" + tableDirectory + "')"))
.hasMessageContaining("Using all columns for partition columns is unsupported");
assertThatThrownBy(() -> onTrino().executeQuery("" +
"CREATE TABLE delta.default." + tableName + "(part int, another_part int)" +
"WITH (partitioned_by = ARRAY['part', 'another_part'], location = 's3://" + bucketName + "/" + tableDirectory + "')"))
.hasMessageContaining("Using all columns for partition columns is unsupported");

assertThatThrownBy(() -> onDelta().executeQuery("" +
"CREATE TABLE default." + tableName + "(part int)" +
"USING DELTA " +
"PARTITIONED BY (part)" +
"LOCATION 's3://" + bucketName + "/" + tableDirectory + "'"))
.hasMessageContaining("Cannot use all columns for partition columns");
assertThatThrownBy(() -> onDelta().executeQuery("" +
"CREATE TABLE default." + tableName + "(part int, another_part int)" +
"USING DELTA " +
"PARTITIONED BY (part, another_part)" +
"LOCATION 's3://" + bucketName + "/" + tableDirectory + "'"))
.hasMessageContaining("Cannot use all columns for partition columns");
}
finally {
dropDeltaTableWithRetry("default." + tableName);
}
}

private String getDatabricksDefaultTableProperties()
{
if (databricksRuntimeVersion.isAtLeast(DATABRICKS_113_RUNTIME_VERSION)) {
Expand Down