julianhyde commented on a change in pull request #1417: [CALCITE-3244]
RelDecorrelator unable to decorrelate expression with …
URL: https://github.com/apache/calcite/pull/1417#discussion_r323465905
##########
File path:
core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java
##########
@@ -309,8 +311,22 @@ private RexNode rewriteExists(RexSubQuery e,
Set<CorrelationId> variablesSet,
}
builder.as("dt");
+ boolean generateNullsOnRight = true;
+ if (e.rel instanceof LogicalAggregate) {
+ // SELECT f0, count(*) FROM t GROUP BY () will always return 1 row.
+ // That means, the RHS never generates null.
+ final LogicalAggregate aggregate = (LogicalAggregate) e.rel;
+ if (aggregate.getGroupSet().isEmpty()
+ && aggregate.getAggCallList().stream()
+ .anyMatch(c -> c.getAggregation() instanceof
SqlCountAggFunction)) {
Review comment:
You should be able to trust the aggregate function to derive its own
nullability.
For example, SUM knows that even when applied to a not-null column x, if the
groupSet is empty it may return null. COUNT knows that it never returns null.
So maybe just look at the rowType of Aggregate, and look at whether the
columns are NOT NULL.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services