Skip to content

Commit

Permalink
Simplify MongoMetadata.getTableMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Nov 23, 2022
1 parent 55914a5 commit 40fa9d3
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public ConnectorTableMetadata getTableMetadata(ConnectorSession session, Connect
{
requireNonNull(tableHandle, "tableHandle is null");
SchemaTableName tableName = getTableName(tableHandle);
return getTableMetadata(session, tableName);
return getTableMetadata(tableName);
}

@Override
Expand Down Expand Up @@ -166,7 +166,7 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess
ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
for (SchemaTableName tableName : listTables(session, prefix)) {
try {
columns.put(tableName, getTableMetadata(session, tableName).getColumns());
columns.put(tableName, getTableMetadata(tableName).getColumns());
}
catch (NotFoundException e) {
// table disappeared during listing operation
Expand Down Expand Up @@ -459,16 +459,13 @@ private static SchemaTableName getTableName(ConnectorTableHandle tableHandle)
return ((MongoTableHandle) tableHandle).getSchemaTableName();
}

private ConnectorTableMetadata getTableMetadata(ConnectorSession session, SchemaTableName tableName)
private ConnectorTableMetadata getTableMetadata(SchemaTableName tableName)
{
MongoTable mongoTable = mongoSession.getTable(tableName);
MongoTableHandle tableHandle = mongoTable.getTableHandle();

List<ColumnMetadata> columns =
getColumnHandles(session, tableHandle).values().stream()
.map(MongoColumnHandle.class::cast)
.map(MongoColumnHandle::toColumnMetadata)
.collect(toImmutableList());
List<ColumnMetadata> columns = mongoTable.getColumns().stream()
.map(MongoColumnHandle::toColumnMetadata)
.collect(toImmutableList());

return new ConnectorTableMetadata(tableName, columns, ImmutableMap.of(), mongoTable.getComment());
}
Expand Down

0 comments on commit 40fa9d3

Please sign in to comment.