Search in sources :

Example 6 with Builder

use of io.trino.spi.connector.InMemoryRecordSet.Builder in project trino by trinodb.

the class CatalogJdbcTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Session session = ((FullConnectorSession) connectorSession).getSession();
    Builder table = InMemoryRecordSet.builder(METADATA);
    for (String name : listCatalogs(session, metadata, accessControl).keySet()) {
        table.addRow(name);
    }
    return table.build().cursor();
}
Also used : TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(io.trino.spi.connector.InMemoryRecordSet.Builder) FullConnectorSession(io.trino.FullConnectorSession) ConnectorSession(io.trino.spi.connector.ConnectorSession) Session(io.trino.Session) FullConnectorSession(io.trino.FullConnectorSession)

Example 7 with Builder

use of io.trino.spi.connector.InMemoryRecordSet.Builder in project trino by trinodb.

the class CatalogSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Session session = ((FullConnectorSession) connectorSession).getSession();
    Builder table = InMemoryRecordSet.builder(CATALOG_TABLE);
    for (Map.Entry<String, Catalog> entry : getCatalogs(session, metadata, accessControl).entrySet()) {
        table.addRow(entry.getKey(), entry.getValue().getConnectorCatalogName().toString(), entry.getValue().getConnectorName());
    }
    return table.build().cursor();
}
Also used : TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(io.trino.spi.connector.InMemoryRecordSet.Builder) Map(java.util.Map) Catalog(io.trino.metadata.Catalog) FullConnectorSession(io.trino.FullConnectorSession) ConnectorSession(io.trino.spi.connector.ConnectorSession) Session(io.trino.Session) FullConnectorSession(io.trino.FullConnectorSession)

Example 8 with Builder

use of io.trino.spi.connector.InMemoryRecordSet.Builder in project trino by trinodb.

the class QuerySystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    checkState(dispatchManager.isPresent(), "Query system table can return results only on coordinator");
    List<BasicQueryInfo> queries = dispatchManager.get().getQueries();
    queries = filterQueries(((FullConnectorSession) session).getSession().getIdentity(), queries, accessControl);
    Builder table = InMemoryRecordSet.builder(QUERY_TABLE);
    for (BasicQueryInfo queryInfo : queries) {
        Optional<QueryInfo> fullQueryInfo = dispatchManager.get().getFullQueryInfo(queryInfo.getQueryId());
        if (fullQueryInfo.isEmpty()) {
            continue;
        }
        QueryStats queryStats = fullQueryInfo.get().getQueryStats();
        table.addRow(queryInfo.getQueryId().toString(), queryInfo.getState().toString(), queryInfo.getSession().getUser(), queryInfo.getSession().getSource().orElse(null), queryInfo.getQuery(), queryInfo.getResourceGroupId().map(QuerySystemTable::resourceGroupIdToBlock).orElse(null), toMillis(queryStats.getQueuedTime()), toMillis(queryStats.getAnalysisTime()), toMillis(queryStats.getPlanningTime()), toTimestampWithTimeZoneMillis(queryStats.getCreateTime()), toTimestampWithTimeZoneMillis(queryStats.getExecutionStartTime()), toTimestampWithTimeZoneMillis(queryStats.getLastHeartbeat()), toTimestampWithTimeZoneMillis(queryStats.getEndTime()), Optional.ofNullable(queryInfo.getErrorType()).map(Enum::name).orElse(null), Optional.ofNullable(queryInfo.getErrorCode()).map(ErrorCode::getName).orElse(null));
    }
    return table.build().cursor();
}
Also used : QueryStats(io.trino.execution.QueryStats) BasicQueryInfo(io.trino.server.BasicQueryInfo) TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(io.trino.spi.connector.InMemoryRecordSet.Builder) BlockBuilder(io.trino.spi.block.BlockBuilder) ErrorCode(io.trino.spi.ErrorCode) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryInfo(io.trino.execution.QueryInfo)

Example 9 with Builder

use of io.trino.spi.connector.InMemoryRecordSet.Builder in project trino by trinodb.

