Search in sources :

Example 6 with TableInfo

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

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

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

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