You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ja...@apache.org on 2014/06/16 23:31:20 UTC
[11/32] git commit: DRILL-482 : Return null value if cast function
input is a null expression.
DRILL-482 : Return null value if cast function input is a null expression.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/817bea53
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/817bea53
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/817bea53
Branch: refs/heads/master
Commit: 817bea53995f7d003ffa30d67d2dbf237d430a3c
Parents: bc0bb4d
Author: Jinfeng Ni <jn...@maprtech.com>
Authored: Fri Jun 13 13:27:31 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Mon Jun 16 07:58:26 2014 -0700
----------------------------------------------------------------------
.../apache/drill/exec/expr/ExpressionTreeMaterializer.java | 7 +++++--
.../src/test/java/org/apache/drill/TestExampleQueries.java | 8 +++++++-
2 files changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/817bea53/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
index 9b80dc0..ef6e6dc 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
@@ -459,10 +459,13 @@ public class ExpressionTreeMaterializer {
if(castEqual(e.getPosition(), newMajor, input.getMajorType())) return input; // don't do pointless cast.
- if(newMinor == MinorType.LATE || newMinor == MinorType.NULL){
+ if(newMinor == MinorType.LATE){
// if the type still isn't fully bound, leave as cast expression.
return new CastExpression(input, e.getMajorType(), e.getPosition());
- }else{
+ } else if (newMinor == MinorType.NULL) {
+ // if input is a NULL expression, remove cast expression and return a TypedNullConstant directly.
+ return new TypedNullConstant(Types.optional(e.getMajorType().getMinorType()));
+ } else {
// if the type is fully bound, convert to functioncall and materialze the function.
MajorType type = e.getMajorType();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/817bea53/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
index 2fcc4fb..783c562 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
@@ -23,7 +23,7 @@ import org.junit.Test;
public class TestExampleQueries extends BaseTestQuery{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestExampleQueries.class);
-
+
@Test // see DRILL-553
public void testQueryWithNullValues() throws Exception {
test("select count(*) from cp.`customer.json` limit 1");
@@ -188,5 +188,11 @@ public class TestExampleQueries extends BaseTestQuery{
public void testUnionAll6() throws Exception {
test("select n_nationkey, n_regionkey from cp.`tpch/nation.parquet` where n_regionkey = 1 union all select r_regionkey, r_regionkey from cp.`tpch/region.parquet` where r_regionkey = 2");
}
+
+ @Test
+ // cast non-exist column from json file. Should return null value.
+ public void testDrill428() throws Exception {
+ test("select cast(NON_EXIST_COL as varchar(10)) from cp.`employee.json` limit 2; ");
+ }
}