Search in sources :

Example 41 with ConnectorId

use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.

the class MetadataManager method getLayout.

@Override
public TableLayout getLayout(Session session, TableLayoutHandle handle) {
    ConnectorId connectorId = handle.getConnectorId();
    CatalogMetadata catalogMetadata = getCatalogMetadata(session, connectorId);
    ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
    ConnectorTransactionHandle transaction = catalogMetadata.getTransactionHandleFor(connectorId);
    return fromConnectorLayout(connectorId, transaction, metadata.getTableLayout(session.toConnectorSession(connectorId), handle.getConnectorHandle()));
}
Also used : ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 42 with ConnectorId

use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.

the class MetadataManager method listTableColumns.

@Override
public Map<QualifiedObjectName, List<ColumnMetadata>> listTableColumns(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Map<QualifiedObjectName, List<ColumnMetadata>> tableColumns = new HashMap<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
        for (ConnectorId connectorId : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
            ConnectorSession connectorSession = session.toConnectorSession(connectorId);
            for (Entry<SchemaTableName, List<ColumnMetadata>> entry : metadata.listTableColumns(connectorSession, tablePrefix).entrySet()) {
                QualifiedObjectName tableName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
                tableColumns.put(tableName, entry.getValue());
            }
            // if table and view names overlap, the view wins
            for (Entry<SchemaTableName, ConnectorViewDefinition> entry : metadata.getViews(connectorSession, tablePrefix).entrySet()) {
                QualifiedObjectName tableName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
                ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
                for (ViewColumn column : deserializeView(entry.getValue().getViewData()).getColumns()) {
                    columns.add(new ColumnMetadata(column.getName(), column.getType()));
                }
                tableColumns.put(tableName, columns.build());
            }
        }
    }
    return ImmutableMap.copyOf(tableColumns);
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) ViewColumn(com.facebook.presto.metadata.ViewDefinition.ViewColumn) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) SchemaTableName(com.facebook.presto.spi.SchemaTableName) QualifiedObjectName.convertFromSchemaTableName(com.facebook.presto.metadata.QualifiedObjectName.convertFromSchemaTableName) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 43 with ConnectorId

use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.

the class MetadataManager method grantTablePrivileges.

@Override
public void grantTablePrivileges(Session session, QualifiedObjectName tableName, Set<Privilege> privileges, String grantee, boolean grantOption) {
    CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, tableName.getCatalogName());
    ConnectorId connectorId = catalogMetadata.getConnectorId();
    ConnectorMetadata metadata = catalogMetadata.getMetadata();
    metadata.grantTablePrivileges(session.toConnectorSession(connectorId), tableName.asSchemaTableName(), privileges, grantee, grantOption);
}
Also used : ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 44 with ConnectorId

use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.

the class MetadataManager method getTableHandle.

@Override
public Optional<TableHandle> getTableHandle(Session session, QualifiedObjectName table) {
    requireNonNull(table, "table is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, table.getCatalogName());
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        ConnectorId connectorId = catalogMetadata.getConnectorId(table);
        ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
        ConnectorTableHandle tableHandle = metadata.getTableHandle(session.toConnectorSession(connectorId), table.asSchemaTableName());
        if (tableHandle != null) {
            return Optional.of(new TableHandle(connectorId, tableHandle));
        }
    }
    return Optional.empty();
}
Also used : ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.connector.ConnectorId) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle)

Example 45 with ConnectorId

use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.

the class MetadataManager method beginCreateTable.

@Override
public OutputTableHandle beginCreateTable(Session session, String catalogName, ConnectorTableMetadata tableMetadata, Optional<NewTableLayout> layout) {
    CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName);
    ConnectorId connectorId = catalogMetadata.getConnectorId();
    ConnectorMetadata metadata = catalogMetadata.getMetadata();
    ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(connectorId);
    ConnectorSession connectorSession = session.toConnectorSession(connectorId);
    ConnectorOutputTableHandle handle = metadata.beginCreateTable(connectorSession, tableMetadata, layout.map(NewTableLayout::getLayout));
    return new OutputTableHandle(connectorId, transactionHandle, handle);
}
Also used : ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.connector.ConnectorId)

Aggregations

ConnectorId (com.facebook.presto.connector.ConnectorId)76 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)39 ConnectorSession (com.facebook.presto.spi.ConnectorSession)14 Session (com.facebook.presto.Session)12 PrestoException (com.facebook.presto.spi.PrestoException)9 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)7 Test (org.testng.annotations.Test)7 ConnectorId.createInformationSchemaConnectorId (com.facebook.presto.connector.ConnectorId.createInformationSchemaConnectorId)5 ConnectorId.createSystemTablesConnectorId (com.facebook.presto.connector.ConnectorId.createSystemTablesConnectorId)5 TableHandle (com.facebook.presto.metadata.TableHandle)5 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)5 SchemaTableName (com.facebook.presto.spi.SchemaTableName)5 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)5 ImmutableList (com.google.common.collect.ImmutableList)5 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)4 QualifiedObjectName.convertFromSchemaTableName (com.facebook.presto.metadata.QualifiedObjectName.convertFromSchemaTableName)4 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)4 ConnectorInsertTableHandle (com.facebook.presto.spi.ConnectorInsertTableHandle)4 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)4 TransactionManager (com.facebook.presto.transaction.TransactionManager)4