clintropolis commented on code in PR #14587:
URL: https://github.com/apache/druid/pull/14587#discussion_r1281034506
##########
processing/src/main/java/org/apache/druid/segment/UnnestStorageAdapter.java:
##########
@@ -408,7 +356,142 @@ void addPreFilter(@Nullable final Filter filter)
);
}
+ class FilterSplitter
+ {
+ private String inputColumn;
+ private ColumnCapabilities inputColumnCapabilites;
+ private VirtualColumns queryVirtualColumns;
+
+ public FilterSplitter(
+ String inputColumn,
+ ColumnCapabilities inputColumnCapabilites, VirtualColumns
queryVirtualColumns
Review Comment:
nit formatting, `VirtualColumns` should be on a separate line (the style
checker has trouble enforcing this sometimes)
##########
processing/src/test/java/org/apache/druid/segment/filter/FilterTestUtils.java:
##########
@@ -44,4 +47,19 @@ public static SelectorFilter selector(final String
fieldName, final String value
{
return new SelectorFilter(fieldName, value, null);
}
+
+ public static Filter sdf(String dimension, String value)
Review Comment:
why does this need to exist instead of just using `selector`? I don't see
any callers using the version that takes extractionFn, and only one caller
using `sdfd` which seems overkill..
##########
sql/src/test/java/org/apache/druid/sql/calcite/CalciteArraysQueryTest.java:
##########
@@ -2888,6 +2888,234 @@ public void testUnnestTwiceWithFiltersAndExpressions()
);
}
+ @Test
+ public void testUnnestThriceWithFiltersOnDimAndUnnestCol()
+ {
+ cannotVectorize();
+ String sql = " SELECT dimZipf, dim3_unnest1, dim3_unnest2, dim3_unnest3
FROM \n"
+ + " ( SELECT * FROM \n"
+ + " ( SELECT * FROM lotsocolumns,
UNNEST(MV_TO_ARRAY(dimMultivalEnumerated)) as ut(dim3_unnest1) )"
+ + " ,UNNEST(MV_TO_ARRAY(dimMultivalEnumerated)) as
ut(dim3_unnest2) \n"
+ + " ), UNNEST(MV_TO_ARRAY(dimMultivalEnumerated)) as
ut(dim3_unnest3) "
+ + " WHERE dimZipf=27 AND dim3_unnest1='Baz'";
+ testQuery(
+ sql,
+ QUERY_CONTEXT_UNNEST,
+ ImmutableList.of(
+ Druids.newScanQueryBuilder()
+ .dataSource(
+ UnnestDataSource.create(
+ UnnestDataSource.create(
+ UnnestDataSource.create(
+ new
TableDataSource(CalciteTests.DATASOURCE5),
+ expressionVirtualColumn(
+ "j0.unnest",
+ "\"dimMultivalEnumerated\"",
+ ColumnType.STRING
+ ),
+ null
+ ),
+ expressionVirtualColumn(
+ "_j0.unnest",
+ "\"dimMultivalEnumerated\"",
+ ColumnType.STRING
+ ), null
+ ),
+ expressionVirtualColumn(
+ "__j0.unnest",
+ "\"dimMultivalEnumerated\"",
+ ColumnType.STRING
+ ),
+ null
+ )
+ )
+ .intervals(querySegmentSpec(Filtration.eternity()))
+
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
+ .filters(and(
+ NullHandling.sqlCompatible()
+ ? equality("dimZipf", "27", ColumnType.LONG)
+ : bound("dimZipf", "27", "27", false, false, null,
StringComparators.NUMERIC),
+ equality("j0.unnest", "Baz", ColumnType.STRING)
+ ))
+ .legacy(false)
+ .context(QUERY_CONTEXT_UNNEST)
+ .columns(ImmutableList.of("__j0.unnest", "_j0.unnest",
"dimZipf", "j0.unnest"))
+ .build()
+ ),
+ ImmutableList.of(
+ new Object[]{"27", "Baz", "Baz", "Baz"},
+ new Object[]{"27", "Baz", "Baz", "Baz"},
+ new Object[]{"27", "Baz", "Baz", "Hello"},
+ new Object[]{"27", "Baz", "Baz", "World"},
+ new Object[]{"27", "Baz", "Baz", "Baz"},
+ new Object[]{"27", "Baz", "Baz", "Baz"},
+ new Object[]{"27", "Baz", "Baz", "Hello"},
+ new Object[]{"27", "Baz", "Baz", "World"},
+ new Object[]{"27", "Baz", "Hello", "Baz"},
+ new Object[]{"27", "Baz", "Hello", "Baz"},
+ new Object[]{"27", "Baz", "Hello", "Hello"},
+ new Object[]{"27", "Baz", "Hello", "World"},
+ new Object[]{"27", "Baz", "World", "Baz"},
+ new Object[]{"27", "Baz", "World", "Baz"},
+ new Object[]{"27", "Baz", "World", "Hello"},
+ new Object[]{"27", "Baz", "World", "World"},
+ new Object[]{"27", "Baz", "Baz", "Baz"},
+ new Object[]{"27", "Baz", "Baz", "Baz"},
+ new Object[]{"27", "Baz", "Baz", "Hello"},
+ new Object[]{"27", "Baz", "Baz", "World"},
+ new Object[]{"27", "Baz", "Baz", "Baz"},
+ new Object[]{"27", "Baz", "Baz", "Baz"},
+ new Object[]{"27", "Baz", "Baz", "Hello"},
+ new Object[]{"27", "Baz", "Baz", "World"},
+ new Object[]{"27", "Baz", "Hello", "Baz"},
+ new Object[]{"27", "Baz", "Hello", "Baz"},
+ new Object[]{"27", "Baz", "Hello", "Hello"},
+ new Object[]{"27", "Baz", "Hello", "World"},
+ new Object[]{"27", "Baz", "World", "Baz"},
+ new Object[]{"27", "Baz", "World", "Baz"},
+ new Object[]{"27", "Baz", "World", "Hello"},
+ new Object[]{"27", "Baz", "World", "World"}
+ )
+ );
+ }
+ @Test
+ public void testUnnestThriceWithFiltersOnDimAndAllUnnestColumns()
+ {
+ cannotVectorize();
+ String sql = " SELECT dimZipf, dim3_unnest1, dim3_unnest2, dim3_unnest3
FROM \n"
+ + " ( SELECT * FROM \n"
+ + " ( SELECT * FROM lotsocolumns,
UNNEST(MV_TO_ARRAY(dimMultivalEnumerated)) as ut(dim3_unnest1) )"
+ + " ,UNNEST(MV_TO_ARRAY(dimMultivalEnumerated)) as
ut(dim3_unnest2) \n"
+ + " ), UNNEST(MV_TO_ARRAY(dimMultivalEnumerated)) as
ut(dim3_unnest3) "
+ + " WHERE dimZipf=27 AND dim3_unnest1='Baz' AND
dim3_unnest2='Hello' AND dim3_unnest3='World'";
+ testQuery(
+ sql,
+ QUERY_CONTEXT_UNNEST,
+ ImmutableList.of(
+ Druids.newScanQueryBuilder()
+ .dataSource(
+ UnnestDataSource.create(
+ UnnestDataSource.create(
+ UnnestDataSource.create(
+ new
TableDataSource(CalciteTests.DATASOURCE5),
+ expressionVirtualColumn(
+ "j0.unnest",
+ "\"dimMultivalEnumerated\"",
+ ColumnType.STRING
+ ),
+ null
+ ),
+ expressionVirtualColumn(
+ "_j0.unnest",
+ "\"dimMultivalEnumerated\"",
+ ColumnType.STRING
+ ), equality("_j0.unnest", "Hello",
ColumnType.STRING)
+ ),
+ expressionVirtualColumn(
+ "__j0.unnest",
+ "\"dimMultivalEnumerated\"",
+ ColumnType.STRING
+ ),
+ equality("__j0.unnest", "World", ColumnType.STRING)
+ )
+ )
+ .intervals(querySegmentSpec(Filtration.eternity()))
+
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
+ .filters(and(
+ NullHandling.sqlCompatible()
+ ? equality("dimZipf", "27", ColumnType.LONG)
+ : bound("dimZipf", "27", "27", false, false, null,
StringComparators.NUMERIC),
Review Comment:
you can use `numericEquality` instead of this
--
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]