Search in sources :

Example 1 with ConnectorTableSchema

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

the class InternalMetadataProvider method getRelationMetadata.

@Override
public Optional<ConnectorTableSchema> getRelationMetadata(ConnectorSession connectorSession, CatalogSchemaTableName tableName) {
    Session session = ((FullConnectorSession) connectorSession).getSession();
    QualifiedObjectName qualifiedName = new QualifiedObjectName(tableName.getCatalogName(), tableName.getSchemaTableName().getSchemaName(), tableName.getSchemaTableName().getTableName());
    Optional<MaterializedViewDefinition> materializedView = metadataManager.getMaterializedView(session, qualifiedName);
    if (materializedView.isPresent()) {
        return Optional.of(new ConnectorTableSchema(tableName.getSchemaTableName(), toColumnSchema(materializedView.get().getColumns())));
    }
    Optional<ViewDefinition> view = metadataManager.getView(session, qualifiedName);
    if (view.isPresent()) {
        return Optional.of(new ConnectorTableSchema(tableName.getSchemaTableName(), toColumnSchema(view.get().getColumns())));
    }
    Optional<TableHandle> tableHandle = metadataManager.getTableHandle(session, qualifiedName);
    if (tableHandle.isPresent()) {
        return Optional.of(metadataManager.getTableSchema(session, tableHandle.get()).getTableSchema());
    }
    return Optional.empty();
}
Also used : MaterializedViewDefinition(io.trino.metadata.MaterializedViewDefinition) ConnectorTableSchema(io.trino.spi.connector.ConnectorTableSchema) ViewDefinition(io.trino.metadata.ViewDefinition) MaterializedViewDefinition(io.trino.metadata.MaterializedViewDefinition) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) FullConnectorSession(io.trino.FullConnectorSession) ConnectorSession(io.trino.spi.connector.ConnectorSession) Session(io.trino.Session) FullConnectorSession(io.trino.FullConnectorSession)

Example 2 with ConnectorTableSchema

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

the class MetadataManager method getTableSchema.

@Override
public TableSchema getTableSchema(Session session, TableHandle tableHandle) {
    CatalogName catalogName = tableHandle.getCatalogName();
    ConnectorMetadata metadata = getMetadata(session, catalogName);
    ConnectorTableSchema tableSchema = metadata.getTableSchema(session.toConnectorSession(catalogName), tableHandle.getConnectorHandle());
    return new TableSchema(catalogName, tableSchema);
}
Also used : ConnectorTableSchema(io.trino.spi.connector.ConnectorTableSchema) ConnectorTableSchema(io.trino.spi.connector.ConnectorTableSchema) CatalogName(io.trino.connector.CatalogName) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 3 with ConnectorTableSchema

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

the class ViewReaderUtil method coralTableRedirectionResolver.

