Search in sources :

Example 16 with OperatorStats

use of io.trino.operator.OperatorStats in project trino by trinodb.

the class BaseFailureRecoveryTest method testJoinDynamicFilteringEnabled.

@Test(invocationCount = INVOCATION_COUNT)
public void testJoinDynamicFilteringEnabled() {
    @Language("SQL") String selectQuery = "SELECT * FROM partitioned_lineitem JOIN supplier ON partitioned_lineitem.suppkey = supplier.suppkey " + "AND supplier.name = 'Supplier#000000001'";
    testSelect(selectQuery, Optional.of(enableDynamicFiltering(true)), queryId -> {
        DynamicFiltersStats dynamicFiltersStats = getDynamicFilteringStats(queryId);
        assertThat(dynamicFiltersStats.getLazyDynamicFilters()).isEqualTo(1);
        DynamicFilterDomainStats domainStats = getOnlyElement(dynamicFiltersStats.getDynamicFilterDomainStats());
        assertThat(domainStats.getSimplifiedDomain()).isEqualTo(singleValue(BIGINT, 1L).toString(getSession().toConnectorSession()));
        OperatorStats probeStats = searchScanFilterAndProjectOperatorStats(queryId, getQualifiedTableName(PARTITIONED_LINEITEM));
        // Currently, stats from all attempts are combined.
        // Asserting on multiple of 615L as well in case the probe scan was completed twice
        assertThat(probeStats.getInputPositions()).isIn(615L, 1230L);
    });
}
Also used : DynamicFilterDomainStats(io.trino.server.DynamicFilterService.DynamicFilterDomainStats) Language(org.intellij.lang.annotations.Language) DynamicFiltersStats(io.trino.server.DynamicFilterService.DynamicFiltersStats) OperatorStats(io.trino.operator.OperatorStats) Test(org.testng.annotations.Test)

Example 17 with OperatorStats

use of io.trino.operator.OperatorStats in project trino by trinodb.

the class AbstractTestJoinQueries method assertJoinOutputPositions.

private void assertJoinOutputPositions(@Language("SQL") String sql, int expectedJoinOutputPositions) {
    ResultWithQueryId<MaterializedResult> result = getDistributedQueryRunner().executeWithQueryId(Session.builder(getSession()).setSystemProperty(JOIN_REORDERING_STRATEGY, "NONE").build(), sql);
    assertEquals(result.getResult().getMaterializedRows().get(0).getField(0), 0L);
    QueryStats stats = getDistributedQueryRunner().getCoordinator().getQueryManager().getFullQueryInfo(result.getQueryId()).getQueryStats();
    int actualJoinOutputPositions = stats.getOperatorSummaries().stream().filter(summary -> summary.getOperatorType().equals("LookupJoinOperator")).map(OperatorStats::getOutputPositions).mapToInt(Math::toIntExact).sum();
    assertEquals(actualJoinOutputPositions, expectedJoinOutputPositions);
}
Also used : NATION(io.trino.tpch.TpchTable.NATION) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) ORDERS(io.trino.tpch.TpchTable.ORDERS) QueryTemplate.parameter(io.trino.tests.QueryTemplate.parameter) CUSTOMER(io.trino.tpch.TpchTable.CUSTOMER) QueryAssertions.assertEqualsIgnoreOrder(io.trino.testing.QueryAssertions.assertEqualsIgnoreOrder) ImmutableList(com.google.common.collect.ImmutableList) SystemSessionProperties(io.trino.SystemSessionProperties) JOIN_REORDERING_STRATEGY(io.trino.SystemSessionProperties.JOIN_REORDERING_STRATEGY) TpchTable(io.trino.tpch.TpchTable) PART(io.trino.tpch.TpchTable.PART) QueryTemplate(io.trino.tests.QueryTemplate) OperatorStats(io.trino.operator.OperatorStats) Language(org.intellij.lang.annotations.Language) REGION(io.trino.tpch.TpchTable.REGION) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) QueryTemplate.queryTemplate(io.trino.tests.QueryTemplate.queryTemplate) JoinDistributionType(io.trino.sql.planner.OptimizerConfig.JoinDistributionType) String.format(java.lang.String.format) List(java.util.List) QueryStats(io.trino.execution.QueryStats) BIGINT(io.trino.spi.type.BigintType.BIGINT) Decimals(io.trino.spi.type.Decimals) Assert.assertTrue(org.testng.Assert.assertTrue) LINE_ITEM(io.trino.tpch.TpchTable.LINE_ITEM) Session(io.trino.Session) MaterializedResult.resultBuilder(io.trino.testing.MaterializedResult.resultBuilder) QueryStats(io.trino.execution.QueryStats) OperatorStats(io.trino.operator.OperatorStats)

