drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [3/5] drill git commit: DRILL-3542: Add method to use both field names and types to determine project operator's triviality.
Date Wed, 26 Aug 2015 22:08:19 GMT
DRILL-3542: Add method to use both field names and types to determine project operator's triviality.

[CALCITE-577] removes a deprecated code where project operator's triviality depends both names
and types. Drill has to add it back, since field name matters in Drill's execution engine.


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/b8527594
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/b8527594
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/b8527594

Branch: refs/heads/master
Commit: b8527594dd741bd518467170c52c977d6e37099e
Parents: 793884d
Author: Jinfeng Ni <jni@apache.org>
Authored: Tue Aug 4 01:54:40 2015 -0700
Committer: Jinfeng Ni <jni@apache.org>
Committed: Wed Aug 26 12:08:11 2015 -0700

----------------------------------------------------------------------
 .../exec/planner/common/DrillRelOptUtil.java    | 41 ++++++++++++++++++++
 .../planner/sql/handlers/DefaultSqlHandler.java |  3 +-
 2 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/b8527594/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
index 1dc9349..0a13b5b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
@@ -23,7 +23,9 @@ import java.util.List;
 import com.google.common.collect.Lists;
 import org.apache.calcite.plan.RelOptUtil;
 import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Project;
 import org.apache.calcite.rel.logical.LogicalCalc;
+import org.apache.calcite.rel.rules.ProjectRemoveRule;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rel.type.RelDataTypeField;
 import org.apache.calcite.rex.RexInputRef;
@@ -115,4 +117,43 @@ public abstract class DrillRelOptUtil {
 
     return RelOptUtil.createProject(rel, refs, fieldNames, false);
   }
+
+  public static boolean isTrivialProject(Project project, boolean useNamesInIdentityProjCalc)
{
+    if (!useNamesInIdentityProjCalc) {
+      return ProjectRemoveRule.isTrivial(project);
+    }  else {
+      return containIdentity(project.getProjects(), project.getRowType(), project.getInput().getRowType());
+    }
+  }
+
+  /**
+   * Returns whether the leading edge of a given array of expressions is
+   * wholly {@link RexInputRef} objects with types and names corresponding
+   * to the underlying row type. */
+  private static boolean containIdentity(List<? extends RexNode> exps,
+                                        RelDataType rowType, RelDataType childRowType) {
+    List<RelDataTypeField> fields = rowType.getFieldList();
+    List<RelDataTypeField> childFields = childRowType.getFieldList();
+    int fieldCount = childFields.size();
+    if (exps.size() != fieldCount) {
+      return false;
+    }
+    for (int i = 0; i < exps.size(); i++) {
+      RexNode exp = exps.get(i);
+      if (!(exp instanceof RexInputRef)) {
+        return false;
+      }
+      RexInputRef var = (RexInputRef) exp;
+      if (var.getIndex() != i) {
+        return false;
+      }
+      if (!fields.get(i).getName().equals(childFields.get(i).getName())) {
+        return false;
+      }
+      if (!fields.get(i).getType().equals(childFields.get(i).getType())) {
+        return false;
+      }
+    }
+    return true;
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/b8527594/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
index 4c986aa..5f90bd6 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
@@ -66,6 +66,7 @@ import org.apache.drill.exec.physical.PhysicalPlan;
 import org.apache.drill.exec.physical.base.AbstractPhysicalVisitor;
 import org.apache.drill.exec.physical.base.PhysicalOperator;
 import org.apache.drill.exec.physical.impl.join.JoinUtils;
+import org.apache.drill.exec.planner.common.DrillRelOptUtil;
 import org.apache.drill.exec.planner.cost.DrillDefaultRelMetadataProvider;
 import org.apache.drill.exec.planner.logical.DrillJoinRel;
 import org.apache.drill.exec.planner.logical.DrillProjectRel;
@@ -504,7 +505,7 @@ public class DefaultSqlHandler extends AbstractSqlHandler {
     DrillProjectRel topProj = DrillProjectRel.create(rel.getCluster(), rel.getTraitSet(),
rel, projections, newRowType);
 
     // Add a final non-trivial Project to get the validatedRowType, if child is not project.
-    if (rel instanceof Project && ProjectRemoveRule.isTrivial(topProj)) {
+    if (rel instanceof Project && DrillRelOptUtil.isTrivialProject(topProj, true))
{
       return rel;
     } else{
       return topProj;


Mime
View raw message