Search in sources :

Example 21 with QueryCompletedEvent

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

the class TestEventListenerBasic method testReferencedTablesInCreateView.

@Test
public void testReferencedTablesInCreateView() throws Exception {
    runQueryAndWaitForEvents("CREATE VIEW mock.default.create_another_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("create_another_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 22 with QueryCompletedEvent

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

the class TestEventListenerBasic method testOutputColumnsForUpdatingAllColumns.

@Test
public void testOutputColumnsForUpdatingAllColumns() throws Exception {
    runQueryAndWaitForEvents("UPDATE mock.default.table_for_output SET test_varchar = 'reset', 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()), new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of()));
}
Also used : QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) OutputColumnMetadata(io.trino.spi.eventlistener.OutputColumnMetadata) Test(org.testng.annotations.Test)

Example 23 with QueryCompletedEvent

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

the class TestEventListenerBasic method testCreateTableLike.

@Test
public void testCreateTableLike() throws Exception {
    runQueryAndWaitForEvents("CREATE TABLE mock.default.create_simple_table (test_column BIGINT, LIKE mock.default.test_table)", 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("create_simple_table");
    assertThat(event.getIoMetadata().getOutput().get().getColumns().get()).containsExactly(new OutputColumnMetadata("test_column", BIGINT_TYPE, ImmutableSet.of()), new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of()), new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of()));
}
Also used : QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) OutputColumnMetadata(io.trino.spi.eventlistener.OutputColumnMetadata) Test(org.testng.annotations.Test)

Example 24 with QueryCompletedEvent

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

the class TestEventListenerBasic method testOutputColumnsForInsertingAliasedColumn.

@Test
public void testOutputColumnsForInsertingAliasedColumn() throws Exception {
    runQueryAndWaitForEvents("INSERT INTO mock.default.table_for_output(test_varchar, test_bigint) SELECT name AS aliased_name, nationkey AS aliased_varchar FROM nation", 2);
    QueryCompletedEvent event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    assertThat(event.getIoMetadata().getOutput().get().getColumns().get()).containsExactly(new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of(new ColumnDetail("tpch", "tiny", "nation", "name"))), 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)

Example 25 with QueryCompletedEvent

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

the class TestEventListenerBasic method testOutputStats.

@Test
public void testOutputStats() throws Exception {
    MaterializedResult result = runQueryAndWaitForEvents("SELECT 1 FROM lineitem", 2);
    QueryCreatedEvent queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    QueryCompletedEvent queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    QueryStats queryStats = getDistributedQueryRunner().getCoordinator().getQueryManager().getFullQueryInfo(new QueryId(queryCreatedEvent.getMetadata().getQueryId())).getQueryStats();
    assertTrue(queryStats.getOutputDataSize().toBytes() > 0L);
    assertTrue(queryCompletedEvent.getStatistics().getOutputBytes() > 0L);
    assertEquals(result.getRowCount(), queryStats.getOutputPositions());
    assertEquals(result.getRowCount(), queryCompletedEvent.getStatistics().getOutputRows());
    runQueryAndWaitForEvents("SELECT COUNT(1) FROM lineitem", 2);
    queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    queryStats = getDistributedQueryRunner().getCoordinator().getQueryManager().getFullQueryInfo(new QueryId(queryCreatedEvent.getMetadata().getQueryId())).getQueryStats();
    assertTrue(queryStats.getOutputDataSize().toBytes() > 0L);
    assertTrue(queryCompletedEvent.getStatistics().getOutputBytes() > 0L);
    assertEquals(1L, queryStats.getOutputPositions());
    assertEquals(1L, queryCompletedEvent.getStatistics().getOutputRows());
    // Ensure the proper conversion in QueryMonitor#createQueryStatistics
    QueryStatistics statistics = queryCompletedEvent.getStatistics();
    assertEquals(statistics.getCpuTime().toMillis(), queryStats.getTotalCpuTime().toMillis());
    assertEquals(statistics.getWallTime().toMillis(), queryStats.getElapsedTime().toMillis());
    assertEquals(statistics.getQueuedTime().toMillis(), queryStats.getQueuedTime().toMillis());
    assertEquals(statistics.getScheduledTime().get().toMillis(), queryStats.getTotalScheduledTime().toMillis());
    assertEquals(statistics.getResourceWaitingTime().get().toMillis(), queryStats.getResourceWaitingTime().toMillis());
    assertEquals(statistics.getAnalysisTime().get().toMillis(), queryStats.getAnalysisTime().toMillis());
    assertEquals(statistics.getPlanningTime().get().toMillis(), queryStats.getPlanningTime().toMillis());
    assertEquals(statistics.getExecutionTime().get().toMillis(), queryStats.getExecutionTime().toMillis());
    assertEquals(statistics.getPeakUserMemoryBytes(), queryStats.getPeakUserMemoryReservation().toBytes());
    assertEquals(statistics.getPeakTaskUserMemory(), queryStats.getPeakTaskUserMemory().toBytes());
    assertEquals(statistics.getPeakTaskTotalMemory(), queryStats.getPeakTaskTotalMemory().toBytes());
    assertEquals(statistics.getPhysicalInputBytes(), queryStats.getPhysicalInputDataSize().toBytes());
    assertEquals(statistics.getPhysicalInputRows(), queryStats.getPhysicalInputPositions());
    assertEquals(statistics.getInternalNetworkBytes(), queryStats.getInternalNetworkInputDataSize().toBytes());
    assertEquals(statistics.getInternalNetworkRows(), queryStats.getInternalNetworkInputPositions());
    assertEquals(statistics.getTotalBytes(), queryStats.getRawInputDataSize().toBytes());
    assertEquals(statistics.getTotalRows(), queryStats.getRawInputPositions());
    assertEquals(statistics.getOutputBytes(), queryStats.getOutputDataSize().toBytes());
    assertEquals(statistics.getOutputRows(), queryStats.getOutputPositions());
    assertEquals(statistics.getWrittenBytes(), queryStats.getLogicalWrittenDataSize().toBytes());
    assertEquals(statistics.getWrittenRows(), queryStats.getWrittenPositions());
    assertEquals(statistics.getCumulativeMemory(), queryStats.getCumulativeUserMemory());
    assertEquals(statistics.getStageGcStatistics(), queryStats.getStageGcStatistics());
    assertEquals(statistics.getCompletedSplits(), queryStats.getCompletedDrivers());
}
Also used : QueryCreatedEvent(io.trino.spi.eventlistener.QueryCreatedEvent) QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) QueryStatistics(io.trino.spi.eventlistener.QueryStatistics) QueryId(io.trino.spi.QueryId) MaterializedResult(io.trino.testing.MaterializedResult) 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