Skip to content

Commit 46dabbd

Browse files
committed
DRILL-7759: Code compilation exception for queries containing (untyped) NULL
1 parent d8d31e5 commit 46dabbd

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,12 @@ private HoldingContainer visitBooleanAnd(BooleanOperator op,
10391039

10401040
JBlock earlyExit = null;
10411041
if (arg.isOptional()) {
1042-
earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().ne(JExpr.lit(1))))._then();
1042+
JExpression expr1 = arg.getIsSet().eq(JExpr.lit(1));
1043+
// UntypedNullHolder does not have `value` field
1044+
if (arg.getMinorType() != TypeProtos.MinorType.NULL) {
1045+
expr1 = expr1.cand(arg.getValue().ne(JExpr.lit(1)));
1046+
}
1047+
earlyExit = eval._if(expr1)._then();
10431048
if (e == null) {
10441049
e = arg.getIsSet();
10451050
} else {

exec/java-exec/src/test/java/org/apache/drill/TestUntypedNull.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,14 @@ public void testCoalesceOnNotExistentColumnsInUDF2() throws Exception {
240240
.baselineValuesForSingleColumn(null, null, null, null, null)
241241
.go();
242242
}
243+
244+
@Test
245+
public void testValueIsNotReferencedOnUntypedNullHolderInstance() throws Exception {
246+
testBuilder()
247+
.physicalPlanFromFile("physical_untyped_null.json")
248+
.unOrdered()
249+
.expectsEmptyResultSet()
250+
.go();
251+
}
243252
}
244253

exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetComplex.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public void notxistsField() throws Exception {
197197
.run();
198198
}
199199

200+
@Test
200201
public void testReadRepeatedDecimals() throws Exception {
201202

202203
JsonStringArrayList<BigDecimal> ints = new JsonStringArrayList<>();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"head" : {
3+
"version" : 1,
4+
"generator" : {
5+
"type" : "ExplainHandler",
6+
"info" : ""
7+
},
8+
"type" : "APACHE_DRILL_PHYSICAL",
9+
"options" : [ ],
10+
"queue" : 0,
11+
"hasResourcePlan" : false,
12+
"resultMode" : "EXEC"
13+
},
14+
"graph" : [ {
15+
"pop" : "mock-scan",
16+
"@id" : 5,
17+
"url": "http://apache.org",
18+
"entries":[
19+
{"records": 100, "types": [
20+
{"name": "order_date", "type": "DATE", "mode": "OPTIONAL"},
21+
{"name": "order_type", "type": "VARCHAR", "mode": "REQUIRED"}
22+
]}
23+
]
24+
}, {
25+
"pop" : "filter",
26+
"@id" : 4,
27+
"child" : 5,
28+
"expr" : "booleanAnd(booleanOr(booleanAnd(istrue(less_than_or_equal_to(`order_date`, cast( 1517443200000 as DATE)) ) , NULL) , isnottrue(less_than_or_equal_to(`order_date`, cast( 1517443200000 as DATE)) ) ) , booleanOr(istrue(booleanOr(equal(`order_date`, cast( 1588291200000 as DATE)) , equal(`order_date`, cast( 1575158400000 as DATE)) ) ) , booleanAnd(NULL, isnottrue(booleanOr(equal(`order_date`, cast( 1588291200000 as DATE)) , equal(`order_date`, cast( 1575158400000 as DATE)) ) ) ) ) ) "
29+
}, {
30+
"pop" : "selection-vector-remover",
31+
"@id" : 3,
32+
"child" : 4
33+
}, {
34+
"pop" : "project",
35+
"@id" : 2,
36+
"exprs" : [ {
37+
"ref" : "`type`",
38+
"expr" : "`order_type`"
39+
} ],
40+
"child" : 3,
41+
"outputProj" : false
42+
}, {
43+
"pop" : "project",
44+
"@id" : 1,
45+
"exprs" : [ {
46+
"ref" : "`type`",
47+
"expr" : "`type`"
48+
} ],
49+
"child" : 2,
50+
"outputProj" : true
51+
}, {
52+
"pop" : "screen",
53+
"@id" : 0,
54+
"child" : 1
55+
} ]
56+
}

0 commit comments

Comments
 (0)