You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by am...@apache.org on 2016/05/26 01:17:45 UTC
drill git commit: DRILL-4693: Ensure final column re-ordering is done
if any select list expression is convert_fromjson.
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 <as...@maprtech.com>
Authored: Wed May 25 15:33:56 2016 -0700
Committer: Aman Sinha <as...@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 {