Search in sources :

Example 1 with QueryCompletedEvent

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

Example 2 with QueryCompletedEvent

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

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

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

the class TestEventListenerBasic method testReferencedTablesWithRowFilter.

@Test
public void testReferencedTablesWithRowFilter() throws Exception {
    runQueryAndWaitForEvents("SELECT 1 FROM mock.default.test_table_with_row_filter", 2);
    QueryCompletedEvent event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    List<TableInfo> tables = event.getMetadata().getTables();
    assertThat(tables).hasSize(2);
    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()).isFalse();
    assertThat(table.getFilters()).isEmpty();
    assertThat(table.getColumns()).hasSize(1);
    ColumnInfo column = table.getColumns().get(0);
    assertThat(column.getColumn()).isEqualTo("name");
    assertThat(column.getMasks()).isEmpty();
    table = tables.get(1);
    assertThat(table.getCatalog()).isEqualTo("mock");
    assertThat(table.getSchema()).isEqualTo("default");
    assertThat(table.getTable()).isEqualTo("test_table_with_row_filter");
    assertThat(table.getAuthorization()).isEqualTo("user");
    assertThat(table.isDirectlyReferenced()).isTrue();
    assertThat(table.getFilters()).hasSize(1);
    assertThat(table.getColumns()).hasSize(1);
    column = table.getColumns().get(0);
    assertThat(column.getColumn()).isEqualTo("test_varchar");
    assertThat(column.getMasks()).isEmpty();
}
Also used : QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) ColumnInfo(io.trino.spi.eventlistener.ColumnInfo) TableInfo(io.trino.spi.eventlistener.TableInfo) Test(org.testng.annotations.Test)

Example 5 with QueryCompletedEvent

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

Aggregations

QueryCompletedEvent (io.trino.spi.eventlistener.QueryCompletedEvent)26 Test (org.testng.annotations.Test)22 OutputColumnMetadata (io.trino.spi.eventlistener.OutputColumnMetadata)13 ColumnDetail (io.trino.spi.eventlistener.ColumnDetail)9 TableInfo (io.trino.spi.eventlistener.TableInfo)8 ColumnInfo (io.trino.spi.eventlistener.ColumnInfo)6 QueryCreatedEvent (io.trino.spi.eventlistener.QueryCreatedEvent)4 QueryStatistics (io.trino.spi.eventlistener.QueryStatistics)3 Session (io.trino.Session)2 SplitCompletedEvent (io.trino.spi.eventlistener.SplitCompletedEvent)2 MaterializedResult (io.trino.testing.MaterializedResult)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 MockConnectorFactory (io.trino.connector.MockConnectorFactory)1 QueryStats (io.trino.execution.QueryStats)1 TestingEventListenerPlugin (io.trino.execution.TestEventListenerPlugin.TestingEventListenerPlugin)1 TestQueues.createResourceGroupId (io.trino.execution.TestQueues.createResourceGroupId)1 ResourceGroupManagerPlugin (io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin)1