|
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; |
@@ -156,7 +157,9 @@ public Iterable<ConnectorFactory> getConnectorFactories() |
156 | 157 | } |
157 | 158 | return ImmutableList.of( |
158 | 159 | new ColumnMetadata("test_varchar", createVarcharType(15)), |
159 | | - new ColumnMetadata("test_bigint", BIGINT)); |
| 160 | + new ColumnMetadata("test_bigint", BIGINT), |
| 161 | + new ColumnMetadata("test_varchar_array", new ArrayType(createVarcharType(15))), |
| 162 | + new ColumnMetadata("test_bigint_array", new ArrayType(BIGINT))); |
160 | 163 | }) |
161 | 164 | .withGetTableHandle((session, schemaTableName) -> { |
162 | 165 | if (!schemaTableName.getTableName().startsWith("create")) { |
@@ -761,7 +764,7 @@ public void testReferencedTablesWithColumnMask() |
761 | 764 | throws Exception |
762 | 765 | { |
763 | 766 | QueryEvents queryEvents = runQueryAndWaitForEvents( |
764 | | - "CREATE TABLE mock.default.create_table_with_referring_mask AS SELECT * FROM mock.default.test_table_with_column_mask" |
| 767 | + "CREATE TABLE mock.default.create_table_with_referring_mask AS SELECT test_varchar, test_bigint FROM mock.default.test_table_with_column_mask" |
765 | 768 | ).getQueryEvents(); |
766 | 769 |
|
767 | 770 | QueryCompletedEvent event = queryEvents.getQueryCompletedEvent(); |
@@ -1372,7 +1375,9 @@ public void testCreateTableLike() |
1372 | 1375 | .containsExactly( |
1373 | 1376 | new OutputColumnMetadata("test_column", BIGINT_TYPE, ImmutableSet.of()), |
1374 | 1377 | new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of()), |
1375 | | - new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of())); |
| 1378 | + new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of()), |
| 1379 | + new OutputColumnMetadata("test_varchar_array", "array(varchar(15))", ImmutableSet.of()), |
| 1380 | + new OutputColumnMetadata("test_bigint_array", "array(bigint)", ImmutableSet.of())); |
1376 | 1381 | } |
1377 | 1382 |
|
1378 | 1383 | @Test |
@@ -1419,6 +1424,41 @@ private void testOutputColumnsForSetOperations(String setOperator) |
1419 | 1424 | new ColumnDetail("tpch", "sf1", "orders", "custkey")))); |
1420 | 1425 | } |
1421 | 1426 |
|
| 1427 | + @Test |
| 1428 | + public void testOutputColumnsWithUnnestQueries() |
| 1429 | + throws Exception |
| 1430 | + { |
| 1431 | + // test unnest with one array column |
| 1432 | + assertLineage( |
| 1433 | + "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)", |
| 1434 | + ImmutableSet.of("mock.default.tests_table_unnest"), |
| 1435 | + new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "tests_table_unnest", "test_varchar_array"))), |
| 1436 | + new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "tests_table_unnest", "test_bigint")))); |
| 1437 | + // test unnest with one array column and with ordinality |
| 1438 | + assertLineage( |
| 1439 | + "SELECT test_varchar_unnest AS test_varchar, row_number_unnest AS test_bigint FROM mock.default.tests_table_unnest CROSS JOIN UNNEST(test_varchar_array) WITH ORDINALITY AS t(test_varchar_unnest, row_number_unnest)", |
| 1440 | + ImmutableSet.of("mock.default.tests_table_unnest"), |
| 1441 | + new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "tests_table_unnest", "test_varchar_array"))), |
| 1442 | + new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of())); |
| 1443 | + // test unnest with two array column |
| 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 | + // test unnest with two array column and with ordinality |
| 1450 | + assertLineage( |
| 1451 | + "SELECT test_varchar_unnest AS test_varchar, row_number_unnest AS test_bigint FROM mock.default.tests_table_unnest CROSS JOIN UNNEST(test_varchar_array, test_bigint_array) WITH ORDINALITY AS t(test_varchar_unnest, test_bigint_unnest, row_number_unnest)", |
| 1452 | + ImmutableSet.of("mock.default.tests_table_unnest"), |
| 1453 | + new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "tests_table_unnest", "test_varchar_array"))), |
| 1454 | + new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of())); |
| 1455 | + assertLineage( |
| 1456 | + "SELECT CAST(test_bigint_unnest AS varchar(15)) AS test_varchar, row_number_unnest AS test_bigint FROM mock.default.tests_table_unnest CROSS JOIN UNNEST(test_varchar_array, test_bigint_array) WITH ORDINALITY AS t(test_varchar_unnest, test_bigint_unnest, row_number_unnest)", |
| 1457 | + ImmutableSet.of("mock.default.tests_table_unnest"), |
| 1458 | + new OutputColumnMetadata("test_varchar", VARCHAR_TYPE, ImmutableSet.of(new ColumnDetail("mock", "default", "tests_table_unnest", "test_bigint_array"))), |
| 1459 | + new OutputColumnMetadata("test_bigint", BIGINT_TYPE, ImmutableSet.of())); |
| 1460 | + } |
| 1461 | + |
1422 | 1462 | @Test |
1423 | 1463 | public void testTableStats() |
1424 | 1464 | throws Exception |
|
0 commit comments