[
https://issues.apache.org/jira/browse/DRILL-6212?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16511865#comment-16511865
]
ASF GitHub Bot commented on DRILL-6212:
---------------------------------------
vrozov commented on a change in pull request #1319: DRILL-6212: Prevent
recursive cast expressions
URL: https://github.com/apache/drill/pull/1319#discussion_r195277468
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillMergeProjectRule.java
##########
@@ -77,4 +85,100 @@ private boolean checkComplexOutput(Project project) {
}
return false;
}
+
+ @Override
+ public void onMatch(RelOptRuleCall call) {
+ final Project topProject = call.rel(0);
+ final Project bottomProject = call.rel(1);
+ final RelBuilder relBuilder = call.builder();
+
+ // If one or both projects are permutations, short-circuit the complex
logic
+ // of building a RexProgram.
+ final Permutation topPermutation = topProject.getPermutation();
+ if (topPermutation != null) {
+ if (topPermutation.isIdentity()) {
+ // Let ProjectRemoveRule handle this.
+ return;
+ }
+ final Permutation bottomPermutation = bottomProject.getPermutation();
+ if (bottomPermutation != null) {
+ if (bottomPermutation.isIdentity()) {
+ // Let ProjectRemoveRule handle this.
+ return;
+ }
+ final Permutation product = topPermutation.product(bottomPermutation);
+ relBuilder.push(bottomProject.getInput());
+ relBuilder.project(relBuilder.fields(product),
+ topProject.getRowType().getFieldNames());
+ call.transformTo(relBuilder.build());
+ return;
+ }
+ }
+
+ // If we're not in force mode and the two projects reference identical
+ // inputs, then return and let ProjectRemoveRule replace the projects.
+ if (!force) {
+ if (RexUtil.isIdentity(topProject.getProjects(),
+ topProject.getInput().getRowType())) {
+ return;
+ }
+ }
+
+ final List<RexNode> pushedProjects =
+ RelOptUtil.pushPastProject(topProject.getProjects(), bottomProject);
+ final List<RexNode> newProjects = simplifyCast(pushedProjects);
+ final RelNode input = bottomProject.getInput();
+ if (RexUtil.isIdentity(newProjects, input.getRowType())) {
+ if (force
+ || input.getRowType().getFieldNames()
+ .equals(topProject.getRowType().getFieldNames())) {
+ call.transformTo(input);
+ return;
+ }
+ }
+
+ // replace the two projects with a combined projection
+ relBuilder.push(bottomProject.getInput());
+ relBuilder.project(newProjects, topProject.getRowType().getFieldNames());
+ call.transformTo(relBuilder.build());
+ }
+
+ public static List<RexNode> simplifyCast(List<RexNode> projectExprs) {
+ final List<RexNode> list = new ArrayList<>();
+ for (RexNode rex: projectExprs) {
+ if (rex.getKind() == SqlKind.CAST) {
+ RexNode operand = ((RexCall) rex).getOperands().get(0);
+ while (operand.getKind() == SqlKind.CAST
+ && operand.getType().equals(rex.getType())) {
+ rex = operand;
+ operand = ((RexCall) rex).getOperands().get(0);
+ }
+
+ }
+ list.add(rex);
+ }
+ return list;
+ }
+
+ public static Project replace(Project topProject, Project bottomProject) {
Review comment:
Where is this method used?
----------------------------------------------------------------
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]
> A simple join is recursing too deep in planning and eventually throwing stack
> overflow.
> ---------------------------------------------------------------------------------------
>
> Key: DRILL-6212
> URL: https://issues.apache.org/jira/browse/DRILL-6212
> Project: Apache Drill
> Issue Type: Bug
> Components: Query Planning & Optimization
> Affects Versions: 1.12.0
> Reporter: Hanumath Rao Maduri
> Assignee: Gautam Kumar Parai
> Priority: Critical
> Fix For: 1.14.0
>
>
> Create two views using following statements.
> {code}
> create view v1 as select cast(greeting as int) f from
> dfs.`/home/mapr/data/json/temp.json`;
> create view v2 as select cast(greeting as int) f from
> dfs.`/home/mapr/data/json/temp.json`;
> {code}
> Executing the following join query produces a stack overflow during the
> planning phase.
> {code}
> select t1.f from dfs.tmp.v1 as t inner join dfs.tmp.v2 as t1 on cast(t.f as
> int) = cast(t1.f as int) and cast(t.f as int) = 10 and cast(t1.f as int) = 10;
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)