Search in sources :

Example 1 with QualifiedTablePrefix

use of com.facebook.presto.metadata.QualifiedTablePrefix in project presto by prestodb.

the class ColumnJdbcTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Session session = toSession(transactionHandle, connectorSession);
    Optional<String> catalogFilter = stringFilter(constraint, 0);
    Optional<String> schemaFilter = stringFilter(constraint, 1);
    Optional<String> tableFilter = stringFilter(constraint, 2);
    Builder table = InMemoryRecordSet.builder(METADATA);
    for (String catalog : filter(listCatalogs(session, metadata, accessControl).keySet(), catalogFilter)) {
        QualifiedTablePrefix prefix = FilterUtil.tablePrefix(catalog, schemaFilter, tableFilter);
        for (Entry<SchemaTableName, List<ColumnMetadata>> entry : listTableColumns(session, metadata, accessControl, prefix).entrySet()) {
            addColumnRows(table, catalog, entry.getKey(), entry.getValue());
        }
    }
    return table.build().cursor();
}
Also used : QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(com.facebook.presto.spi.InMemoryRecordSet.Builder) List(java.util.List) SchemaTableName(com.facebook.presto.spi.SchemaTableName) SystemConnectorSessionUtil.toSession(com.facebook.presto.connector.system.SystemConnectorSessionUtil.toSession) Session(com.facebook.presto.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession)

Example 2 with QualifiedTablePrefix

use of com.facebook.presto.metadata.QualifiedTablePrefix in project presto by prestodb.

the class InformationSchemaPageSourceProvider method buildTables.

private InternalTable buildTables(Session session, String catalogName, Map<String, NullableValue> filters) {
    QualifiedTablePrefix prefix = extractQualifiedTablePrefix(catalogName, filters);
    Set<SchemaTableName> tables = listTables(session, metadata, accessControl, prefix);
    Set<SchemaTableName> views = listViews(session, metadata, accessControl, prefix);
    InternalTable.Builder table = InternalTable.builder(informationSchemaTableColumns(TABLE_TABLES));
    for (SchemaTableName name : union(tables, views)) {
        // if table and view names overlap, the view wins
        String type = views.contains(name) ? "VIEW" : "BASE TABLE";
        table.add(catalogName, name.getSchemaName(), name.getTableName(), type);
    }
    return table.build();
}
Also used : QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) SchemaTableName(com.facebook.presto.spi.SchemaTableName) InternalTable(com.facebook.presto.metadata.InternalTable)

Example 3 with QualifiedTablePrefix

use of com.facebook.presto.metadata.QualifiedTablePrefix in project presto by prestodb.

the class InformationSchemaPageSourceProvider method buildColumns.

private InternalTable buildColumns(Session session, String catalogName, Map<String, NullableValue> filters) {
    InternalTable.Builder table = InternalTable.builder(informationSchemaTableColumns(TABLE_COLUMNS));
    QualifiedTablePrefix prefix = extractQualifiedTablePrefix(catalogName, filters);
    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(catalogName, tableName.getSchemaName(), tableName.getTableName(), column.getName(), ordinalPosition, null, "YES", column.getType().getDisplayName(), column.getComment(), column.getExtraInfo());
            ordinalPosition++;
        }
    }
    return table.build();
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) InternalTable(com.facebook.presto.metadata.InternalTable) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Constraint(com.facebook.presto.spi.Constraint)

Example 4 with QualifiedTablePrefix

use of com.facebook.presto.metadata.QualifiedTablePrefix in project presto by prestodb.

the class TableJdbcTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Session session = toSession(transactionHandle, connectorSession);
    Optional<String> catalogFilter = stringFilter(constraint, 0);
    Optional<String> schemaFilter = stringFilter(constraint, 1);
    Optional<String> tableFilter = stringFilter(constraint, 2);
    Optional<String> typeFilter = stringFilter(constraint, 3);
    Builder table = InMemoryRecordSet.builder(METADATA);
    for (String catalog : filter(listCatalogs(session, metadata, accessControl).keySet(), catalogFilter)) {
        QualifiedTablePrefix prefix = tablePrefix(catalog, schemaFilter, tableFilter);
        if (FilterUtil.emptyOrEquals(typeFilter, "TABLE")) {
            for (SchemaTableName name : listTables(session, metadata, accessControl, prefix)) {
                table.addRow(tableRow(catalog, name, "TABLE"));
            }
        }
        if (FilterUtil.emptyOrEquals(typeFilter, "VIEW")) {
            for (SchemaTableName name : listViews(session, metadata, accessControl, prefix)) {
                table.addRow(tableRow(catalog, name, "VIEW"));
            }
        }
    }
    return table.build().cursor();
}
Also used : QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(com.facebook.presto.spi.InMemoryRecordSet.Builder) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Session(com.facebook.presto.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession) SystemConnectorSessionUtil.toSession(com.facebook.presto.connector.system.SystemConnectorSessionUtil.toSession)

Aggregations

QualifiedTablePrefix (com.facebook.presto.metadata.QualifiedTablePrefix)4 SchemaTableName (com.facebook.presto.spi.SchemaTableName)4 Session (com.facebook.presto.Session)2 SystemConnectorSessionUtil.toSession (com.facebook.presto.connector.system.SystemConnectorSessionUtil.toSession)2 InternalTable (com.facebook.presto.metadata.InternalTable)2 TableMetadataBuilder.tableMetadataBuilder (com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder)2 ConnectorSession (com.facebook.presto.spi.ConnectorSession)2 Builder (com.facebook.presto.spi.InMemoryRecordSet.Builder)2 List (java.util.List)2 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)1 Constraint (com.facebook.presto.spi.Constraint)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1