Skip to content
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 @@ -46,6 +46,7 @@
import jakarta.inject.Inject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -331,11 +332,19 @@ private ConnectorTableMetadata getTableMetadata(ConnectorSession session, Schema
return null;
}

List<ColumnMetadata> columnMetadata = tableHandle.getDeltaTable().getColumns().stream()
DeltaTable deltaTable = tableHandle.getDeltaTable();

// External location property
Map<String, Object> properties = new HashMap<>(1);
if (deltaTable.getTableLocation() != null) {
properties.put(DeltaTableProperties.EXTERNAL_LOCATION_PROPERTY, deltaTable.getTableLocation());
}

List<ColumnMetadata> columnMetadata = deltaTable.getColumns().stream()
.map(column -> getColumnMetadata(session, column))
.collect(Collectors.toList());

return new ConnectorTableMetadata(tableName, columnMetadata);
return new ConnectorTableMetadata(tableName, columnMetadata, properties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,33 @@ private static void setCommitFileModificationTime(String tableLocation, long com
Paths.get(URI.create(tableLocation)).resolve("_delta_log/").resolve(format("%020d.json", commitId)),
FileTime.from(commitTimeMillis, TimeUnit.MILLISECONDS));
}

@Test(dataProvider = "deltaReaderVersions")
public void testShowCreateTable(String deltaVersion)
{
String tableName = deltaVersion + "/data-reader-primitives";
String fullTableName = format("%s.%s.\"%s\"", DELTA_CATALOG, DELTA_SCHEMA.toLowerCase(), tableName);

String createTableQueryTemplate = "CREATE TABLE %s (\n" +
" \"as_int\" integer,\n" +
" \"as_long\" bigint,\n" +
" \"as_byte\" tinyint,\n" +
" \"as_short\" smallint,\n" +
" \"as_boolean\" boolean,\n" +
" \"as_float\" real,\n" +
" \"as_double\" double,\n" +
" \"as_string\" varchar,\n" +
" \"as_binary\" varbinary,\n" +
" \"as_big_decimal\" decimal(1,0)\n" +
")\n" +
"WITH (\n" +
" external_location = '%s'\n" +
")";

String expectedSqlCommand = format(createTableQueryTemplate, fullTableName, goldenTablePath(tableName));

String showCreateTableCommandResult = (String) computeActual("SHOW CREATE TABLE " + fullTableName).getOnlyValue();
Comment on lines +364 to +366
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Add a test case covering a Delta table with no tableLocation to exercise the null/absent-location path

Since external_location is now only added when deltaTable.getTableLocation() is non-null, please add a test where tableLocation is null/absent. For instance, create a Delta table via the connector without specifying external_location and assert that SHOW CREATE TABLE omits the WITH ( external_location = ...) clause. This will exercise the empty-property-map branch and guard against regressions in metadata population.


assertEquals(showCreateTableCommandResult, expectedSqlCommand);
}
}
Loading