Search in sources :

Example 1 with TableInfo

use of io.trino.spi.eventlistener.TableInfo 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 2 with TableInfo

use of io.trino.spi.eventlistener.TableInfo 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 3 with TableInfo

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

the class TestEventListenerBasic method testReferencedColumns.

@Test
public void testReferencedColumns() throws Exception {
    // assert that ColumnInfos for referenced columns are present when the table was not aliased
    runQueryAndWaitForEvents("SELECT name, nationkey FROM nation", 2);
    QueryCompletedEvent event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    TableInfo table = getOnlyElement(event.getMetadata().getTables());
    assertEquals(table.getColumns().stream().map(ColumnInfo::getColumn).collect(toImmutableSet()), ImmutableSet.of("name", "nationkey"));
    // assert that ColumnInfos for referenced columns are present when the table was aliased
    runQueryAndWaitForEvents("SELECT name, nationkey FROM nation n", 2);
    event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    table = getOnlyElement(event.getMetadata().getTables());
    assertEquals(table.getColumns().stream().map(ColumnInfo::getColumn).collect(toImmutableSet()), ImmutableSet.of("name", "nationkey"));
    // assert that ColumnInfos for referenced columns are present when the table was aliased and its columns were aliased
    runQueryAndWaitForEvents("SELECT a, b FROM nation n(a, b, c, d)", 2);
    event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    table = getOnlyElement(event.getMetadata().getTables());
    assertEquals(table.getColumns().stream().map(ColumnInfo::getColumn).collect(toImmutableSet()), ImmutableSet.of("name", "nationkey"));
}
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 4 with TableInfo

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

the class TestEventListenerBasic method testReferencedTablesWithColumnMask.

@Test
public void testReferencedTablesWithColumnMask() throws Exception {
    runQueryAndWaitForEvents("CREATE TABLE mock.default.create_table_with_referring_mask AS SELECT * FROM mock.default.test_table_with_column_mask", 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_table_with_referring_mask");
    assertThat(event.getIoMetadata().getOutput().get().getColumns().get()).containsExactly(new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "test_table_with_column_mask", "test_varchar"))), new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "test_table_with_column_mask", "test_bigint"))));
    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("orders");
    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("orderkey");
    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_column_mask");
    assertThat(table.getAuthorization()).isEqualTo("user");
    assertThat(table.isDirectlyReferenced()).isTrue();
    assertThat(table.getFilters()).isEmpty();
    assertThat(table.getColumns()).hasSize(2);
    column = table.getColumns().get(0);
    assertThat(column.getColumn()).isEqualTo("test_varchar");
    assertThat(column.getMasks()).hasSize(1);
    column = table.getColumns().get(1);
    assertThat(column.getColumn()).isEqualTo("test_bigint");
    assertThat(column.getMasks()).isEmpty();
}
Also used : ColumnDetail(io.trino.spi.eventlistener.ColumnDetail) QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) ColumnInfo(io.trino.spi.eventlistener.ColumnInfo) TableInfo(io.trino.spi.eventlistener.TableInfo) OutputColumnMetadata(io.trino.spi.eventlistener.OutputColumnMetadata) Test(org.testng.annotations.Test)

Example 5 with TableInfo

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

Aggregations

QueryCompletedEvent (io.trino.spi.eventlistener.QueryCompletedEvent)8 TableInfo (io.trino.spi.eventlistener.TableInfo)8 Test (org.testng.annotations.Test)8 ColumnInfo (io.trino.spi.eventlistener.ColumnInfo)6 ColumnDetail (io.trino.spi.eventlistener.ColumnDetail)3 OutputColumnMetadata (io.trino.spi.eventlistener.OutputColumnMetadata)3 RoutineInfo (io.trino.spi.eventlistener.RoutineInfo)1