the class ColumnJdbcTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Builder table = InMemoryRecordSet.builder(METADATA);
    if (constraint.isNone()) {
        return table.build().cursor();
    }
    Session session = ((FullConnectorSession) connectorSession).getSession();
    boolean omitDateTimeTypePrecision = isOmitDateTimeTypePrecision(session);
    Optional<String> catalogFilter = tryGetSingleVarcharValue(constraint, 0);
    Optional<String> schemaFilter = tryGetSingleVarcharValue(constraint, 1);
    Optional<String> tableFilter = tryGetSingleVarcharValue(constraint, 2);
    Domain catalogDomain = constraint.getDomains().get().getOrDefault(0, Domain.all(createUnboundedVarcharType()));
    Domain schemaDomain = constraint.getDomains().get().getOrDefault(1, Domain.all(createUnboundedVarcharType()));
    Domain tableDomain = constraint.getDomains().get().getOrDefault(2, Domain.all(createUnboundedVarcharType()));
    if (isNonLowercase(schemaFilter) || isNonLowercase(tableFilter)) {
        // Non-lowercase predicate will never match a lowercase name (until TODO https://github.com/trinodb/trino/issues/17)
        return table.build().cursor();
    }
    for (String catalog : listCatalogs(session, metadata, accessControl, catalogFilter).keySet()) {
        if (!catalogDomain.includesNullableValue(utf8Slice(catalog))) {
            continue;
        }
        if ((schemaDomain.isAll() && tableDomain.isAll()) || schemaFilter.isPresent()) {
            QualifiedTablePrefix tablePrefix = tablePrefix(catalog, schemaFilter, tableFilter);
            Map<SchemaTableName, List<ColumnMetadata>> tableColumns = listTableColumns(session, metadata, accessControl, tablePrefix);
            addColumnsRow(table, catalog, tableColumns, omitDateTimeTypePrecision);
        } else {
            Collection<String> schemas = listSchemas(session, metadata, accessControl, catalog, schemaFilter);
            for (String schema : schemas) {
                if (!schemaDomain.includesNullableValue(utf8Slice(schema))) {
                    continue;
                }
                QualifiedTablePrefix tablePrefix = tableFilter.isPresent() ? new QualifiedTablePrefix(catalog, schema, tableFilter.get()) : new QualifiedTablePrefix(catalog, schema);
                Set<SchemaTableName> tables = listTables(session, metadata, accessControl, tablePrefix);
                for (SchemaTableName schemaTableName : tables) {
                    String tableName = schemaTableName.getTableName();
                    if (!tableDomain.includesNullableValue(utf8Slice(tableName))) {
                        continue;
                    }
                    Map<SchemaTableName, List<ColumnMetadata>> tableColumns = listTableColumns(session, metadata, accessControl, new QualifiedTablePrefix(catalog, schema, tableName));
                    addColumnsRow(table, catalog, tableColumns, omitDateTimeTypePrecision);
                }
            }
        }
    }
    return table.build().cursor();
}
Also used : TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(io.trino.spi.connector.InMemoryRecordSet.Builder) SchemaTableName(io.trino.spi.connector.SchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) QualifiedTablePrefix(io.trino.metadata.QualifiedTablePrefix) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) Session(io.trino.Session) FullConnectorSession(io.trino.FullConnectorSession) ConnectorSession(io.trino.spi.connector.ConnectorSession) FullConnectorSession(io.trino.FullConnectorSession)

Example 10 with Builder

use of io.trino.spi.connector.InMemoryRecordSet.Builder in project trino by trinodb.

the class TableJdbcTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Session session = ((FullConnectorSession) connectorSession).getSession();
    Optional<String> catalogFilter = tryGetSingleVarcharValue(constraint, 0);
    Optional<String> schemaFilter = tryGetSingleVarcharValue(constraint, 1);
    Optional<String> tableFilter = tryGetSingleVarcharValue(constraint, 2);
    Optional<String> typeFilter = tryGetSingleVarcharValue(constraint, 3);
    boolean includeTables = emptyOrEquals(typeFilter, "TABLE");
    boolean includeViews = emptyOrEquals(typeFilter, "VIEW");
    Builder table = InMemoryRecordSet.builder(METADATA);
    if (!includeTables && !includeViews) {
        return table.build().cursor();
    }
    if (isNonLowercase(schemaFilter) || isNonLowercase(tableFilter)) {
        // Non-lowercase predicate will never match a lowercase name (until TODO https://github.com/trinodb/trino/issues/17)
        return table.build().cursor();
    }
    for (String catalog : listCatalogs(session, metadata, accessControl, catalogFilter).keySet()) {
        QualifiedTablePrefix prefix = tablePrefix(catalog, schemaFilter, tableFilter);
        Set<SchemaTableName> views = listViews(session, metadata, accessControl, prefix);
        for (SchemaTableName name : listTables(session, metadata, accessControl, prefix)) {
            boolean isView = views.contains(name);
            if ((includeTables && !isView) || (includeViews && isView)) {
                table.addRow(tableRow(catalog, name, isView ? "VIEW" : "TABLE"));
            }
        }
    }
    return table.build().cursor();
}
Also used : QualifiedTablePrefix(io.trino.metadata.QualifiedTablePrefix) TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(io.trino.spi.connector.InMemoryRecordSet.Builder) SchemaTableName(io.trino.spi.connector.SchemaTableName) FullConnectorSession(io.trino.FullConnectorSession) ConnectorSession(io.trino.spi.connector.ConnectorSession) Session(io.trino.Session) FullConnectorSession(io.trino.FullConnectorSession)

Aggregations

TableMetadataBuilder.tableMetadataBuilder (io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder)10 Builder (io.trino.spi.connector.InMemoryRecordSet.Builder)10 FullConnectorSession (io.trino.FullConnectorSession)7 Session (io.trino.Session)7 ConnectorSession (io.trino.spi.connector.ConnectorSession)7 QualifiedTablePrefix (io.trino.metadata.QualifiedTablePrefix)4 SchemaTableName (io.trino.spi.connector.SchemaTableName)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)2 Map (java.util.Map)2 VerifyException (com.google.common.base.VerifyException)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Slices (io.airlift.slice.Slices)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 SystemSessionProperties.isOmitDateTimeTypePrecision (io.trino.SystemSessionProperties.isOmitDateTimeTypePrecision)1 SystemColumnHandle (io.trino.connector.system.SystemColumnHandle)1 FilterUtil.tablePrefix (io.trino.connector.system.jdbc.FilterUtil.tablePrefix)1 FilterUtil.tryGetSingleVarcharValue (io.trino.connector.system.jdbc.FilterUtil.tryGetSingleVarcharValue)1 QueryInfo (io.trino.execution.QueryInfo)1