Search in sources :

Example 1 with MetadataProvider

use of io.trino.spi.connector.MetadataProvider 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

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 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 TABLE_COMMENT (io.trino.plugin.hive.HiveMetadata.TABLE_COMMENT)1 HiveSessionProperties.isLegacyHiveViewTranslation (io.trino.plugin.hive.HiveSessionProperties.isLegacyHiveViewTranslation)1 TEXTFILE (io.trino.plugin.hive.HiveStorageFormat.TEXTFILE)1 HiveType.toHiveType (io.trino.plugin.hive.HiveType.toHiveType)1 Column (io.trino.plugin.hive.metastore.Column)1 CoralSemiTransactionalHiveMSCAdapter (io.trino.plugin.hive.metastore.CoralSemiTransactionalHiveMSCAdapter)1 SemiTransactionalHiveMetastore (io.trino.plugin.hive.metastore.SemiTransactionalHiveMetastore)1 StorageFormat.fromHiveStorageFormat (io.trino.plugin.hive.metastore.StorageFormat.fromHiveStorageFormat)1 Table (io.trino.plugin.hive.metastore.Table)1