|
51 | 51 | import io.trino.spi.eventlistener.TableInfo; |
52 | 52 | import io.trino.spi.metrics.Metrics; |
53 | 53 | import io.trino.spi.security.ViewExpression; |
| 54 | +import io.trino.spi.type.ArrayType; |
54 | 55 | import io.trino.spi.type.Type; |
55 | 56 | import io.trino.spi.type.TypeManager; |
56 | 57 | import io.trino.spi.type.TypeSignature; |
@@ -110,6 +111,9 @@ public class TestEventListenerBasic |
110 | 111 | private static final String IGNORE_EVENT_MARKER = " -- ignore_generated_event"; |
111 | 112 | private static final String VARCHAR_TYPE = "varchar(15)"; |
112 | 113 | private static final String BIGINT_TYPE = BIGINT.getDisplayName(); |
| 114 | + private static final String VARCHAR_ARRAY_TYPE = "array(varchar(15))"; |
| 115 | + private static final String BIGINT_ARRAY_TYPE = "array(bigint)"; |
| 116 | + private static final Type VARCHAR_15 = createVarcharType(15); |
113 | 117 | private static final Metrics TEST_METRICS = new Metrics(ImmutableMap.of("test_metrics", new LongCount(1))); |
114 | 118 |
|
115 | 119 | private EventsAwaitingQueries queries; |
@@ -155,8 +159,10 @@ public Iterable<ConnectorFactory> getConnectorFactories() |
155 | 159 | return ImmutableList.of(new ColumnMetadata("test_column", BIGINT)); |
156 | 160 | } |
157 | 161 | return ImmutableList.of( |
158 | | - new ColumnMetadata("test_varchar", createVarcharType(15)), |
159 | | - new ColumnMetadata("test_bigint", BIGINT)); |
| 162 | + new ColumnMetadata("test_varchar", VARCHAR_15), |
| 163 | + new ColumnMetadata("test_bigint", BIGINT), |
| 164 | + new ColumnMetadata("test_varchar_array", new ArrayType(VARCHAR_15)), |
| 165 | + new ColumnMetadata("test_bigint_array", new ArrayType(BIGINT))); |
160 | 166 | }) |
161 | 167 | .withGetTableHandle((session, schemaTableName) -> { |
162 | 168 | if (!schemaTableName.getTableName().startsWith("create")) { |
@@ -194,7 +200,7 @@ public Iterable<ConnectorFactory> getConnectorFactories() |
194 | 200 | "SELECT test_varchar AS test_column FROM mock.default.test_table_with_row_filter", |
195 | 201 | Optional.empty(), |
196 | 202 | Optional.empty(), |
197 | | - ImmutableList.of(new ConnectorViewDefinition.ViewColumn("test_column", createVarcharType(15).getTypeId(), Optional.empty())), |
| 203 | + ImmutableList.of(new ConnectorViewDefinition.ViewColumn("test_column", VARCHAR_15.getTypeId(), Optional.empty())), |
198 | 204 | Optional.empty(), |
199 | 205 | Optional.empty(), |
200 | 206 | true, |
@@ -761,7 +767,7 @@ public void testReferencedTablesWithColumnMask() |
761 | 767 | throws Exception |
762 | 768 | { |
763 | 769 | QueryEvents queryEvents = runQueryAndWaitForEvents( |
764 | | - "CREATE TABLE mock.default.create_table_with_referring_mask AS SELECT * FROM mock.default.test_table_with_column_mask" |
| 770 | + "CREATE TABLE mock.default.create_table_with_referring_mask AS SELECT test_varchar, test_bigint FROM mock.default.test_table_with_column_mask" |
765 | 771 | ).getQueryEvents(); |
766 | 772 |
|
767 | 773 | QueryCompletedEvent event = queryEvents.getQueryCompletedEvent(); |
@@ -1372,7 +1378,9 @@ public void testCreateTableLike() |
1372 | 1378 | .containsExactly( |
1373 | 1379 | new OutputColumnMetadata("test_column", BIGINT_TYPE, ImmutableSet.of()), |
1374 | 1380 | new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of()), |
1375 | | - new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of())); |
| 1381 | + new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of()), |
| 1382 | + new OutputColumnMetadata("test_varchar_array", VARCHAR_ARRAY_TYPE, ImmutableSet.of()), |
| 1383 | + new OutputColumnMetadata("test_bigint_array", BIGINT_ARRAY_TYPE, ImmutableSet.of())); |
1376 | 1384 | } |
1377 | 1385 |
|
1378 | 1386 | @Test |
@@ -1419,6 +1427,27 @@ private void testOutputColumnsForSetOperations(String setOperator) |
1419 | 1427 | new ColumnDetail("tpch", "sf1", "orders", "custkey")))); |
1420 | 1428 | } |
1421 | 1429 |
|
| 1430 | + @Test |
| 1431 | + public void testOutputColumnsWithUnnestQueries() |
| 1432 | + throws Exception |
| 1433 | + { |
| 1434 | + assertLineage( |
| 1435 | + "SELECT test_varchar_unnest AS test_varchar, test_bigint AS test_bigint FROM mock.default.tests_table_unnest CROSS JOIN UNNEST(test_varchar_array) AS t(test_varchar_unnest)", |
| 1436 | + ImmutableSet.of("mock.default.tests_table_unnest"), |
| 1437 | + new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "tests_table_unnest", "test_varchar_array"))), |
| 1438 | + new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "tests_table_unnest", "test_bigint")))); |
| 1439 | + assertLineage( |
| 1440 | + "SELECT test_varchar_unnest AS test_varchar, test_bigint_unnest AS test_bigint FROM mock.default.tests_table_unnest CROSS JOIN UNNEST(test_varchar_array) WITH ORDINALITY AS t(test_varchar_unnest, test_bigint_unnest)", |
| 1441 | + ImmutableSet.of("mock.default.tests_table_unnest"), |
| 1442 | + new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "tests_table_unnest", "test_varchar_array"))), |
| 1443 | + new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of())); |
| 1444 | + assertLineage( |
| 1445 | + "SELECT test_varchar_unnest AS test_varchar, test_bigint_unnest AS test_bigint FROM mock.default.tests_table_unnest CROSS JOIN UNNEST(test_varchar_array, test_bigint_array) AS t(test_varchar_unnest, test_bigint_unnest)", |
| 1446 | + ImmutableSet.of("mock.default.tests_table_unnest"), |
| 1447 | + new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "tests_table_unnest", "test_varchar_array"))), |
| 1448 | + new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "tests_table_unnest", "test_bigint_array")))); |
| 1449 | + } |
| 1450 | + |
1422 | 1451 | @Test |
1423 | 1452 | public void testTableStats() |
1424 | 1453 | throws Exception |
|
0 commit comments