Skip to content

Display Hive partition projection column properties #18076

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

Merged
merged 1 commit into from
Jun 29, 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 @@ -99,7 +99,7 @@ public Map<String, Object> getPartitionProjectionTrinoTableProperties(Table tabl
return trinoTablePropertiesBuilder.buildOrThrow();
}

public Map<String, Object> getPartitionProjectionTrinoColumnProperties(Table table, String columnName)
public static Map<String, Object> getPartitionProjectionTrinoColumnProperties(Table table, String columnName)
{
Map<String, String> metastoreTableProperties = table.getParameters();
return rewriteColumnProjectionProperties(metastoreTableProperties, columnName);
Expand Down Expand Up @@ -293,7 +293,7 @@ else if (!columnProjections.isEmpty()) {
return new PartitionProjection(projectionEnabledProperty.orElse(false), storageLocationTemplate, columnProjections);
}

private Map<String, Object> rewriteColumnProjectionProperties(Map<String, String> metastoreTableProperties, String columnName)
private static Map<String, Object> rewriteColumnProjectionProperties(Map<String, String> metastoreTableProperties, String columnName)
{
ImmutableMap.Builder<String, Object> trinoTablePropertiesBuilder = ImmutableMap.builder();
rewriteProperty(
Expand All @@ -307,13 +307,13 @@ private Map<String, Object> rewriteColumnProjectionProperties(Map<String, String
trinoTablePropertiesBuilder,
getMetastoreProjectionPropertyKey(columnName, COLUMN_PROJECTION_VALUES_SUFFIX),
COLUMN_PROJECTION_VALUES,
this::splitCommaSeparatedString);
PartitionProjectionService::splitCommaSeparatedString);
rewriteProperty(
metastoreTableProperties,
trinoTablePropertiesBuilder,
getMetastoreProjectionPropertyKey(columnName, COLUMN_PROJECTION_RANGE_SUFFIX),
COLUMN_PROJECTION_RANGE,
this::splitCommaSeparatedString);
PartitionProjectionService::splitCommaSeparatedString);
rewriteProperty(
metastoreTableProperties,
trinoTablePropertiesBuilder,
Expand Down Expand Up @@ -355,7 +355,7 @@ private Projection parseColumnProjection(String columnName, Type columnType, Map
return projectionFactory.create(columnName, columnType, columnProperties);
}

private <I, V> void rewriteProperty(
private static <I, V> void rewriteProperty(
Map<String, I> sourceProperties,
ImmutableMap.Builder<String, V> targetPropertiesBuilder,
String sourcePropertyKey,
Expand All @@ -371,7 +371,7 @@ private TrinoException columnProjectionException(String message)
return new TrinoException(INVALID_COLUMN_PROPERTY, message);
}

private List<String> splitCommaSeparatedString(String value)
private static List<String> splitCommaSeparatedString(String value)
{
return Splitter.on(',')
.trimResults()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.trino.plugin.hive.HiveTimestampPrecision;
import io.trino.plugin.hive.HiveType;
import io.trino.plugin.hive.avro.TrinoAvroSerDe;
import io.trino.plugin.hive.aws.athena.PartitionProjectionService;
import io.trino.plugin.hive.metastore.Column;
import io.trino.plugin.hive.metastore.SortingColumn;
import io.trino.plugin.hive.metastore.Table;
Expand Down Expand Up @@ -1188,6 +1189,7 @@ public static Function<HiveColumnHandle, ColumnMetadata> columnMetadataGetter(Ta
.setComment(handle.isHidden() ? Optional.empty() : columnComment.get(handle.getName()))
.setExtraInfo(Optional.ofNullable(columnExtraInfo(handle.isPartitionKey())))
.setHidden(handle.isHidden())
.setProperties(PartitionProjectionService.getPartitionProjectionTrinoColumnProperties(table, handle.getName()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ protected static QueryRunner createHiveQueryRunner(Map<String, String> extraProp
// Reduce writer sort buffer size to ensure SortingFileWriter gets used
"hive.writer-sort-buffer-size", "1MB",
// Make weighted split scheduling more conservative to avoid OOMs in test
"hive.minimum-assigned-split-weight", "0.5"))
"hive.minimum-assigned-split-weight", "0.5",
"hive.partition-projection-enabled", "true"))
.setInitialTables(REQUIRED_TPCH_TABLES)
.setTpchBucketedCatalogEnabled(true)
.build();
Expand Down Expand Up @@ -4334,6 +4335,33 @@ public void testShowCreateTable()
assertEquals(getOnlyElement(actualResult.getOnlyColumnAsSet()), createTableSql);
}

@Test
public void testShowCreateTableWithColumnProperties()
{
try (TestTable table = new TestTable(
getQueryRunner()::execute,
"test_show_create_table_with_column_properties",
"(a INT, b INT WITH (partition_projection_type = 'INTEGER', partition_projection_range = ARRAY['0', '10'])) " +
"WITH (" +
" partition_projection_enabled = true," +
" partitioned_by = ARRAY['b']," +
" partition_projection_location_template = 's3://example/${b}')")) {
String result = (String) computeScalar("SHOW CREATE TABLE " + table.getName());
assertEquals(
result,
"CREATE TABLE hive.tpch." + table.getName() + " (\n" +
" a integer,\n" +
" b integer WITH ( partition_projection_range = ARRAY['0','10'], partition_projection_type = 'INTEGER' )\n" +
")\n" +
"WITH (\n" +
" format = 'ORC',\n" +
" partition_projection_enabled = true,\n" +
" partition_projection_location_template = 's3://example/${b}',\n" +
" partitioned_by = ARRAY['b']\n" +
")");
}
}

private void testCreateExternalTable(
String tableName,
String fileContents,
Expand Down