Skip to content
Closed
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 @@ -470,32 +470,36 @@ public ConnectorTableMetadata getTableMetadata(ConnectorSession session, Connect
{
DeltaLakeTableHandle tableHandle = checkValidTableHandle(table);
String location = metastore.getTableLocation(tableHandle.getSchemaTableName());
Map<String, String> columnComments = getColumnComments(tableHandle.getMetadataEntry());
Map<String, Boolean> columnsNullability = getColumnsNullability(tableHandle.getMetadataEntry());
Map<String, String> columnGenerations = getGeneratedColumnExpressions(tableHandle.getMetadataEntry());
MetadataEntry metadataEntry = tableHandle.getMetadataEntry();
Map<String, String> columnComments = getColumnComments(metadataEntry);
Map<String, Boolean> columnsNullability = getColumnsNullability(metadataEntry);
Map<String, String> columnGenerations = getGeneratedColumnExpressions(metadataEntry);
List<String> constraints = ImmutableList.<String>builder()
.addAll(getCheckConstraints(tableHandle.getMetadataEntry()).values())
.addAll(getColumnInvariants(tableHandle.getMetadataEntry()).values()) // The internal logic for column invariants in Delta Lake is same as check constraints
.addAll(getCheckConstraints(metadataEntry).values())
.addAll(getColumnInvariants(metadataEntry).values()) // The internal logic for column invariants in Delta Lake is same as check constraints
.build();
List<ColumnMetadata> columns = getColumns(tableHandle.getMetadataEntry()).stream()
List<ColumnMetadata> columns = getColumns(metadataEntry).stream()
.map(column -> getColumnMetadata(column, columnComments.get(column.getName()), columnsNullability.getOrDefault(column.getName(), true), columnGenerations.get(column.getName())))
.collect(toImmutableList());

ImmutableMap.Builder<String, Object> properties = ImmutableMap.<String, Object>builder()
.put(LOCATION_PROPERTY, location)
.put(PARTITIONED_BY_PROPERTY, tableHandle.getMetadataEntry().getCanonicalPartitionColumns());
.put(LOCATION_PROPERTY, location);
List<String> partitionColumnNames = metadataEntry.getCanonicalPartitionColumns();
if (!partitionColumnNames.isEmpty()) {
properties.put(PARTITIONED_BY_PROPERTY, partitionColumnNames);
}

Optional<Long> checkpointInterval = tableHandle.getMetadataEntry().getCheckpointInterval();
Optional<Long> checkpointInterval = metadataEntry.getCheckpointInterval();
checkpointInterval.ifPresent(value -> properties.put(CHECKPOINT_INTERVAL_PROPERTY, value));

Optional<Boolean> changeDataFeedEnabled = tableHandle.getMetadataEntry().isChangeDataFeedEnabled();
Optional<Boolean> changeDataFeedEnabled = metadataEntry.isChangeDataFeedEnabled();
changeDataFeedEnabled.ifPresent(value -> properties.put(CHANGE_DATA_FEED_ENABLED_PROPERTY, value));

return new ConnectorTableMetadata(
tableHandle.getSchemaTableName(),
columns,
properties.buildOrThrow(),
Optional.ofNullable(tableHandle.getMetadataEntry().getDescription()),
Optional.ofNullable(metadataEntry.getDescription()),
constraints.stream()
.map(constraint -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1427,22 +1427,18 @@ private void testDeltaLakeTableLocationChanged(boolean fewerEntries, boolean fir
}

// Verify table schema gets reflected correctly
String qualifiedTableName = "%s.%s.%s".formatted(getSession().getCatalog().orElseThrow(), SCHEMA, tableName);
assertThat(computeScalar("SHOW CREATE TABLE " + tableName))
.isEqualTo(format("" +
"CREATE TABLE %s.%s.%s (\n" +
" a_number integer,\n" +
" a_string varchar,\n" +
" another_string varchar\n" +
")\n" +
"WITH (\n" +
" location = '%s',\n" +
" partitioned_by = ARRAY[%s]\n" +
")",
getSession().getCatalog().orElseThrow(),
SCHEMA,
tableName,
newLocation,
secondPartitioned ? "'a_number'" : ""));
.isEqualTo("" +
"CREATE TABLE " + qualifiedTableName + " (\n" +
" a_number integer,\n" +
" a_string varchar,\n" +
" another_string varchar\n" +
")\n" +
"WITH (\n" +
" location = '" + newLocation + "'" + (secondPartitioned ? "," : "") + "\n" +
(secondPartitioned ? " partitioned_by = ARRAY['a_number']\n" : "") +
")");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ public void testShowCreateTable()
" comment varchar\n" +
")\n" +
"WITH (\n" +
" location = \\E'.*/test_schema/orders',\n\\Q" +
" partitioned_by = ARRAY[]\n" +
" location = \\E'.*/test_schema/orders'\n\\Q" +
")");
}

Expand Down