hsyuan commented on a change in pull request #1160: [CALCITE-2712] Add rule to 
eliminate unnecessary outer join
URL: https://github.com/apache/calcite/pull/1160#discussion_r276744020
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
 ##########
 @@ -735,6 +737,95 @@ public static RelNode createCastRel(
     }
   }
 
+  /** Transforms the aggregate call according to the limit and offset. */
+  public static List<AggregateCall> transformAggregateCall(
+      List<AggregateCall> aggregateCalls, int limit, int offset) {
+    // Adjust arguments of the aggregate call.
+    final List<AggregateCall> newAggregateCall = new ArrayList<>();
+    for (AggregateCall aggregateCall : aggregateCalls) {
+      final List<Integer> args = new ArrayList<>();
+      aggregateCall.getArgList()
+          .forEach(i -> args.add(i >= limit ? i - offset : i));
+
+      newAggregateCall.add(AggregateCall
+          .create(aggregateCall.getAggregation(), aggregateCall.isDistinct(),
+              aggregateCall.isApproximate(), aggregateCall.ignoreNulls(), args,
+              aggregateCall.filterArg, aggregateCall.getCollation(),
+              aggregateCall.getType(), aggregateCall.getName()));
+    }
+    return newAggregateCall;
+  }
+
+  /** Transforms the condition according to the limit and offset. */
+  public static RexNode transformCondition(RexNode condition,
+      RexBuilder rexBuilder, int limit, int offset) {
+    RexShuttle shuttle = new RexShuttle() {
+      @Override public RexNode visitInputRef(RexInputRef inputRef) {
+        int index = inputRef.getIndex();
+        if (index >= limit) {
+          return rexBuilder.makeInputRef(inputRef.getType(), index - offset);
+        }
+        return inputRef;
+      }
+    };
+    return condition.accept(shuttle);
+  }
+
+  /**
+   * Whether it can remove join according to the aggregate.
+   *
+   * @param aggregate  Aggregate
+   * @param lowerLimit lower limit (included)
+   * @param upperLimit upper limit (excluded)
 
 Review comment:
   The explanation of lower/upper limit is unclear.

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

Reply via email to