Example 18 with OperatorStats

use of io.trino.operator.OperatorStats in project trino by trinodb.

the class QueryMonitor method createQueryStatistics.

private QueryStatistics createQueryStatistics(QueryInfo queryInfo) {
    ImmutableList.Builder<String> operatorSummaries = ImmutableList.builder();
    for (OperatorStats summary : queryInfo.getQueryStats().getOperatorSummaries()) {
        operatorSummaries.add(operatorStatsCodec.toJson(summary));
    }
    Optional<StatsAndCosts> planNodeStatsAndCosts = queryInfo.getOutputStage().map(StatsAndCosts::create);
    Optional<String> serializedPlanNodeStatsAndCosts = planNodeStatsAndCosts.map(statsAndCostsCodec::toJson);
    QueryStats queryStats = queryInfo.getQueryStats();
    return new QueryStatistics(ofMillis(queryStats.getTotalCpuTime().toMillis()), ofMillis(queryStats.getFailedCpuTime().toMillis()), ofMillis(queryStats.getElapsedTime().toMillis()), ofMillis(queryStats.getQueuedTime().toMillis()), Optional.of(ofMillis(queryStats.getTotalScheduledTime().toMillis())), Optional.of(ofMillis(queryStats.getFailedScheduledTime().toMillis())), Optional.of(ofMillis(queryStats.getResourceWaitingTime().toMillis())), Optional.of(ofMillis(queryStats.getAnalysisTime().toMillis())), Optional.of(ofMillis(queryStats.getPlanningTime().toMillis())), Optional.of(ofMillis(queryStats.getExecutionTime().toMillis())), queryStats.getPeakUserMemoryReservation().toBytes(), queryStats.getPeakTaskUserMemory().toBytes(), queryStats.getPeakTaskTotalMemory().toBytes(), queryStats.getPhysicalInputDataSize().toBytes(), queryStats.getPhysicalInputPositions(), queryStats.getInternalNetworkInputDataSize().toBytes(), queryStats.getInternalNetworkInputPositions(), queryStats.getRawInputDataSize().toBytes(), queryStats.getRawInputPositions(), queryStats.getOutputDataSize().toBytes(), queryStats.getOutputPositions(), queryStats.getLogicalWrittenDataSize().toBytes(), queryStats.getWrittenPositions(), queryStats.getCumulativeUserMemory(), queryStats.getFailedCumulativeUserMemory(), queryStats.getStageGcStatistics(), queryStats.getCompletedDrivers(), queryInfo.isCompleteInfo(), getCpuDistributions(queryInfo), operatorSummaries.build(), serializedPlanNodeStatsAndCosts);
}
Also used : QueryStats(io.trino.execution.QueryStats) QueryStatistics(io.trino.spi.eventlistener.QueryStatistics) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) StatsAndCosts(io.trino.cost.StatsAndCosts) OperatorStats(io.trino.operator.OperatorStats)

Example 19 with OperatorStats

use of io.trino.operator.OperatorStats in project trino by trinodb.

the class QueryMonitor method extractPlanNodeStats.

