yashmayya commented on code in PR #16966:
URL: https://github.com/apache/pinot/pull/16966#discussion_r2409290390
##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/NullHandlingIntegrationTest.java:
##########
@@ -459,4 +459,29 @@ public Object[][] nullLiteralQueries() {
{String.format("SELECT tan(null) FROM %s", getTableName()), "null"}
};
}
+
+ /// This test ensures IS_TRUE can be trimmed off on leaf stage
+ @Test(dataProvider = "useBothQueryEngines")
+ public void testFilteredAggregationNoScanInFilter(boolean
useMultiStageQueryEngine)
+ throws Exception {
+ setUseMultiStageQueryEngine(useMultiStageQueryEngine);
+
+ String query = "SELECT city, COUNT(*), COUNT(*) FILTER(WHERE description =
'unknown') FROM mytable GROUP BY city";
+
+ // MSE will insert IS_TRUE to the aggregate filter
+ if (useMultiStageQueryEngine) {
+ explainLogical(query,
+ "Execution Plan\n"
+ + "PinotLogicalAggregate(group=[{0}], agg#0=[COUNT($1)],
agg#1=[COUNT($2)], aggType=[FINAL])\n"
+ + " PinotLogicalExchange(distribution=[hash[0]])\n"
+ + " PinotLogicalAggregate(group=[{0}], agg#0=[COUNT()],
agg#1=[COUNT() FILTER $1], aggType=[LEAF])\n"
+ + " LogicalProject(city=[$5], $f1=[IS TRUE(=($7,
_UTF-8'unknown'))])\n"
Review Comment:
So this `IS_TRUE` is inserted in order to filter out null values because
`=(null, 'unknown')` is `null` and `IS_TRUE(null)` evaluates to `false`?
##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/RequestContextUtils.java:
##########
@@ -287,6 +287,16 @@ public static String getStringValue(Expression
thriftExpression) {
* missing an EQUALS filter operator.
*/
public static FilterContext getFilter(ExpressionContext filterExpression) {
+ FunctionContext function = filterExpression.getFunction();
+ // Trim off outer IS_TRUE function as it is redundant
+ if (function != null && function.getFunctionName().equals("istrue")) {
+ return getFilter(function.getArguments().get(0));
+ } else {
Review Comment:
Shouldn't we check if the argument is also a function? Do we want to apply
this optimization even if the argument is an identifier?
--
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]