Search in sources :

Example 1 with QualifiedTablePrefix

use of io.prestosql.metadata.QualifiedTablePrefix in project hetu-core by openlookeng.

the class TableCommentSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Optional<String> catalogFilter = stringFilter(constraint, 0);
    Optional<String> schemaFilter = stringFilter(constraint, 1);
    Optional<String> tableFilter = stringFilter(constraint, 2);
    Session session = toSession(transactionHandle, connectorSession);
    Builder table = InMemoryRecordSet.builder(COMMENT_TABLE);
    for (String catalog : filter(listCatalogs(session, metadata, accessControl).keySet(), catalogFilter)) {
        QualifiedTablePrefix prefix = tablePrefix(catalog, schemaFilter, tableFilter);
        Set<SchemaTableName> names = ImmutableSet.of();
        try {
            names = listTables(session, metadata, accessControl, prefix);
        } catch (PrestoException e) {
            // listTables throws an exception if cannot connect the database
            LOG.debug(e, "Failed to get tables for catalog: %s", catalog);
        }
        for (SchemaTableName name : names) {
            QualifiedObjectName tableName = new QualifiedObjectName(prefix.getCatalogName(), name.getSchemaName(), name.getTableName());
            Optional<String> comment = Optional.empty();
            try {
                comment = metadata.getTableHandle(session, tableName).map(handle -> metadata.getTableMetadata(session, handle)).map(metadata -> metadata.getMetadata().getComment()).get();
            } catch (PrestoException e) {
                // getTableHandle may throw an exception (e.g. Cassandra connector doesn't allow case insensitive column names)
                LOG.debug(e, "Failed to get metadata for table: %s", name);
            }
            table.addRow(prefix.getCatalogName(), name.getSchemaName(), name.getTableName(), comment.orElse(null));
        }
    }
    return table.build().cursor();
}
Also used : FilterUtil.tablePrefix(io.prestosql.connector.system.jdbc.FilterUtil.tablePrefix) MetadataListing.listTables(io.prestosql.metadata.MetadataListing.listTables) Logger(io.airlift.log.Logger) Builder(io.prestosql.spi.connector.InMemoryRecordSet.Builder) SINGLE_COORDINATOR(io.prestosql.spi.connector.SystemTable.Distribution.SINGLE_COORDINATOR) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) InMemoryRecordSet(io.prestosql.spi.connector.InMemoryRecordSet) Inject(javax.inject.Inject) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) MetadataListing.listCatalogs(io.prestosql.metadata.MetadataListing.listCatalogs) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) FilterUtil.stringFilter(io.prestosql.connector.system.jdbc.FilterUtil.stringFilter) TableMetadataBuilder.tableMetadataBuilder(io.prestosql.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) RecordCursor(io.prestosql.spi.connector.RecordCursor) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) AccessControl(io.prestosql.security.AccessControl) SystemTable(io.prestosql.spi.connector.SystemTable) TupleDomain(io.prestosql.spi.predicate.TupleDomain) SystemConnectorSessionUtil.toSession(io.prestosql.connector.system.SystemConnectorSessionUtil.toSession) Set(java.util.Set) Metadata(io.prestosql.metadata.Metadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) FilterUtil.filter(io.prestosql.connector.system.jdbc.FilterUtil.filter) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) Optional(java.util.Optional) QualifiedTablePrefix(io.prestosql.metadata.QualifiedTablePrefix) QualifiedTablePrefix(io.prestosql.metadata.QualifiedTablePrefix) Builder(io.prestosql.spi.connector.InMemoryRecordSet.Builder) TableMetadataBuilder.tableMetadataBuilder(io.prestosql.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) PrestoException(io.prestosql.spi.PrestoException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Session(io.prestosql.Session) SystemConnectorSessionUtil.toSession(io.prestosql.connector.system.SystemConnectorSessionUtil.toSession)

Example 2 with QualifiedTablePrefix

use of io.prestosql.metadata.QualifiedTablePrefix in project hetu-core by openlookeng.

the class InformationSchemaMetadata method calculatePrefixesWithSchemaName.

private Set<QualifiedTablePrefix> calculatePrefixesWithSchemaName(ConnectorSession connectorSession, TupleDomain<ColumnHandle> constraint, Optional<Predicate<Map<ColumnHandle, NullableValue>>> predicate) {
    Optional<Set<String>> schemas = filterString(constraint, SCHEMA_COLUMN_HANDLE);
    if (schemas.isPresent()) {
        return schemas.get().stream().filter(this::isLowerCase).map(schema -> new QualifiedTablePrefix(catalogName, schema)).collect(toImmutableSet());
    }
    Session session = ((FullConnectorSession) connectorSession).getSession();
    return metadata.listSchemaNames(session, catalogName).stream().filter(schema -> !predicate.isPresent() || predicate.get().test(schemaAsFixedValues(schema))).map(schema -> new QualifiedTablePrefix(catalogName, schema)).collect(toImmutableSet());
}
Also used : ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) Slice(io.airlift.slice.Slice) FullConnectorSession(io.prestosql.FullConnectorSession) NullableValue(io.prestosql.spi.predicate.NullableValue) EquatableValueSet(io.prestosql.spi.predicate.EquatableValueSet) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Collectors.toMap(java.util.stream.Collectors.toMap) TableMetadataBuilder.tableMetadataBuilder(io.prestosql.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) ConnectorTableProperties(io.prestosql.spi.connector.ConnectorTableProperties) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) MetadataUtil.findColumnMetadata(io.prestosql.metadata.MetadataUtil.findColumnMetadata) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) ENGLISH(java.util.Locale.ENGLISH) ConnectorTableLayoutHandle(io.prestosql.spi.connector.ConnectorTableLayoutHandle) Constraint(io.prestosql.spi.connector.Constraint) ImmutableSet(com.google.common.collect.ImmutableSet) ConstraintApplicationResult(io.prestosql.spi.connector.ConstraintApplicationResult) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TupleDomain(io.prestosql.spi.predicate.TupleDomain) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Predicates.compose(com.google.common.base.Predicates.compose) Metadata(io.prestosql.metadata.Metadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) ConnectorTableLayout(io.prestosql.spi.connector.ConnectorTableLayout) List(java.util.List) Stream(java.util.stream.Stream) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) Domain(io.prestosql.spi.predicate.Domain) Entry(java.util.Map.Entry) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) SchemaMetadataBuilder.schemaMetadataBuilder(io.prestosql.metadata.MetadataUtil.SchemaMetadataBuilder.schemaMetadataBuilder) SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) QualifiedTablePrefix(io.prestosql.metadata.QualifiedTablePrefix) EquatableValueSet(io.prestosql.spi.predicate.EquatableValueSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) QualifiedTablePrefix(io.prestosql.metadata.QualifiedTablePrefix) FullConnectorSession(io.prestosql.FullConnectorSession) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Session(io.prestosql.Session) FullConnectorSession(io.prestosql.FullConnectorSession)

