somu-imply commented on code in PR #13892:
URL: https://github.com/apache/druid/pull/13892#discussion_r1129981804
##########
sql/src/test/java/org/apache/druid/sql/calcite/CalciteArraysQueryTest.java:
##########
@@ -2732,6 +2744,139 @@ public void testUnnest()
);
}
+ @Test
+ public void testUnnestTwice()
+ {
+ cannotVectorize();
+ testQuery(
+ "SELECT dim1, MV_TO_ARRAY(dim3), STRING_TO_ARRAY(dim1, U&'\\005C.') AS
dim1_split, dim1_split_unnest, dim3_unnest\n"
+ + "FROM\n"
+ + " druid.numfoo,\n"
+ + " UNNEST(STRING_TO_ARRAY(dim1, U&'\\005C.')) as t2
(dim1_split_unnest),\n"
+ + " UNNEST(MV_TO_ARRAY(dim3)) as t3 (dim3_unnest)",
+ QUERY_CONTEXT_UNNEST,
+ ImmutableList.of(
+ Druids.newScanQueryBuilder()
+ .dataSource(
+ UnnestDataSource.create(
+ UnnestDataSource.create(
+ new TableDataSource(CalciteTests.DATASOURCE3),
+ expressionVirtualColumn(
+ "j0.unnest",
+ "string_to_array(\"dim1\",'\\u005C.')",
+ ColumnType.STRING_ARRAY
+ ),
+ null
+ ),
+ expressionVirtualColumn(
+ "_j0.unnest",
+ "\"dim3\"",
+ ColumnType.STRING
+ ),
+ null
+ )
+ )
+ .intervals(querySegmentSpec(Filtration.eternity()))
+ .virtualColumns(
+ expressionVirtualColumn(
+ "v0",
+ "mv_to_array(\"dim3\")",
+ ColumnType.STRING_ARRAY
+ ),
+ expressionVirtualColumn(
+ "v1",
+ "string_to_array(\"dim1\",'\\u005C.')",
+ ColumnType.STRING_ARRAY
+ )
+ )
+
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
+ .legacy(false)
+ .context(QUERY_CONTEXT_UNNEST)
+ .columns(ImmutableList.of("_j0.unnest", "dim1", "j0.unnest",
"v0", "v1"))
+ .build()
+ ),
+ ImmutableList.of(
+ new Object[]{"", ImmutableList.of("a", "b"), useDefault ? null :
ImmutableList.of(""), "", "a"},
+ new Object[]{"", ImmutableList.of("a", "b"), useDefault ? null :
ImmutableList.of(""), "", "b"},
+ new Object[]{"10.1", ImmutableList.of("b", "c"),
ImmutableList.of("10", "1"), "10", "b"},
+ new Object[]{"10.1", ImmutableList.of("b", "c"),
ImmutableList.of("10", "1"), "10", "c"},
+ new Object[]{"10.1", ImmutableList.of("b", "c"),
ImmutableList.of("10", "1"), "1", "b"},
+ new Object[]{"10.1", ImmutableList.of("b", "c"),
ImmutableList.of("10", "1"), "1", "c"},
+ new Object[]{"2", ImmutableList.of("d"), ImmutableList.of("2"),
"2", "d"},
+ new Object[]{"1", useDefault ? null : ImmutableList.of(""),
ImmutableList.of("1"), "1", ""},
+ new Object[]{"def", null, ImmutableList.of("def"), "def",
NullHandling.defaultStringValue()},
+ new Object[]{"abc", null, ImmutableList.of("abc"), "abc",
NullHandling.defaultStringValue()}
+ )
+ );
+ }
+
+ @Test
+ public void testUnnestTwiceWithFiltersAndExpressions()
+ {
+ cannotVectorize();
+ testQuery(
+ "SELECT dim1, MV_TO_ARRAY(dim3), STRING_TO_ARRAY(dim1, U&'\\005C.') AS
dim1_split, dim1_split_unnest, dim3_unnest || 'xx' AS dim3_unnest\n"
+ + "FROM\n"
+ + " druid.numfoo,\n"
+ + " UNNEST(STRING_TO_ARRAY(dim1, U&'\\005C.')) as t2
(dim1_split_unnest),\n"
+ + " UNNEST(MV_TO_ARRAY(dim3)) as t3 (dim3_unnest)"
+ + "WHERE t2.dim1_split_unnest IN ('1', '2')",
+ QUERY_CONTEXT_UNNEST,
+ ImmutableList.of(
+ Druids.newScanQueryBuilder()
+ .dataSource(
+ UnnestDataSource.create(
+ UnnestDataSource.create(
+ new TableDataSource(CalciteTests.DATASOURCE3),
+ expressionVirtualColumn(
+ "j0.unnest",
+ "string_to_array(\"dim1\",'\\u005C.')",
+ ColumnType.STRING_ARRAY
+ ),
+ null
+ ),
+ expressionVirtualColumn(
+ "_j0.unnest",
+ "\"dim3\"",
+ ColumnType.STRING
+ ),
+ null
+ )
+ )
+ .intervals(querySegmentSpec(Filtration.eternity()))
+ .virtualColumns(
+ expressionVirtualColumn(
+ "v0",
+ "mv_to_array(\"dim3\")",
+ ColumnType.STRING_ARRAY
+ ),
+ expressionVirtualColumn(
+ "v1",
+ "string_to_array(\"dim1\",'\\u005C.')",
+ ColumnType.STRING_ARRAY
+ ),
+ expressionVirtualColumn(
+ "v2",
+ "concat(\"_j0.unnest\",'xx')",
+ ColumnType.STRING
+ )
+ )
+ .filters(in("j0.unnest", ImmutableList.of("1", "2"), null))
+
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
+ .legacy(false)
+ .context(QUERY_CONTEXT_UNNEST)
+ .columns(ImmutableList.of("dim1", "j0.unnest", "v0", "v1",
"v2"))
+ .build()
+ ),
+ ImmutableList.of(
+ new Object[]{"10.1", ImmutableList.of("b", "c"),
ImmutableList.of("10", "1"), "1", "bxx"},
+ new Object[]{"10.1", ImmutableList.of("b", "c"),
ImmutableList.of("10", "1"), "1", "cxx"},
+ new Object[]{"2", ImmutableList.of("d"), ImmutableList.of("2"),
"2", "dxx"},
+ new Object[]{"1", null, ImmutableList.of("1"), "1", "xx"}
Review Comment:
Replace with `new Object[]{"1", useDefault ? null: ImmutableList.of(""),
ImmutableList.of("1"), "1", "xx"}`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]