Skip to content

Commit

Permalink
Implement Optional-based connector metadata API in Tpch
Browse files Browse the repository at this point in the history
  • Loading branch information
kokosing committed Jul 18, 2018
1 parent 95e596f commit 9950359
Showing 1 changed file with 9 additions and 13 deletions.
Expand Up @@ -290,7 +290,7 @@ public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, Conn
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> tableColumns = ImmutableMap.builder();
for (String schemaName : getSchemaNames(session, prefix.getSchemaName())) {
for (String schemaName : getSchemaNames(session, Optional.ofNullable(prefix.getSchemaName()))) {
for (TpchTable<?> tpchTable : TpchTable.getTables()) {
if (prefix.getTableName() == null || tpchTable.getTableName().equals(prefix.getTableName())) {
ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpchTable, columnNaming);
Expand Down Expand Up @@ -416,10 +416,10 @@ public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTable
}

@Override
public List<SchemaTableName> listTables(ConnectorSession session, String schemaNameOrNull)
public List<SchemaTableName> listTables(ConnectorSession session, Optional<String> filterSchema)
{
ImmutableList.Builder<SchemaTableName> builder = ImmutableList.builder();
for (String schemaName : getSchemaNames(session, schemaNameOrNull)) {
for (String schemaName : getSchemaNames(session, filterSchema)) {
for (TpchTable<?> tpchTable : TpchTable.getTables()) {
builder.add(new SchemaTableName(schemaName, tpchTable.getTableName()));
}
Expand All @@ -439,19 +439,15 @@ private TupleDomain<ColumnHandle> toTupleDomain(Map<TpchColumnHandle, Set<Nullab
})));
}

private List<String> getSchemaNames(ConnectorSession session, String schemaNameOrNull)
private List<String> getSchemaNames(ConnectorSession session, Optional<String> schemaName)
{
List<String> schemaNames;
if (schemaNameOrNull == null) {
schemaNames = listSchemaNames(session);
if (!schemaName.isPresent()) {
return listSchemaNames(session);
}
else if (schemaNameToScaleFactor(schemaNameOrNull) > 0) {
schemaNames = ImmutableList.of(schemaNameOrNull);
if (schemaNameToScaleFactor(schemaName.get()) > 0) {
return ImmutableList.of(schemaName.get());
}
else {
schemaNames = ImmutableList.of();
}
return schemaNames;
return ImmutableList.of();
}

private static String scaleFactorSchemaName(double scaleFactor)
Expand Down

0 comments on commit 9950359

Please sign in to comment.