Search in sources :

Example 1 with OutputColumnMetadata

use of io.trino.spi.eventlistener.OutputColumnMetadata 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 OutputColumnMetadata

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

the class TestEventListenerBasic method testReferencedTablesInCreateMaterializedView.

@Test
public void testReferencedTablesInCreateMaterializedView() throws Exception {
    runQueryAndWaitForEvents("CREATE MATERIALIZED VIEW mock.default.test_view AS SELECT * FROM nation", 2);
    QueryCompletedEvent event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    assertThat(event.getIoMetadata().getOutput().get().getCatalogName()).isEqualTo("mock");
    assertThat(event.getIoMetadata().getOutput().get().getSchema()).isEqualTo("default");
    assertThat(event.getIoMetadata().getOutput().get().getTable()).isEqualTo("test_view");
    assertThat(event.getIoMetadata().getOutput().get().getColumns().get()).containsExactly(new OutputColumnMetadata("nationkey", BIGINT_TYPE, ImmutableSet.of(new ColumnDetail("tpch", "tiny", "nation", "nationkey"))), new OutputColumnMetadata("name", "varchar(25)", ImmutableSet.of(new ColumnDetail("tpch", "tiny", "nation", "name"))), new OutputColumnMetadata("regionkey", BIGINT_TYPE, ImmutableSet.of(new ColumnDetail("tpch", "tiny", "nation", "regionkey"))), new OutputColumnMetadata("comment", "varchar(152)", ImmutableSet.of(new ColumnDetail("tpch", "tiny", "nation", "comment"))));
    List<TableInfo> tables = event.getMetadata().getTables();
    assertThat(tables).hasSize(1);
    TableInfo table = tables.get(0);
    assertThat(table.getCatalog()).isEqualTo("tpch");
    assertThat(table.getSchema()).isEqualTo("tiny");
    assertThat(table.getTable()).isEqualTo("nation");
    assertThat(table.getAuthorization()).isEqualTo("user");
    assertThat(table.isDirectlyReferenced()).isTrue();
    assertThat(table.getFilters()).isEmpty();
    assertThat(table.getColumns()).hasSize(4);
}
Also used : ColumnDetail(io.trino.spi.eventlistener.ColumnDetail) QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) TableInfo(io.trino.spi.eventlistener.TableInfo) OutputColumnMetadata(io.trino.spi.eventlistener.OutputColumnMetadata) Test(org.testng.annotations.Test)

Example 3 with OutputColumnMetadata

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

the class TestEventListenerBasic method testOutputColumnsForUpdatingSingleColumn.

@Test
public void testOutputColumnsForUpdatingSingleColumn() throws Exception {
    runQueryAndWaitForEvents("UPDATE mock.default.table_for_output SET test_varchar = 're-reset' WHERE test_bigint = 1", 2);
    QueryCompletedEvent event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    assertThat(event.getIoMetadata().getOutput().get().getColumns().get()).containsExactly(new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of()));
}
Also used : QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) OutputColumnMetadata(io.trino.spi.eventlistener.OutputColumnMetadata) Test(org.testng.annotations.Test)

Example 4 with OutputColumnMetadata

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

the class TestEventListenerBasic method testOutputColumnsForCreateTableAsSelectAllFromView.

@Test
public void testOutputColumnsForCreateTableAsSelectAllFromView() throws Exception {
    runQueryAndWaitForEvents("CREATE TABLE mock.default.create_new_table AS SELECT * FROM mock.default.test_view", 2);
    QueryCompletedEvent event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    assertThat(event.getIoMetadata().getOutput().get().getColumns().get()).containsExactly(new OutputColumnMetadata("test_column", BIGINT_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "test_view", "test_column"))));
}
Also used : ColumnDetail(io.trino.spi.eventlistener.ColumnDetail) QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) OutputColumnMetadata(io.trino.spi.eventlistener.OutputColumnMetadata) Test(org.testng.annotations.Test)

Example 5 with OutputColumnMetadata

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

the class TestEventListenerBasic method testOutputColumnsForInsertingSingleColumn.

@Test
public void testOutputColumnsForInsertingSingleColumn() throws Exception {
    runQueryAndWaitForEvents("INSERT INTO mock.default.table_for_output(test_bigint) SELECT nationkey + 1 AS test_bigint FROM nation", 2);
    QueryCompletedEvent event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    assertThat(event.getIoMetadata().getOutput().get().getColumns().get()).containsExactly(new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of(new ColumnDetail("tpch", "tiny", "nation", "nationkey"))));
}
Also used : ColumnDetail(io.trino.spi.eventlistener.ColumnDetail) QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) OutputColumnMetadata(io.trino.spi.eventlistener.OutputColumnMetadata) Test(org.testng.annotations.Test)

Aggregations

OutputColumnMetadata (io.trino.spi.eventlistener.OutputColumnMetadata)14 QueryCompletedEvent (io.trino.spi.eventlistener.QueryCompletedEvent)13 Test (org.testng.annotations.Test)13 ColumnDetail (io.trino.spi.eventlistener.ColumnDetail)9 TableInfo (io.trino.spi.eventlistener.TableInfo)3 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 ColumnInfo (io.trino.spi.eventlistener.ColumnInfo)1 QueryIOMetadata (io.trino.spi.eventlistener.QueryIOMetadata)1 QueryInputMetadata (io.trino.spi.eventlistener.QueryInputMetadata)1 QueryOutputMetadata (io.trino.spi.eventlistener.QueryOutputMetadata)1 Analysis (io.trino.sql.analyzer.Analysis)1 List (java.util.List)1 OptionalLong (java.util.OptionalLong)1