use of io.trino.execution.QueryInfo in project trino by trinodb.
the class BaseConnectorTest method testWrittenStats.
@Test
public void testWrittenStats() {
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));
skipTestUnless(hasBehavior(SUPPORTS_INSERT));
String tableName = "test_written_stats_" + randomTableSuffix();
try {
String sql = "CREATE TABLE " + tableName + " AS SELECT * FROM nation";
ResultWithQueryId<MaterializedResult> resultResultWithQueryId = getDistributedQueryRunner().executeWithQueryId(getSession(), sql);
QueryInfo queryInfo = getDistributedQueryRunner().getCoordinator().getQueryManager().getFullQueryInfo(resultResultWithQueryId.getQueryId());
assertEquals(queryInfo.getQueryStats().getOutputPositions(), 1L);
assertEquals(queryInfo.getQueryStats().getWrittenPositions(), 25L);
assertTrue(queryInfo.getQueryStats().getLogicalWrittenDataSize().toBytes() > 0L);
sql = "INSERT INTO " + tableName + " SELECT * FROM nation LIMIT 10";
resultResultWithQueryId = getDistributedQueryRunner().executeWithQueryId(getSession(), sql);
queryInfo = getDistributedQueryRunner().getCoordinator().getQueryManager().getFullQueryInfo(resultResultWithQueryId.getQueryId());
assertEquals(queryInfo.getQueryStats().getOutputPositions(), 1L);
assertEquals(queryInfo.getQueryStats().getWrittenPositions(), 10L);
assertTrue(queryInfo.getQueryStats().getLogicalWrittenDataSize().toBytes() > 0L);
} finally {
assertUpdate("DROP TABLE IF EXISTS " + tableName);
}
}
use of io.trino.execution.QueryInfo in project trino by trinodb.
the class TestLateMaterializationQueries method assertLazyQuery.
private void assertLazyQuery(@Language("SQL") String sql) {
QueryManager queryManager = getDistributedQueryRunner().getCoordinator().getQueryManager();
ResultWithQueryId<MaterializedResult> workProcessorResultResultWithQueryId = getDistributedQueryRunner().executeWithQueryId(lateMaterialization(), sql);
QueryInfo workProcessorQueryInfo = queryManager.getFullQueryInfo(workProcessorResultResultWithQueryId.getQueryId());
ResultWithQueryId<MaterializedResult> noWorkProcessorResultResultWithQueryId = getDistributedQueryRunner().executeWithQueryId(noLateMaterialization(), sql);
QueryInfo noWorkProcessorQueryInfo = queryManager.getFullQueryInfo(noWorkProcessorResultResultWithQueryId.getQueryId());
// ensure results are correct
MaterializedResult expected = computeExpected(sql, workProcessorResultResultWithQueryId.getResult().getTypes());
assertEqualsIgnoreOrder(workProcessorResultResultWithQueryId.getResult(), expected, "For query: \n " + sql);
assertEqualsIgnoreOrder(noWorkProcessorResultResultWithQueryId.getResult(), expected, "For query: \n " + sql);
// ensure work processor query processed less input data
long workProcessorProcessedInputBytes = workProcessorQueryInfo.getQueryStats().getProcessedInputDataSize().toBytes();
long noWorkProcessorProcessedInputBytes = noWorkProcessorQueryInfo.getQueryStats().getProcessedInputDataSize().toBytes();
assertTrue(workProcessorProcessedInputBytes < noWorkProcessorProcessedInputBytes, "Expected work processor query to process less input data");
}
use of io.trino.execution.QueryInfo 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();
}
use of io.trino.execution.QueryInfo in project trino by trinodb.
the class ExplainAnalyzeOperator method getOutput.
@Override
public Page getOutput() {
if (!finishing) {
return null;
}
QueryInfo queryInfo = queryPerformanceFetcher.getQueryInfo(operatorContext.getDriverContext().getTaskId().getQueryId());
checkState(queryInfo.getOutputStage().isPresent(), "Output stage is missing");
checkState(queryInfo.getOutputStage().get().getSubStages().size() == 1, "Expected one sub stage of explain node");
if (!hasFinalStageInfo(queryInfo.getOutputStage().get())) {
return null;
}
String plan = textDistributedPlan(queryInfo.getOutputStage().get().getSubStages().get(0), queryInfo.getQueryStats(), metadata, functionManager, operatorContext.getSession(), verbose);
BlockBuilder builder = VARCHAR.createBlockBuilder(null, 1);
VARCHAR.writeString(builder, plan);
outputConsumed = true;
return new Page(builder.build());
}
use of io.trino.execution.QueryInfo in project trino by trinodb.
the class TestBasicQueryInfo method testConstructor.
@Test
public void testConstructor() {
BasicQueryInfo basicInfo = new BasicQueryInfo(new QueryInfo(new QueryId("0"), TEST_SESSION.toSessionRepresentation(), RUNNING, false, URI.create("1"), ImmutableList.of("2", "3"), "SELECT 4", Optional.empty(), new QueryStats(DateTime.parse("1991-09-06T05:00-05:30"), DateTime.parse("1991-09-06T05:01-05:30"), DateTime.parse("1991-09-06T05:02-05:30"), DateTime.parse("1991-09-06T06:00-05:30"), new Duration(8, MINUTES), new Duration(7, MINUTES), new Duration(35, MINUTES), new Duration(35, MINUTES), new Duration(44, MINUTES), new Duration(9, MINUTES), new Duration(99, SECONDS), new Duration(12, MINUTES), 13, 14, 15, 16, 17, 18, 19, 34, 20, 21.0, 22.0, DataSize.valueOf("23GB"), DataSize.valueOf("24GB"), DataSize.valueOf("25GB"), DataSize.valueOf("26GB"), DataSize.valueOf("27GB"), DataSize.valueOf("28GB"), DataSize.valueOf("29GB"), DataSize.valueOf("30GB"), DataSize.valueOf("31GB"), true, new Duration(32, MINUTES), new Duration(33, MINUTES), new Duration(34, MINUTES), new Duration(35, MINUTES), new Duration(36, MINUTES), true, ImmutableSet.of(BlockedReason.WAITING_FOR_MEMORY), DataSize.valueOf("271GB"), DataSize.valueOf("271GB"), 281, 281, new Duration(37, MINUTES), new Duration(38, MINUTES), DataSize.valueOf("272GB"), DataSize.valueOf("272GB"), 282, 282, DataSize.valueOf("39GB"), DataSize.valueOf("40GB"), 41, 42, DataSize.valueOf("43GB"), DataSize.valueOf("44GB"), 45, 46, DataSize.valueOf("47GB"), DataSize.valueOf("48GB"), 49, 50, DataSize.valueOf("51GB"), DataSize.valueOf("52GB"), ImmutableList.of(new StageGcStatistics(101, 102, 103, 104, 105, 106, 107)), DynamicFiltersStats.EMPTY, ImmutableList.of()), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(), ImmutableSet.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.empty(), false, "33", Optional.empty(), null, StandardErrorCode.ABANDONED_QUERY.toErrorCode(), ImmutableList.of(), ImmutableSet.of(), Optional.empty(), ImmutableList.of(), ImmutableList.of(), false, Optional.empty(), Optional.of(QueryType.SELECT)));
assertEquals(basicInfo.getQueryId().getId(), "0");
assertEquals(basicInfo.getState(), RUNNING);
assertEquals(basicInfo.isScheduled(), false);
assertEquals(basicInfo.getQuery(), "SELECT 4");
assertEquals(basicInfo.getQueryType().get(), QueryType.SELECT);
assertEquals(basicInfo.getQueryStats().getCreateTime(), DateTime.parse("1991-09-06T05:00-05:30"));
assertEquals(basicInfo.getQueryStats().getEndTime(), DateTime.parse("1991-09-06T06:00-05:30"));
assertEquals(basicInfo.getQueryStats().getElapsedTime(), new Duration(8, MINUTES));
assertEquals(basicInfo.getQueryStats().getExecutionTime(), new Duration(44, MINUTES));
assertEquals(basicInfo.getQueryStats().getTotalDrivers(), 17);
assertEquals(basicInfo.getQueryStats().getQueuedDrivers(), 18);
assertEquals(basicInfo.getQueryStats().getRunningDrivers(), 19);
assertEquals(basicInfo.getQueryStats().getCompletedDrivers(), 20);
assertEquals(basicInfo.getQueryStats().getCumulativeUserMemory(), 21.0);
assertEquals(basicInfo.getQueryStats().getFailedCumulativeUserMemory(), 22.0);
assertEquals(basicInfo.getQueryStats().getUserMemoryReservation(), DataSize.valueOf("23GB"));
assertEquals(basicInfo.getQueryStats().getTotalMemoryReservation(), DataSize.valueOf("25GB"));
assertEquals(basicInfo.getQueryStats().getPeakUserMemoryReservation(), DataSize.valueOf("26GB"));
assertEquals(basicInfo.getQueryStats().getTotalScheduledTime(), new Duration(32, MINUTES));
assertEquals(basicInfo.getQueryStats().getFailedScheduledTime(), new Duration(33, MINUTES));
assertEquals(basicInfo.getQueryStats().getTotalCpuTime(), new Duration(34, MINUTES));
assertEquals(basicInfo.getQueryStats().getFailedCpuTime(), new Duration(35, MINUTES));
assertEquals(basicInfo.getQueryStats().isFullyBlocked(), true);
assertEquals(basicInfo.getQueryStats().getBlockedReasons(), ImmutableSet.of(BlockedReason.WAITING_FOR_MEMORY));
assertEquals(basicInfo.getQueryStats().getProgressPercentage(), OptionalDouble.of(100));
assertEquals(basicInfo.getErrorCode(), StandardErrorCode.ABANDONED_QUERY.toErrorCode());
assertEquals(basicInfo.getErrorType(), StandardErrorCode.ABANDONED_QUERY.toErrorCode().getType());
}
Aggregations