Example 3 with QualifiedTablePrefix

use of io.prestosql.metadata.QualifiedTablePrefix in project hetu-core by openlookeng.

the class InformationSchemaPageSourceProvider method getInternalTable.

private InternalTable getInternalTable(ConnectorSession connectorSession, ConnectorTableHandle tablehandle) {
    Session session = ((FullConnectorSession) connectorSession).getSession();
    InformationSchemaTableHandle handle = (InformationSchemaTableHandle) tablehandle;
    Set<QualifiedTablePrefix> prefixes = handle.getPrefixes();
    return getInformationSchemaTable(session, handle.getCatalogName(), handle.getSchemaTableName(), prefixes);
}
Also used : QualifiedTablePrefix(io.prestosql.metadata.QualifiedTablePrefix) FullConnectorSession(io.prestosql.FullConnectorSession) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Session(io.prestosql.Session) FullConnectorSession(io.prestosql.FullConnectorSession)

Example 4 with QualifiedTablePrefix

use of io.prestosql.metadata.QualifiedTablePrefix in project hetu-core by openlookeng.

the class InformationSchemaMetadata method calculatePrefixesWithTableName.

public Set<QualifiedTablePrefix> calculatePrefixesWithTableName(ConnectorSession connectorSession, Set<QualifiedTablePrefix> prefixes, TupleDomain<ColumnHandle> constraint, Optional<Predicate<Map<ColumnHandle, NullableValue>>> predicate) {
    Session session = ((FullConnectorSession) connectorSession).getSession();
    Optional<Set<String>> tables = filterString(constraint, TABLE_NAME_COLUMN_HANDLE);
    if (tables.isPresent()) {
        return prefixes.stream().flatMap(prefix -> tables.get().stream().filter(this::isLowerCase).map(table -> table.toLowerCase(ENGLISH)).map(table -> new QualifiedObjectName(catalogName, prefix.getSchemaName().get(), table))).filter(objectName -> metadata.getTableHandle(session, objectName).isPresent() || metadata.getView(session, objectName).isPresent()).map(QualifiedTablePrefix::toQualifiedTablePrefix).collect(toImmutableSet());
    }
    return prefixes.stream().flatMap(prefix -> Stream.concat(metadata.listTables(session, prefix).stream(), metadata.listViews(session, prefix).stream())).filter(objectName -> !predicate.isPresent() || predicate.get().test(asFixedValues(objectName))).map(QualifiedTablePrefix::toQualifiedTablePrefix).collect(toImmutableSet());
}
Also used : ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) Slice(io.airlift.slice.Slice) FullConnectorSession(io.prestosql.FullConnectorSession) NullableValue(io.prestosql.spi.predicate.NullableValue) EquatableValueSet(io.prestosql.spi.predicate.EquatableValueSet) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Collectors.toMap(java.util.stream.Collectors.toMap) TableMetadataBuilder.tableMetadataBuilder(io.prestosql.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) ConnectorTableProperties(io.prestosql.spi.connector.ConnectorTableProperties) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) MetadataUtil.findColumnMetadata(io.prestosql.metadata.MetadataUtil.findColumnMetadata) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) ENGLISH(java.util.Locale.ENGLISH) ConnectorTableLayoutHandle(io.prestosql.spi.connector.ConnectorTableLayoutHandle) Constraint(io.prestosql.spi.connector.Constraint) ImmutableSet(com.google.common.collect.ImmutableSet) ConstraintApplicationResult(io.prestosql.spi.connector.ConstraintApplicationResult) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TupleDomain(io.prestosql.spi.predicate.TupleDomain) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Predicates.compose(com.google.common.base.Predicates.compose) Metadata(io.prestosql.metadata.Metadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) ConnectorTableLayout(io.prestosql.spi.connector.ConnectorTableLayout) List(java.util.List) Stream(java.util.stream.Stream) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) Domain(io.prestosql.spi.predicate.Domain) Entry(java.util.Map.Entry) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) SchemaMetadataBuilder.schemaMetadataBuilder(io.prestosql.metadata.MetadataUtil.SchemaMetadataBuilder.schemaMetadataBuilder) SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) QualifiedTablePrefix(io.prestosql.metadata.QualifiedTablePrefix) EquatableValueSet(io.prestosql.spi.predicate.EquatableValueSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) FullConnectorSession(io.prestosql.FullConnectorSession) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Session(io.prestosql.Session) FullConnectorSession(io.prestosql.FullConnectorSession)

