drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amansi...@apache.org
Subject drill git commit: DRILL-4693: Ensure final column re-ordering is done if any select list expression is convert_fromjson.
Date Thu, 26 May 2016 01:17:45 GMT
Repository: drill
Updated Branches:
  refs/heads/master 3d92d2829 -> 6ddd5fa73


DRILL-4693:  Ensure final column re-ordering is done if any select list expression is convert_fromjson.

close apache/drill#508


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

Branch: refs/heads/master
Commit: 6ddd5fa730934946165a27f91faece7e60e3c98c
Parents: 3d92d28
Author: Aman Sinha <asinha@maprtech.com>
Authored: Wed May 25 15:33:56 2016 -0700
Committer: Aman Sinha <asinha@maprtech.com>
Committed: Wed May 25 18:14:09 2016 -0700

----------------------------------------------------------------------
 .../drill/exec/planner/physical/ProjectPrel.java   | 17 +++++++++++++++++
 .../exec/physical/impl/TestConvertFunctions.java   | 17 +++++++++++++++++
 2 files changed, 34 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/6ddd5fa7/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrel.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrel.java
index e109dc4..25cd717 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrel.java
@@ -31,7 +31,9 @@ import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelTraitSet;
 import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
 import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlKind;
 
 public class ProjectPrel extends DrillProjectRelBase implements Prel{
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ProjectPrel.class);
@@ -79,8 +81,23 @@ public class ProjectPrel extends DrillProjectRelBase implements Prel{
     return SelectionVectorMode.NONE;
   }
 
+  /**
+   * Whether this Project requires a final column re-ordering. Returns False for all cases
except when
+   * convert_fromjson function is present.  For convert_fromjson function, the Project operator
at
+   * run-time produces an output schema with convert_fromjson expr appended to the end of
the schema.
+   * We need a final column re-ordering to ensure the correct column order.
+  */
   @Override
   public boolean needsFinalColumnReordering() {
+    for (RexNode expr : this.exps) {
+      // TODO: a convert_fromjson nested within other convert functions currently does not
work.
+      // When it is supported, we should enhance this check by using a visitor to find the
nested function.
+      if (expr.getKind() == SqlKind.OTHER_FUNCTION &&
+          expr instanceof RexCall &&
+          ((RexCall) expr).getOperator().getName().equalsIgnoreCase("CONVERT_FROMJSON"))
{
+        return true;
+      }
+    }
     return false;
   }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/6ddd5fa7/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
index 8bf65d7..80189d5 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
@@ -217,6 +217,23 @@ public class TestConvertFunctions extends BaseTestQuery {
 
   }
 
+  @Test // DRILL-4693
+  public void testConvertFromJson_drill4693() throws Exception {
+    Object mapVal1 = mapOf("x", "y");
+
+    String query = String.format("select 'abc' as col1, convert_from('{\"x\" : \"y\"}', 'json')
as col2, 'xyz' as col3 "
+        + " from cp.`/store/json/input2.json` t"
+        + " where t.`integer` = 2001");
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col1", "col2", "col3")
+        .baselineValues("abc", mapVal1, "xyz")
+        .go();
+
+  }
+
   @Test
   public void testConvertToComplexJSON() throws Exception {
 


Mime
View raw message