Repository: drill
Updated Branches:
  refs/heads/master 406dd2a58 -> 789b83d77


DRILL-5757: CONVERT_TO_JSON function is failed while using non-existence field 
as a parameter.

close apache/drill#929


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

Branch: refs/heads/master
Commit: 2c470de30a9ae70709b392f8cb36094a450e52d8
Parents: 406dd2a
Author: Vitalii Diravka <vitalii.dira...@gmail.com>
Authored: Thu Aug 31 13:24:37 2017 +0000
Committer: Aman Sinha <asi...@maprtech.com>
Committed: Sat Sep 2 22:59:44 2017 -0700

----------------------------------------------------------------------
 .../drill/exec/expr/ExpressionTreeMaterializer.java |  7 ++++---
 .../complex/writer/TestComplexTypeReader.java       | 16 +++++++++++++++-
 2 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/2c470de3/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 f14d816..23df262 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
@@ -423,10 +423,11 @@ public class ExpressionTreeMaterializer {
           TypeProtos.MajorType parmType = 
matchedFuncHolder.getParmMajorType(i);
 
           //Case 1: If  1) the argument is NullExpression
-          //            2) the parameter of matchedFuncHolder allows null 
input, or func's null_handling is NULL_IF_NULL (means null and non-null are 
exchangable).
+          //            2) the minor type of parameter of matchedFuncHolder is 
not LATE (the type of null expression is still unknown)
+          //            3) the parameter of matchedFuncHolder allows null 
input, or func's null_handling is NULL_IF_NULL (means null and non-null are 
exchangeable).
           //        then replace NullExpression with a TypedNullConstant
-          if (currentArg.equals(NullExpression.INSTANCE) &&
-            ( parmType.getMode().equals(TypeProtos.DataMode.OPTIONAL) ||
+          if (currentArg.equals(NullExpression.INSTANCE) && 
!MinorType.LATE.equals(parmType.getMinorType()) &&
+              (TypeProtos.DataMode.OPTIONAL.equals(parmType.getMode()) ||
               matchedFuncHolder.getNullHandling() == 
FunctionTemplate.NullHandling.NULL_IF_NULL)) {
             argsWithCast.add(new TypedNullConstant(parmType));
           } else if (Types.softEquals(parmType, currentArg.getMajorType(), 
matchedFuncHolder.getNullHandling() == 
FunctionTemplate.NullHandling.NULL_IF_NULL) ||

http://git-wip-us.apache.org/repos/asf/drill/blob/2c470de3/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestComplexTypeReader.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestComplexTypeReader.java
 
b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestComplexTypeReader.java
index c3cfb68..67b2e5a 100644
--- 
a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestComplexTypeReader.java
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestComplexTypeReader.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -299,4 +299,18 @@ public class TestComplexTypeReader extends BaseTestQuery{
     Files.deleteIfExists(path1);
     Files.deleteIfExists(path2);
   }
+
+  @Test
+  public void testNonExistentFieldConverting() throws Exception {
+    String query = "select employee_id, convert_to(`complex_field`, 'JSON') as 
complex_field from cp.`employee.json` " +
+        "where employee_id = 1";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("employee_id", "complex_field")
+        .baselineValues(1L, null)
+        .build()
+        .run();
+  }
 }

Reply via email to