xiedeyantu commented on code in PR #4897:
URL: https://github.com/apache/calcite/pull/4897#discussion_r3169130688


##########
core/src/main/java/org/apache/calcite/rel/rules/IntersectToDistinctRule.java:
##########
@@ -176,10 +178,32 @@ public void onMatchAggregatePushdown(RelOptRuleCall call) 
{
     final RelOptCluster cluster = intersect.getCluster();
     final RexBuilder rexBuilder = cluster.getRexBuilder();
     final RelBuilder relBuilder = call.builder();
+    List<RelDataTypeField> outputFields = 
intersect.getRowType().getFieldList();
 
     // 1st level aggregate: create an aggregate(col_0, ..., col_n, count(*)), 
for each branch
     for (RelNode input : intersect.getInputs()) {
       relBuilder.push(input);
+
+      // if any of the input fields is non-nullable, the corresponding output 
field
+      // is non-nullable this is captured in the type derivation in 
intersect.getRowType()
+      // if we know that nulls cannot be present in the output,
+      // then we can filter them from the inputs before aggregating
+      ArrayList<RexNode> nullFilters = new ArrayList<>();
+      List<RelDataTypeField> inputFields = input.getRowType().getFieldList();
+      for (int fieldIndex = 0; fieldIndex < outputFields.size(); fieldIndex++) 
{
+        RelDataTypeField inputField = inputFields.get(fieldIndex);
+        if (!outputFields.get(fieldIndex).getType().isNullable()
+            && inputField.getType().isNullable()) {
+          nullFilters.add(
+              rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL,
+              rexBuilder.makeInputRef(input, fieldIndex)));
+        }
+      }
+
+      if (!nullFilters.isEmpty()) {
+        relBuilder.filter(nullFilters);

Review Comment:
   Removed



-- 
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]

Reply via email to