Search in sources :

Example 1 with QueryIOMetadata

use of io.trino.spi.eventlistener.QueryIOMetadata in project trino by trinodb.

the class QueryMonitor method getQueryIOMetadata.

private static QueryIOMetadata getQueryIOMetadata(QueryInfo queryInfo) {
    Multimap<FragmentNode, OperatorStats> planNodeStats = extractPlanNodeStats(queryInfo);
    ImmutableList.Builder<QueryInputMetadata> inputs = ImmutableList.builder();
    for (Input input : queryInfo.getInputs()) {
        // Note: input table can be mapped to multiple operators
        Collection<OperatorStats> inputTableOperatorStats = planNodeStats.get(new FragmentNode(input.getFragmentId(), input.getPlanNodeId()));
        OptionalLong physicalInputBytes = OptionalLong.empty();
        OptionalLong physicalInputPositions = OptionalLong.empty();
        if (!inputTableOperatorStats.isEmpty()) {
            physicalInputBytes = OptionalLong.of(inputTableOperatorStats.stream().map(OperatorStats::getPhysicalInputDataSize).mapToLong(DataSize::toBytes).sum());
            physicalInputPositions = OptionalLong.of(inputTableOperatorStats.stream().mapToLong(OperatorStats::getPhysicalInputPositions).sum());
        }
        inputs.add(new QueryInputMetadata(input.getCatalogName(), input.getSchema(), input.getTable(), input.getColumns().stream().map(Column::getName).collect(Collectors.toList()), input.getConnectorInfo(), physicalInputBytes, physicalInputPositions));
    }
    Optional<QueryOutputMetadata> output = Optional.empty();
    if (queryInfo.getOutput().isPresent()) {
        Optional<TableFinishInfo> tableFinishInfo = queryInfo.getQueryStats().getOperatorSummaries().stream().map(OperatorStats::getInfo).filter(TableFinishInfo.class::isInstance).map(TableFinishInfo.class::cast).findFirst();
        Optional<List<OutputColumnMetadata>> outputColumnsMetadata = queryInfo.getOutput().get().getColumns().map(columns -> columns.stream().map(column -> new OutputColumnMetadata(column.getColumn().getName(), column.getColumn().getType(), column.getSourceColumns().stream().map(Analysis.SourceColumn::getColumnDetail).collect(toImmutableSet()))).collect(toImmutableList()));
        output = Optional.of(new QueryOutputMetadata(queryInfo.getOutput().get().getCatalogName(), queryInfo.getOutput().get().getSchema(), queryInfo.getOutput().get().getTable(), outputColumnsMetadata, tableFinishInfo.map(TableFinishInfo::getConnectorOutputMetadata), tableFinishInfo.map(TableFinishInfo::isJsonLengthLimitExceeded)));
    }
    return new QueryIOMetadata(inputs.build(), output);
}
Also used : TableFinishInfo(io.trino.operator.TableFinishInfo) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) QueryOutputMetadata(io.trino.spi.eventlistener.QueryOutputMetadata) OperatorStats(io.trino.operator.OperatorStats) QueryInputMetadata(io.trino.spi.eventlistener.QueryInputMetadata) Input(io.trino.execution.Input) Analysis(io.trino.sql.analyzer.Analysis) OptionalLong(java.util.OptionalLong) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) QueryIOMetadata(io.trino.spi.eventlistener.QueryIOMetadata) OutputColumnMetadata(io.trino.spi.eventlistener.OutputColumnMetadata)

Example 2 with QueryIOMetadata

use of io.trino.spi.eventlistener.QueryIOMetadata in project trino by trinodb.

the class QueryMonitor method queryImmediateFailureEvent.

public void queryImmediateFailureEvent(BasicQueryInfo queryInfo, ExecutionFailureInfo failure) {
    eventListenerManager.queryCompleted(new QueryCompletedEvent(new QueryMetadata(queryInfo.getQueryId().toString(), queryInfo.getSession().getTransactionId().map(TransactionId::toString), queryInfo.getQuery(), queryInfo.getUpdateType(), queryInfo.getPreparedQuery(), queryInfo.getState().toString(), ImmutableList.of(), ImmutableList.of(), queryInfo.getSelf(), Optional.empty(), Optional.empty()), new QueryStatistics(ofMillis(0), ofMillis(0), ofMillis(0), ofMillis(queryInfo.getQueryStats().getQueuedTime().toMillis()), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ImmutableList.of(), 0, true, ImmutableList.of(), ImmutableList.of(), Optional.empty()), createQueryContext(queryInfo.getSession(), queryInfo.getResourceGroupId(), queryInfo.getQueryType()), new QueryIOMetadata(ImmutableList.of(), Optional.empty()), createQueryFailureInfo(failure, Optional.empty()), ImmutableList.of(), ofEpochMilli(queryInfo.getQueryStats().getCreateTime().getMillis()), ofEpochMilli(queryInfo.getQueryStats().getEndTime().getMillis()), ofEpochMilli(queryInfo.getQueryStats().getEndTime().getMillis())));
    logQueryTimeline(queryInfo);
}
Also used : QueryMetadata(io.trino.spi.eventlistener.QueryMetadata) QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) QueryStatistics(io.trino.spi.eventlistener.QueryStatistics) QueryIOMetadata(io.trino.spi.eventlistener.QueryIOMetadata)

Aggregations

QueryIOMetadata (io.trino.spi.eventlistener.QueryIOMetadata)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Input (io.trino.execution.Input)1 OperatorStats (io.trino.operator.OperatorStats)1 TableFinishInfo (io.trino.operator.TableFinishInfo)1 OutputColumnMetadata (io.trino.spi.eventlistener.OutputColumnMetadata)1 QueryCompletedEvent (io.trino.spi.eventlistener.QueryCompletedEvent)1 QueryInputMetadata (io.trino.spi.eventlistener.QueryInputMetadata)1 QueryMetadata (io.trino.spi.eventlistener.QueryMetadata)1 QueryOutputMetadata (io.trino.spi.eventlistener.QueryOutputMetadata)1 QueryStatistics (io.trino.spi.eventlistener.QueryStatistics)1 Analysis (io.trino.sql.analyzer.Analysis)1 List (java.util.List)1 OptionalLong (java.util.OptionalLong)1