Example 5 with QualifiedTablePrefix

use of io.prestosql.metadata.QualifiedTablePrefix in project hetu-core by openlookeng.

the class InformationSchemaPageSourceProvider method buildColumns.

private InternalTable buildColumns(Session session, Set<QualifiedTablePrefix> prefixes) {
    InternalTable.Builder table = InternalTable.builder(informationSchemaTableColumns(TABLE_COLUMNS));
    for (QualifiedTablePrefix prefix : prefixes) {
        for (Entry<SchemaTableName, List<ColumnMetadata>> entry : listTableColumns(session, metadata, accessControl, prefix).entrySet()) {
            SchemaTableName tableName = entry.getKey();
            int ordinalPosition = 1;
            for (ColumnMetadata column : entry.getValue()) {
                if (column.isHidden()) {
                    continue;
                }
                table.add(prefix.getCatalogName(), tableName.getSchemaName(), tableName.getTableName(), column.getName(), ordinalPosition, null, "YES", column.getType().getDisplayName(), column.getComment(), column.getExtraInfo(), column.getComment());
                ordinalPosition++;
            }
        }
    }
    return table.build();
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) QualifiedTablePrefix(io.prestosql.metadata.QualifiedTablePrefix) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) InternalTable(io.prestosql.metadata.InternalTable) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Aggregations

QualifiedTablePrefix (io.prestosql.metadata.QualifiedTablePrefix)8 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)7 Session (io.prestosql.Session)6 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)6 TableMetadataBuilder.tableMetadataBuilder (io.prestosql.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder)5 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 FullConnectorSession (io.prestosql.FullConnectorSession)3 SystemConnectorSessionUtil.toSession (io.prestosql.connector.system.SystemConnectorSessionUtil.toSession)3 Metadata (io.prestosql.metadata.Metadata)3 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)3 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)3 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)3 TupleDomain (io.prestosql.spi.predicate.TupleDomain)3 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)3 List (java.util.List)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Predicates.compose (com.google.common.base.Predicates.compose)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2