Search in sources :

Example 1 with Builder

use of io.prestosql.spi.connector.InMemoryRecordSet.Builder 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 Builder

use of io.prestosql.spi.connector.InMemoryRecordSet.Builder in project hetu-core by openlookeng.

the class TaskSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    Builder table = InMemoryRecordSet.builder(TASK_TABLE);
    for (TaskInfo taskInfo : taskManager.getAllTaskInfo()) {
        TaskStats stats = taskInfo.getStats();
        TaskStatus taskStatus = taskInfo.getTaskStatus();
        table.addRow(nodeId, taskStatus.getTaskId().toString(), taskStatus.getTaskId().getStageId().toString(), taskStatus.getTaskId().getQueryId().toString(), taskStatus.getState().toString(), (long) stats.getTotalDrivers(), (long) stats.getQueuedDrivers(), (long) stats.getRunningDrivers(), (long) stats.getCompletedDrivers(), toMillis(stats.getTotalScheduledTime()), toMillis(stats.getTotalCpuTime()), toMillis(stats.getTotalBlockedTime()), toBytes(stats.getRawInputDataSize()), stats.getRawInputPositions(), toBytes(stats.getProcessedInputDataSize()), stats.getProcessedInputPositions(), toBytes(stats.getOutputDataSize()), stats.getOutputPositions(), toBytes(stats.getPhysicalWrittenDataSize()), toTimeStamp(stats.getCreateTime()), toTimeStamp(stats.getFirstStartTime()), toTimeStamp(taskInfo.getLastHeartbeat()), toTimeStamp(stats.getEndTime()));
    }
    return table.build().cursor();
}
Also used : TaskInfo(io.prestosql.execution.TaskInfo) Builder(io.prestosql.spi.connector.InMemoryRecordSet.Builder) TableMetadataBuilder.tableMetadataBuilder(io.prestosql.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) TaskStats(io.prestosql.operator.TaskStats) TaskStatus(io.prestosql.execution.TaskStatus)

Example 3 with Builder

use of io.prestosql.spi.connector.InMemoryRecordSet.Builder in project hetu-core by openlookeng.

the class CatalogJdbcTable method cursor.

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

Example 4 with Builder

use of io.prestosql.spi.connector.InMemoryRecordSet.Builder in project hetu-core by openlookeng.

the class CatalogSystemTable method cursor.

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

Example 5 with Builder

use of io.prestosql.spi.connector.InMemoryRecordSet.Builder in project hetu-core by openlookeng.

the class NodeSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    Builder table = InMemoryRecordSet.builder(NODES_TABLE);
    AllNodes allNodes = nodeManager.getAllNodes();
    addRows(table, allNodes.getActiveNodes(), ACTIVE);
    addRows(table, allNodes.getInactiveNodes(), INACTIVE);
    addRows(table, allNodes.getIsolatingNodes(), ISOLATING);
    addRows(table, allNodes.getIsolatedNodes(), ISOLATED);
    addRows(table, allNodes.getShuttingDownNodes(), SHUTTING_DOWN);
    return table.build().cursor();
}
Also used : Builder(io.prestosql.spi.connector.InMemoryRecordSet.Builder) TableMetadataBuilder.tableMetadataBuilder(io.prestosql.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) AllNodes(io.prestosql.metadata.AllNodes)

Aggregations

TableMetadataBuilder.tableMetadataBuilder (io.prestosql.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder)9 Builder (io.prestosql.spi.connector.InMemoryRecordSet.Builder)9 Session (io.prestosql.Session)6 SystemConnectorSessionUtil.toSession (io.prestosql.connector.system.SystemConnectorSessionUtil.toSession)6 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)6 QualifiedTablePrefix (io.prestosql.metadata.QualifiedTablePrefix)3 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)3 ImmutableSet (com.google.common.collect.ImmutableSet)1 Logger (io.airlift.log.Logger)1 FilterUtil.filter (io.prestosql.connector.system.jdbc.FilterUtil.filter)1 FilterUtil.stringFilter (io.prestosql.connector.system.jdbc.FilterUtil.stringFilter)1 FilterUtil.tablePrefix (io.prestosql.connector.system.jdbc.FilterUtil.tablePrefix)1 QueryInfo (io.prestosql.execution.QueryInfo)1 QueryStats (io.prestosql.execution.QueryStats)1 TaskInfo (io.prestosql.execution.TaskInfo)1 TaskStatus (io.prestosql.execution.TaskStatus)1 AllNodes (io.prestosql.metadata.AllNodes)1 Metadata (io.prestosql.metadata.Metadata)1 MetadataListing.listCatalogs (io.prestosql.metadata.MetadataListing.listCatalogs)1 MetadataListing.listTables (io.prestosql.metadata.MetadataListing.listTables)1