Repository: drill
Updated Branches:
  refs/heads/master 27364122c -> 202a8e154


DRILL-3876: Avoid an extra copy of the original list when flattening

This only fixes a basic case, a more complete refactoring of the rewrite rule 
could avoid copies in cases with multiple flattens, this will be addressed in 
DRILL-3899.

close apache/drill#187


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

Branch: refs/heads/master
Commit: 6bc9111ac9ca1f87ee32a279e9c52ac06091b0a5
Parents: 2736412
Author: Jason Altekruse <[email protected]>
Authored: Tue Oct 6 09:23:18 2015 -0700
Committer: Jinfeng Ni <[email protected]>
Committed: Wed Oct 14 14:46:41 2015 -0700

----------------------------------------------------------------------
 .../visitor/SplitUpComplexExpressions.java      |  4 +++
 .../impl/flatten/TestFlattenPlanning.java       | 30 ++++++++++++++++++++
 2 files changed, 34 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/6bc9111a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/SplitUpComplexExpressions.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/SplitUpComplexExpressions.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/SplitUpComplexExpressions.java
index ebc825b..b79836d 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/SplitUpComplexExpressions.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/SplitUpComplexExpressions.java
@@ -94,6 +94,10 @@ public class SplitUpComplexExpressions extends 
BasePrelVisitor<Prel, Object, Rel
     }
     List<RexNode> complexExprs = exprSplitter.getComplexExprs();
 
+    if (complexExprs.size() == 1) {
+      return project;
+    }
+
     ProjectPrel childProject;
 
     List<RexNode> allExprs = new ArrayList();

http://git-wip-us.apache.org/repos/asf/drill/blob/6bc9111a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/flatten/TestFlattenPlanning.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/flatten/TestFlattenPlanning.java
 
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/flatten/TestFlattenPlanning.java
new file mode 100644
index 0000000..cbcf0fb
--- /dev/null
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/flatten/TestFlattenPlanning.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.physical.impl.flatten;
+
+import org.apache.drill.PlanTestBase;
+import org.junit.Test;
+
+public class TestFlattenPlanning extends PlanTestBase {
+
+  @Test
+  public void testFlattenPlanningAvoidUnnecessaryProject() throws Exception {
+    testPlanSubstrPatterns("select flatten(complex), rownum from 
cp.`/store/json/test_flatten_mappify2.json`",
+        new String[]{"Project(EXPR$0=[$1], rownum=[$0])"}, new 
String[]{"Project(EXPR$0=[$0], EXPR$1=[$1], EXPR$3=[$1])"});
+  }
+}

Reply via email to