Search in sources :

Example 41 with ConnectorMetadata

use of io.trino.spi.connector.ConnectorMetadata in project trino by trinodb.

the class MetadataManager method getSchemaProperties.

@Override
public Map<String, Object> getSchemaProperties(Session session, CatalogSchemaName schemaName) {
    if (!schemaExists(session, schemaName)) {
        throw new TrinoException(SCHEMA_NOT_FOUND, format("Schema '%s' does not exist", schemaName));
    }
    CatalogMetadata catalogMetadata = getCatalogMetadata(session, new CatalogName(schemaName.getCatalogName()));
    CatalogName catalogName = catalogMetadata.getConnectorIdForSchema(schemaName);
    ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
    ConnectorSession connectorSession = session.toConnectorSession(catalogName);
    return metadata.getSchemaProperties(connectorSession, schemaName);
}
Also used : TrinoException(io.trino.spi.TrinoException) CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 42 with ConnectorMetadata

use of io.trino.spi.connector.ConnectorMetadata in project trino by trinodb.

the class MetadataManager method getMaterializedViewInternal.

private Optional<ConnectorMaterializedViewDefinition> getMaterializedViewInternal(Session session, QualifiedObjectName viewName) {
    if (viewName.getCatalogName().isEmpty() || viewName.getSchemaName().isEmpty() || viewName.getObjectName().isEmpty()) {
        // View cannot exist
        return Optional.empty();
    }
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, viewName.getCatalogName());
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        CatalogName catalogName = catalogMetadata.getConnectorId(session, viewName);
        ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
        ConnectorSession connectorSession = session.toConnectorSession(catalogName);
        return metadata.getMaterializedView(connectorSession, viewName.asSchemaTableName());
    }
    return Optional.empty();
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 43 with ConnectorMetadata

use of io.trino.spi.connector.ConnectorMetadata in project trino by trinodb.

the class MetadataManager method dropTable.

@Override
public void dropTable(Session session, TableHandle tableHandle) {
    CatalogName catalogName = tableHandle.getCatalogName();
    CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName);
    ConnectorMetadata metadata = catalogMetadata.getMetadata(session);
    Optional<CatalogSchemaTableName> tableName = getTableNameIfSystemSecurity(session, catalogMetadata, tableHandle);
    metadata.dropTable(session.toConnectorSession(catalogName), tableHandle.getConnectorHandle());
    tableName.ifPresent(name -> systemSecurityMetadata.tableDropped(session, name));
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName)

Example 44 with ConnectorMetadata

use of io.trino.spi.connector.ConnectorMetadata in project trino by trinodb.

the class MetadataManager method listMaterializedViews.

@Override
public List<QualifiedObjectName> listMaterializedViews(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<QualifiedObjectName> objectName = prefix.asQualifiedObjectName();
    if (objectName.isPresent()) {
        return isMaterializedView(session, objectName.get()) ? ImmutableList.of(objectName.get()) : ImmutableList.of();
    }
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Set<QualifiedObjectName> materializedViews = new LinkedHashSet<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        for (CatalogName catalogName : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
            ConnectorSession connectorSession = session.toConnectorSession(catalogName);
            metadata.listMaterializedViews(connectorSession, prefix.getSchemaName()).stream().map(convertFromSchemaTableName(prefix.getCatalogName())).filter(prefix::matches).forEach(materializedViews::add);
        }
    }
    return ImmutableList.copyOf(materializedViews);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 45 with ConnectorMetadata

use of io.trino.spi.connector.ConnectorMetadata in project trino by trinodb.

the class MetadataManager method getSystemTable.

@Override
public Optional<SystemTable> getSystemTable(Session session, QualifiedObjectName tableName) {
    requireNonNull(session, "session is null");
    requireNonNull(tableName, "tableName is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, tableName.getCatalogName());
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        // we query only main connector for runtime system tables
        CatalogName catalogName = catalogMetadata.getCatalogName();
        ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
        return metadata.getSystemTable(session.toConnectorSession(catalogName), tableName.asSchemaTableName());
    }
    return Optional.empty();
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Aggregations

ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)190 CatalogName (io.trino.connector.CatalogName)101 ConnectorSession (io.trino.spi.connector.ConnectorSession)97 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)70 Test (org.testng.annotations.Test)63 TestingConnectorSession (io.trino.testing.TestingConnectorSession)52 SchemaTableName (io.trino.spi.connector.SchemaTableName)48 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)43 ColumnHandle (io.trino.spi.connector.ColumnHandle)40 ConnectorOutputTableHandle (io.trino.spi.connector.ConnectorOutputTableHandle)32 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)32 ConnectorInsertTableHandle (io.trino.spi.connector.ConnectorInsertTableHandle)31 Constraint (io.trino.spi.connector.Constraint)31 MaterializedResult (io.trino.testing.MaterializedResult)27 HiveColumnHandle.bucketColumnHandle (io.trino.plugin.hive.HiveColumnHandle.bucketColumnHandle)26 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)26 TrinoException (io.trino.spi.TrinoException)23 Slice (io.airlift.slice.Slice)22 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)21 SchemaTablePrefix (io.trino.spi.connector.SchemaTablePrefix)20