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();
}
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();
}
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");
}
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);
}
}
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"))));
}
Aggregations