private static CoralTableRedirectionResolver coralTableRedirectionResolver(ConnectorSession session, BiFunction<ConnectorSession, SchemaTableName, Optional<CatalogSchemaTableName>> tableRedirectionResolver, MetadataProvider metadataProvider) {
    return schemaTableName -> tableRedirectionResolver.apply(session, schemaTableName).map(target -> {
        ConnectorTableSchema tableSchema = metadataProvider.getRelationMetadata(session, target).orElseThrow(() -> new TableNotFoundException(target.getSchemaTableName(), format("%s is redirected to %s, but that relation cannot be found", schemaTableName, target)));
        List<Column> columns = tableSchema.getColumns().stream().filter(columnSchema -> !columnSchema.isHidden()).map(columnSchema -> new Column(columnSchema.getName(), toHiveType(columnSchema.getType()), Optional.empty())).collect(toImmutableList());
        Table table = Table.builder().setDatabaseName(schemaTableName.getSchemaName()).setTableName(schemaTableName.getTableName()).setTableType(EXTERNAL_TABLE.name()).setDataColumns(columns).withStorage(storage -> storage.setStorageFormat(fromHiveStorageFormat(TEXTFILE))).setOwner(Optional.empty()).build();
        return toMetastoreApiTable(table);
    });
}
Also used : BiFunction(java.util.function.BiFunction) EXTERNAL_TABLE(org.apache.hadoop.hive.metastore.TableType.EXTERNAL_TABLE) CoralSemiTransactionalHiveMSCAdapter(io.trino.plugin.hive.metastore.CoralSemiTransactionalHiveMSCAdapter) HiveMetastoreClient(com.linkedin.coral.common.HiveMetastoreClient) StorageFormat.fromHiveStorageFormat(io.trino.plugin.hive.metastore.StorageFormat.fromHiveStorageFormat) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) MetadataProvider(io.trino.spi.connector.MetadataProvider) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Column(io.trino.plugin.hive.metastore.Column) Verify.verify(com.google.common.base.Verify.verify) Locale(java.util.Locale) SemiTransactionalHiveMetastore(io.trino.plugin.hive.metastore.SemiTransactionalHiveMetastore) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ViewColumn(io.trino.spi.connector.ConnectorViewDefinition.ViewColumn) TEXTFILE(io.trino.plugin.hive.HiveStorageFormat.TEXTFILE) ConnectorViewDefinition(io.trino.spi.connector.ConnectorViewDefinition) VIRTUAL_VIEW(org.apache.hadoop.hive.metastore.TableType.VIRTUAL_VIEW) HiveType.toHiveType(io.trino.plugin.hive.HiveType.toHiveType) TABLE_COMMENT(io.trino.plugin.hive.HiveMetadata.TABLE_COMMENT) HiveSessionProperties.isLegacyHiveViewTranslation(io.trino.plugin.hive.HiveSessionProperties.isLegacyHiveViewTranslation) RelDataType(org.apache.calcite.rel.type.RelDataType) HIVE_VIEW_TRANSLATION_ERROR(io.trino.plugin.hive.HiveErrorCode.HIVE_VIEW_TRANSLATION_ERROR) HiveToRelConverter(com.linkedin.coral.hive.hive2rel.HiveToRelConverter) Table(io.trino.plugin.hive.metastore.Table) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TrinoException(io.trino.spi.TrinoException) ConnectorSession(io.trino.spi.connector.ConnectorSession) RelNode(org.apache.calcite.rel.RelNode) CatalogName(io.trino.plugin.base.CatalogName) SchemaTableName(io.trino.spi.connector.SchemaTableName) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) ConnectorTableSchema(io.trino.spi.connector.ConnectorTableSchema) ThriftMetastoreUtil.toMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.toMetastoreApiTable) HiveUtil.checkCondition(io.trino.plugin.hive.util.HiveUtil.checkCondition) Base64(java.util.Base64) List(java.util.List) RelToTrinoConverter(com.linkedin.coral.trino.rel2trino.RelToTrinoConverter) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) JsonCodecFactory(io.airlift.json.JsonCodecFactory) TableType(org.apache.hadoop.hive.metastore.TableType) HIVE_INVALID_VIEW_DATA(io.trino.plugin.hive.HiveErrorCode.HIVE_INVALID_VIEW_DATA) Optional(java.util.Optional) TypeManager(io.trino.spi.type.TypeManager) JsonCodec(io.airlift.json.JsonCodec) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Table(io.trino.plugin.hive.metastore.Table) ThriftMetastoreUtil.toMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.toMetastoreApiTable) Column(io.trino.plugin.hive.metastore.Column) ViewColumn(io.trino.spi.connector.ConnectorViewDefinition.ViewColumn) ConnectorTableSchema(io.trino.spi.connector.ConnectorTableSchema)

Aggregations

ConnectorTableSchema (io.trino.spi.connector.ConnectorTableSchema)3 ConnectorSession (io.trino.spi.connector.ConnectorSession)2 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 HiveMetastoreClient (com.linkedin.coral.common.HiveMetastoreClient)1 HiveToRelConverter (com.linkedin.coral.hive.hive2rel.HiveToRelConverter)1 RelToTrinoConverter (com.linkedin.coral.trino.rel2trino.RelToTrinoConverter)1 JsonCodec (io.airlift.json.JsonCodec)1 JsonCodecFactory (io.airlift.json.JsonCodecFactory)1 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)1 FullConnectorSession (io.trino.FullConnectorSession)1 Session (io.trino.Session)1 CatalogName (io.trino.connector.CatalogName)1 MaterializedViewDefinition (io.trino.metadata.MaterializedViewDefinition)1 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)1 TableHandle (io.trino.metadata.TableHandle)1 ViewDefinition (io.trino.metadata.ViewDefinition)1 CatalogName (io.trino.plugin.base.CatalogName)1 HIVE_INVALID_VIEW_DATA (io.trino.plugin.hive.HiveErrorCode.HIVE_INVALID_VIEW_DATA)1 HIVE_VIEW_TRANSLATION_ERROR (io.trino.plugin.hive.HiveErrorCode.HIVE_VIEW_TRANSLATION_ERROR)1