private static void extractPlanNodeStats(StageInfo stageInfo, ImmutableMultimap.Builder<FragmentNode, OperatorStats> planNodeStats) {
    PlanFragment fragment = stageInfo.getPlan();
    if (fragment == null) {
        return;
    }
    // Note: a plan node may be mapped to multiple operators
    Map<PlanNodeId, Collection<OperatorStats>> allOperatorStats = Multimaps.index(stageInfo.getStageStats().getOperatorSummaries(), OperatorStats::getPlanNodeId).asMap();
    // Sometimes a plan node is merged with other nodes into a single operator, and in that case,
    // use the stats of the nearest parent node with stats.
    fragment.getRoot().accept(new PlanVisitor<Void, Collection<OperatorStats>>() {

        @Override
        protected Void visitPlan(PlanNode node, Collection<OperatorStats> parentStats) {
            Collection<OperatorStats> operatorStats = allOperatorStats.getOrDefault(node.getId(), parentStats);
            planNodeStats.putAll(new FragmentNode(fragment.getId(), node.getId()), operatorStats);
            for (PlanNode child : node.getSources()) {
                child.accept(this, operatorStats);
            }
            return null;
        }
    }, ImmutableList.of());
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PlanNode(io.trino.sql.planner.plan.PlanNode) Collection(java.util.Collection) OperatorStats(io.trino.operator.OperatorStats) PlanFragment(io.trino.sql.planner.PlanFragment)

Example 20 with OperatorStats

use of io.trino.operator.OperatorStats in project trino by trinodb.

the class SplitMonitor method splitCompletedEvent.

private void splitCompletedEvent(TaskId taskId, DriverStats driverStats, @Nullable String failureType, @Nullable String failureMessage) {
    Duration queuedTime = ofMillis(driverStats.getQueuedTime().toMillis());
    Optional<Duration> queuedTimeIfSplitRan = Optional.empty();
    if (driverStats.getStartTime() != null) {
        queuedTimeIfSplitRan = Optional.of(queuedTime);
    }
    Duration elapsedTime = ofMillis(driverStats.getElapsedTime().toMillis());
    Optional<Duration> elapsedTimeIfSplitRan = Optional.empty();
    if (driverStats.getEndTime() != null) {
        elapsedTimeIfSplitRan = Optional.of(elapsedTime);
    }
    Optional<SplitFailureInfo> splitFailureMetadata = Optional.empty();
    if (failureType != null) {
        splitFailureMetadata = Optional.of(new SplitFailureInfo(failureType, failureMessage != null ? failureMessage : ""));
    }
    Optional<String> splitCatalog = driverStats.getOperatorStats().stream().map(OperatorStats::getInfo).filter(SplitOperatorInfo.class::isInstance).map(SplitOperatorInfo.class::cast).map(info -> info.getCatalogName().getCatalogName()).findFirst();
    try {
        eventListenerManager.splitCompleted(new SplitCompletedEvent(taskId.getQueryId().toString(), taskId.getStageId().toString(), taskId.toString(), splitCatalog, driverStats.getCreateTime().toDate().toInstant(), Optional.ofNullable(driverStats.getStartTime()).map(startTime -> startTime.toDate().toInstant()), Optional.ofNullable(driverStats.getEndTime()).map(endTime -> endTime.toDate().toInstant()), new SplitStatistics(ofMillis(driverStats.getTotalCpuTime().toMillis()), elapsedTime, queuedTime, ofMillis(driverStats.getRawInputReadTime().toMillis()), driverStats.getRawInputPositions(), driverStats.getRawInputDataSize().toBytes(), queuedTimeIfSplitRan, elapsedTimeIfSplitRan), splitFailureMetadata, objectMapper.writeValueAsString(driverStats)));
    } catch (JsonProcessingException e) {
        log.error(e, "Error processing split completion event for task %s", taskId);
    }
}
Also used : SplitCompletedEvent(io.trino.spi.eventlistener.SplitCompletedEvent) SplitFailureInfo(io.trino.spi.eventlistener.SplitFailureInfo) Logger(io.airlift.log.Logger) OperatorStats(io.trino.operator.OperatorStats) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DriverStats(io.trino.operator.DriverStats) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TaskId(io.trino.execution.TaskId) SplitStatistics(io.trino.spi.eventlistener.SplitStatistics) Inject(javax.inject.Inject) EventListenerManager(io.trino.eventlistener.EventListenerManager) Duration(java.time.Duration) Objects.requireNonNull(java.util.Objects.requireNonNull) SplitOperatorInfo(io.trino.operator.SplitOperatorInfo) Optional(java.util.Optional) Duration.ofMillis(java.time.Duration.ofMillis) Nullable(javax.annotation.Nullable) SplitCompletedEvent(io.trino.spi.eventlistener.SplitCompletedEvent) SplitStatistics(io.trino.spi.eventlistener.SplitStatistics) SplitFailureInfo(io.trino.spi.eventlistener.SplitFailureInfo) Duration(java.time.Duration) SplitOperatorInfo(io.trino.operator.SplitOperatorInfo) OperatorStats(io.trino.operator.OperatorStats) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

OperatorStats (io.trino.operator.OperatorStats)29 Test (org.testng.annotations.Test)18 Language (org.intellij.lang.annotations.Language)15 DynamicFilterDomainStats (io.trino.server.DynamicFilterService.DynamicFilterDomainStats)14 DynamicFiltersStats (io.trino.server.DynamicFilterService.DynamicFiltersStats)14 DynamicFiltersTestUtil.getSimplifiedDomainString (io.trino.util.DynamicFiltersTestUtil.getSimplifiedDomainString)13 ImmutableList (com.google.common.collect.ImmutableList)4 Session (io.trino.Session)3 MaterializedResult (io.trino.testing.MaterializedResult)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Duration (io.airlift.units.Duration)2 QueryStats (io.trino.execution.QueryStats)2 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)2 BlockedReason (io.trino.operator.BlockedReason)2 PipelineStats (io.trino.operator.PipelineStats)2 StageGcStatistics (io.trino.spi.eventlistener.StageGcStatistics)2 PlanFragment (io.trino.sql.planner.PlanFragment)2 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)2 BaseConnectorTest (io.trino.testing.BaseConnectorTest)2 HashSet (java.util.HashSet)2