use of io.trino.operator.TableFinishInfo 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);
}
Aggregations