Skip to content

Commit

Permalink
Don't forward requests for well-known schemas to connector
Browse files Browse the repository at this point in the history
This requires hard-coding knowledge about sys and information_schema in
MetadataManager. It's a hack until we figure out how we want to model
these going forward.
  • Loading branch information
martint committed Sep 22, 2014
1 parent db9716a commit 9819aea
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
public class MetadataManager
implements Metadata
{
private static final String SYS_SCHEMA_NAME = "sys";
private static final String INFORMATION_SCHEMA_NAME = "information_schema";

private final SystemTablesMetadata systemMetadata;
private final ConcurrentMap<String, ConnectorMetadataEntry> informationSchemasByCatalog = new ConcurrentHashMap<>();
private final ConcurrentMap<String, ConnectorMetadataEntry> connectorsByCatalog = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -189,9 +192,9 @@ public Optional<TableHandle> getTableHandle(ConnectorSession session, QualifiedT
{
checkNotNull(table, "table is null");

SchemaTableName tableName = table.asSchemaTableName();
for (ConnectorMetadataEntry entry : allConnectorsFor(table.getCatalogName())) {
ConnectorTableHandle tableHandle = entry.getMetadata().getTableHandle(session, tableName);
ConnectorMetadataEntry entry = getConnectorFor(table);
if (entry != null) {
ConnectorTableHandle tableHandle = entry.getMetadata().getTableHandle(session, table.asSchemaTableName());
if (tableHandle != null) {
return Optional.of(new TableHandle(entry.getConnectorId(), tableHandle));
}
Expand Down Expand Up @@ -405,8 +408,9 @@ public Map<QualifiedTableName, ViewDefinition> getViews(ConnectorSession session
@Override
public Optional<ViewDefinition> getView(ConnectorSession session, QualifiedTableName viewName)
{
SchemaTablePrefix prefix = viewName.asSchemaTableName().toSchemaTablePrefix();
for (ConnectorMetadataEntry entry : allConnectorsFor(viewName.getCatalogName())) {
ConnectorMetadataEntry entry = getConnectorFor(viewName);
if (entry != null) {
SchemaTablePrefix prefix = viewName.asSchemaTableName().toSchemaTablePrefix();
Map<SchemaTableName, String> views = entry.getMetadata().getViews(session, prefix);
String view = views.get(viewName.asSchemaTableName());
if (view != null) {
Expand Down Expand Up @@ -473,6 +477,21 @@ private List<ConnectorMetadataEntry> allConnectorsFor(String catalogName)
return builder.build();
}

private ConnectorMetadataEntry getConnectorFor(QualifiedTableName name)
{
String catalog = name.getCatalogName();
String schema = name.getSchemaName();

if (schema.equals(SYS_SCHEMA_NAME)) {
return new ConnectorMetadataEntry(SystemTablesManager.CONNECTOR_ID, systemMetadata);
}
else if (schema.equals(INFORMATION_SCHEMA_NAME)) {
return informationSchemasByCatalog.get(catalog);
}

return connectorsByCatalog.get(catalog);
}

private ConnectorMetadata lookupConnectorFor(TableHandle tableHandle)
{
return getConnectorMetadata(tableHandle.getConnectorId());
Expand Down

0 comments on commit 9819aea

Please sign in to comment.