Search in sources :

Example 6 with ColumnDetail

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

Example 7 with ColumnDetail

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

the class TestEventListenerBasic method testOutputColumnsForCreateTableAsSelectAllFromMaterializedView.

@Test
public void testOutputColumnsForCreateTableAsSelectAllFromMaterializedView() throws Exception {
    runQueryAndWaitForEvents("CREATE TABLE mock.default.create_new_table AS SELECT * FROM mock.default.test_materialized_view", 2);
    QueryCompletedEvent event = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    assertThat(event.getIoMetadata().getOutput().get().getColumns().get()).containsExactly(new OutputColumnMetadata("test_column", BIGINT_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "test_materialized_view", "test_column"))));
}
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 8 with ColumnDetail

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

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

Aggregations

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