Search in sources :

Example 11 with QueryCompletedEvent

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

the class TestEventListenerBasic method testReferencedTablesWithViews.

@Test
public void testReferencedTablesWithViews() throws Exception {
    runQueryAndWaitForEvents("SELECT test_column FROM mock.default.test_view", 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("nationkey");
    assertThat(column.getMasks()).isEmpty();
    table = tables.get(1);
    assertThat(table.getCatalog()).isEqualTo("mock");
    assertThat(table.getSchema()).isEqualTo("default");
    assertThat(table.getTable()).isEqualTo("test_view");
    assertThat(table.getAuthorization()).isEqualTo("user");
    assertThat(table.isDirectlyReferenced()).isTrue();
    assertThat(table.getFilters()).isEmpty();
    assertThat(table.getColumns()).hasSize(1);
    column = table.getColumns().get(0);
    assertThat(column.getColumn()).isEqualTo("test_column");
    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 12 with QueryCompletedEvent

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

the class TestEventListenerBasic method testReferencedTablesWithMaterializedViews.

@Test
public void testReferencedTablesWithMaterializedViews() throws Exception {
    runQueryAndWaitForEvents("SELECT test_column FROM mock.default.test_materialized_view", 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("alice");
    assertThat(table.isDirectlyReferenced()).isFalse();
    assertThat(table.getFilters()).isEmpty();
    assertThat(table.getColumns()).hasSize(1);
    ColumnInfo column = table.getColumns().get(0);
    assertThat(column.getColumn()).isEqualTo("nationkey");
    assertThat(column.getMasks()).isEmpty();
    table = tables.get(1);
    assertThat(table.getCatalog()).isEqualTo("mock");
    assertThat(table.getSchema()).isEqualTo("default");
    assertThat(table.getTable()).isEqualTo("test_materialized_view");
    assertThat(table.getAuthorization()).isEqualTo("user");
    assertThat(table.isDirectlyReferenced()).isTrue();
    assertThat(table.getFilters()).isEmpty();
    assertThat(table.getColumns()).hasSize(1);
    column = table.getColumns().get(0);
    assertThat(column.getColumn()).isEqualTo("test_column");
    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 13 with QueryCompletedEvent

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

the class TestEventListenerBasic method testReferencedTablesAndRoutines.

@Test
public void testReferencedTablesAndRoutines() throws Exception {
    runQueryAndWaitForEvents("SELECT sum(linenumber) FROM lineitem", 2);
    QueryCompletedEvent event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    List<TableInfo> tables = event.getMetadata().getTables();
    assertEquals(tables.size(), 1);
    TableInfo table = tables.get(0);
    assertEquals(table.getCatalog(), "tpch");
    assertEquals(table.getSchema(), "tiny");
    assertEquals(table.getTable(), "lineitem");
    assertEquals(table.getAuthorization(), "user");
    assertTrue(table.getFilters().isEmpty());
    assertEquals(table.getColumns().size(), 1);
    ColumnInfo column = table.getColumns().get(0);
    assertEquals(column.getColumn(), "linenumber");
    assertTrue(column.getMasks().isEmpty());
    List<RoutineInfo> routines = event.getMetadata().getRoutines();
    assertEquals(tables.size(), 1);
    RoutineInfo routine = routines.get(0);
    assertEquals(routine.getRoutine(), "sum");
    assertEquals(routine.getAuthorization(), "user");
}
Also used : QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) ColumnInfo(io.trino.spi.eventlistener.ColumnInfo) TableInfo(io.trino.spi.eventlistener.TableInfo) RoutineInfo(io.trino.spi.eventlistener.RoutineInfo) Test(org.testng.annotations.Test)

Example 14 with QueryCompletedEvent

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

the class TestEventListenerBasic method assertLineage.

private void assertLineage(Set<String> inputTables, OutputColumnMetadata... outputColumnMetadata) {
    QueryCompletedEvent event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    assertThat(event.getMetadata().getTables()).map(TestEventListenerBasic::getQualifiedName).containsExactlyInAnyOrderElementsOf(inputTables);
    if (outputColumnMetadata.length != 0) {
        assertThat(event.getIoMetadata().getOutput().get().getColumns().get()).containsExactly(outputColumnMetadata);
    }
}
Also used : QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent)

Example 15 with QueryCompletedEvent

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

the class TestEventListenerBasic method testOutputColumnsForCreateTableAsSelectWithAliasedColumn.

@Test
public void testOutputColumnsForCreateTableAsSelectWithAliasedColumn() throws Exception {
    runQueryAndWaitForEvents("CREATE TABLE mock.default.create_new_table(aliased_bigint, aliased_varchar) AS SELECT nationkey AS keynation, concat(name, comment) FROM nation", 2);
    QueryCompletedEvent event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    assertThat(event.getIoMetadata().getOutput().get().getColumns().get()).containsExactly(new OutputColumnMetadata("aliased_bigint", BIGINT_TYPE, ImmutableSet.of(new ColumnDetail("tpch", "tiny", "nation", "nationkey"))), new OutputColumnMetadata("aliased_varchar", "varchar", ImmutableSet.of(new ColumnDetail("tpch", "tiny", "nation", "name"), new ColumnDetail("tpch", "tiny", "nation", "comment"))));
}
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