vvysotskyi commented on a change in pull request #1386: DRILL-6574: Add option
to push LIMIT(0) on top of SCAN (late limit 0 optimization)
URL: https://github.com/apache/drill/pull/1386#discussion_r203399743
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/FindLimit0Visitor.java
##########
@@ -126,9 +161,84 @@ public static boolean containsLimit0(final RelNode rel) {
return visitor.isContains();
}
- private boolean contains = false;
+ /**
+ * TODO(DRILL-3993): Use RelBuilder to create a limit node to allow for
applying this optimization in potentially
+ * any of the transformations, but currently this can be applied after Drill
logical transformation, and before
+ * Drill physical transformation.
+ */
+ public static DrillRel addLimitOnTopOfLeafNodes(final DrillRel rel) {
+ final Pointer<Boolean> isUnsupported = new Pointer<>(false);
+
+ // to visit unsupported functions
+ final RexShuttle unsupportedFunctionsVisitor = new RexShuttle() {
+ @Override
+ public RexNode visitCall(RexCall call) {
+ final SqlOperator operator = call.getOperator();
+ if (isUnsupportedScalarFunction(operator)) {
+ isUnsupported.value = true;
+ return call;
+ }
+ return super.visitCall(call);
+ }
+ };
+
+ // to visit unsupported operators
+ final RelShuttle unsupportedOperationsVisitor = new RelShuttleImpl() {
+ @Override
+ public RelNode visit(RelNode other) {
+ if (other instanceof DrillUnionRelBase) {
+ isUnsupported.value = true;
+ return other;
+ } else if (other instanceof DrillProjectRelBase) {
+ other.accept(unsupportedFunctionsVisitor);
Review comment:
Should we also add a check for `isUnsupported` value before calling
`other.accept()` to consider a case when rel node has several inputs and one of
the previous inputs already changed `isUnsupported` value?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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