use of com.facebook.presto.spi.connector.ConnectorMetadata in project presto by prestodb.
the class MetadataManager method listViews.
@Override
public List<QualifiedObjectName> listViews(Session session, QualifiedTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
Set<QualifiedObjectName> views = new LinkedHashSet<>();
if (catalog.isPresent()) {
CatalogMetadata catalogMetadata = catalog.get();
String schemaNameOrNull = prefix.getSchemaName().orElse(null);
for (ConnectorId connectorId : catalogMetadata.listConnectorIds()) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
ConnectorSession connectorSession = session.toConnectorSession(connectorId);
metadata.listViews(connectorSession, schemaNameOrNull).stream().map(convertFromSchemaTableName(prefix.getCatalogName())::apply).forEach(views::add);
}
}
return ImmutableList.copyOf(views);
}
use of com.facebook.presto.spi.connector.ConnectorMetadata in project presto by prestodb.
the class MetadataManager method getLayouts.
@Override
public List<TableLayoutResult> getLayouts(Session session, TableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns) {
if (constraint.getSummary().isNone()) {
return ImmutableList.of();
}
ConnectorId connectorId = table.getConnectorId();
ConnectorTableHandle connectorTable = table.getConnectorHandle();
CatalogMetadata catalogMetadata = getCatalogMetadata(session, connectorId);
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
ConnectorTransactionHandle transaction = catalogMetadata.getTransactionHandleFor(connectorId);
ConnectorSession connectorSession = session.toConnectorSession(connectorId);
List<ConnectorTableLayoutResult> layouts = metadata.getTableLayouts(connectorSession, connectorTable, constraint, desiredColumns);
return layouts.stream().map(layout -> new TableLayoutResult(fromConnectorLayout(connectorId, transaction, layout.getTableLayout()), layout.getUnenforcedConstraint())).collect(toImmutableList());
}
use of com.facebook.presto.spi.connector.ConnectorMetadata in project presto by prestodb.
the class MetadataManager method renameTable.
@Override
public void renameTable(Session session, TableHandle tableHandle, QualifiedObjectName newTableName) {
String catalogName = newTableName.getCatalogName();
CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName);
ConnectorId connectorId = catalogMetadata.getConnectorId();
if (!tableHandle.getConnectorId().equals(connectorId)) {
throw new PrestoException(SYNTAX_ERROR, "Cannot rename tables across catalogs");
}
ConnectorMetadata metadata = catalogMetadata.getMetadata();
metadata.renameTable(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle(), newTableName.asSchemaTableName());
}
use of com.facebook.presto.spi.connector.ConnectorMetadata in project presto by prestodb.
the class MetadataManager method getNewTableLayout.
@Override
public Optional<NewTableLayout> getNewTableLayout(Session session, String catalogName, ConnectorTableMetadata tableMetadata) {
CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName);
ConnectorId connectorId = catalogMetadata.getConnectorId();
ConnectorMetadata metadata = catalogMetadata.getMetadata();
ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(connectorId);
ConnectorSession connectorSession = session.toConnectorSession(connectorId);
return metadata.getNewTableLayout(connectorSession, tableMetadata).map(layout -> new NewTableLayout(connectorId, transactionHandle, layout));
}
use of com.facebook.presto.spi.connector.ConnectorMetadata in project presto by prestodb.
the class MetadataManager method listSchemaNames.
@Override
public List<String> listSchemaNames(Session session, String catalogName) {
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, catalogName);
ImmutableSet.Builder<String> schemaNames = ImmutableSet.builder();
if (catalog.isPresent()) {
CatalogMetadata catalogMetadata = catalog.get();
ConnectorSession connectorSession = session.toConnectorSession(catalogMetadata.getConnectorId());
for (ConnectorId connectorId : catalogMetadata.listConnectorIds()) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
schemaNames.addAll(metadata.listSchemaNames(connectorSession));
}
}
return ImmutableList.copyOf(schemaNames.build());
}
Aggregations