This is an automated email from the ASF dual-hosted git repository.
zabetak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new a539d2a46cc HIVE-29488: NPE in Kryo deserializer when query plan
contains ExprNodeGenericFuncDesc with Guava collections (#6352)
a539d2a46cc is described below
commit a539d2a46cc083a2f768f52cbff311a1f8f12a9e
Author: Thomas Rebele <[email protected]>
AuthorDate: Mon Mar 16 17:00:09 2026 +0100
HIVE-29488: NPE in Kryo deserializer when query plan contains
ExprNodeGenericFuncDesc with Guava collections (#6352)
---
.../hive/ql/plan/ExprNodeGenericFuncDesc.java | 34 ++++-
.../hive/ql/exec/TestSerializationUtilities.java | 23 ++++
.../ql/exec/vector/TestVectorizationContext.java | 142 +++++++++++----------
3 files changed, 133 insertions(+), 66 deletions(-)
diff --git
a/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeGenericFuncDesc.java
b/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeGenericFuncDesc.java
index d7f8c0b126d..7867d31f7a8 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeGenericFuncDesc.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeGenericFuncDesc.java
@@ -75,6 +75,12 @@ public class ExprNodeGenericFuncDesc extends ExprNodeDesc
implements
public ExprNodeGenericFuncDesc() {;
}
+ /**
+ * Constructor.
+ *
+ * @param children the children; a copy is made, so later changes to the
passed list
+ * do not affect the children of this instance
+ */
/* If the function has an explicit name like func(args) then call a
* constructor that explicitly provides the function name in the
* funcText argument.
@@ -86,6 +92,12 @@ public ExprNodeGenericFuncDesc(TypeInfo typeInfo, GenericUDF
genericUDF,
genericUDF, funcText, children);
}
+ /**
+ * Constructor.
+ *
+ * @param children the children; a copy is made, so later changes to the
passed list
+ * do not affect the children of this instance
+ */
public ExprNodeGenericFuncDesc(ObjectInspector oi, GenericUDF genericUDF,
String funcText,
List<ExprNodeDesc> children) {
@@ -94,16 +106,28 @@ public ExprNodeGenericFuncDesc(ObjectInspector oi,
GenericUDF genericUDF,
ObjectInspectorUtils.getWritableObjectInspector(oi);
assert (genericUDF != null);
this.genericUDF = genericUDF;
- this.children = children;
+ this.children = children == null ? new ArrayList<>() : new
ArrayList<>(children);
this.funcText = funcText;
}
+ /**
+ * Constructor.
+ *
+ * @param children the children; a copy is made, so later changes to the
passed list
+ * do not affect the children of this instance
+ */
// Backward-compatibility interfaces for functions without a user-visible
name.
public ExprNodeGenericFuncDesc(TypeInfo typeInfo, GenericUDF genericUDF,
List<ExprNodeDesc> children) {
this(typeInfo, genericUDF, null, children);
}
+ /**
+ * Constructor.
+ *
+ * @param children the children; a copy is made, so later changes to the
passed list
+ * do not affect the children of this instance
+ */
public ExprNodeGenericFuncDesc(ObjectInspector oi, GenericUDF genericUDF,
List<ExprNodeDesc> children) {
this(oi, genericUDF, null, children);
@@ -125,8 +149,14 @@ public void setGenericUDF(GenericUDF genericUDF) {
this.genericUDF = genericUDF;
}
+ /**
+ * Sets the children.
+ *
+ * @param children the new children; a copy is made, so later changes to the
passed list
+ * do not affect the children of this instance
+ */
public void setChildren(List<ExprNodeDesc> children) {
- this.children = children;
+ this.children = children == null ? new ArrayList<>() : new
ArrayList<>(children);
}
@Override
diff --git
a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestSerializationUtilities.java
b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestSerializationUtilities.java
index 5d58e09a571..a50a6bdd3d0 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestSerializationUtilities.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestSerializationUtilities.java
@@ -23,17 +23,21 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Properties;
+import com.google.common.collect.ArrayListMultimap;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.io.orc.OrcInputFormat;
import org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat;
import org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc;
import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
import org.apache.hadoop.hive.ql.plan.ExprNodeDescUtils;
import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
@@ -153,6 +157,25 @@ public void testUnsupportedDeserialization() throws
Exception {
Assert.assertTrue(ExprNodeDescUtils.isSame(validExpr, desc));
}
+ @Test
+ public void testSerializeChildrenFromGuavaCollection() throws Exception {
+ ExprNodeDesc column = new
ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "foo", null, false);
+ ExprNodeDesc constant = new
ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "bar");
+ ArrayListMultimap<Object, ExprNodeDesc> l = ArrayListMultimap.create();
+ l.put("coltype", column);
+ l.put("coltype", constant);
+
+ FunctionInfo inFunctionInfo = FunctionRegistry.getFunctionInfo("in");
+ Optional<Collection<ExprNodeDesc>> v =
l.asMap().values().stream().findFirst();
+ Assert.assertTrue(v.isPresent());
+ List<ExprNodeDesc> children = (List<ExprNodeDesc>) v.get();
+ ExprNodeGenericFuncDesc node =
ExprNodeGenericFuncDesc.newInstance(inFunctionInfo.getGenericUDF(), "in",
children);
+
+ byte[] buf =
SerializationUtilities.serializeObjectWithTypeInformation(node);
+ ExprNodeDesc desc =
SerializationUtilities.deserializeObjectWithTypeInformation(buf, true);
+ Assert.assertTrue(ExprNodeDescUtils.isSame(node, desc));
+ }
+
private MapWork doSerDeser(Configuration configuration) throws Exception,
IOException {
MapWork mapWork = mockMapWorkWithSomePartitionDescProperties();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git
a/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java
b/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java
index 7bdb565b3e8..d6ac3758891 100644
---
a/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java
+++
b/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java
@@ -36,6 +36,7 @@
import
org.apache.hadoop.hive.ql.exec.vector.expressions.FuncLogWithBaseDoubleToDouble;
import
org.apache.hadoop.hive.ql.exec.vector.expressions.FuncLogWithBaseLongToDouble;
import
org.apache.hadoop.hive.ql.exec.vector.expressions.FuncPowerDoubleToDouble;
+import
org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprCharScalarStringScalar;
import org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprColumnCondExpr;
import
org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprCondExprCondExpr;
import
org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprCharScalarStringGroupColumn;
@@ -47,6 +48,7 @@
import
org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprStringGroupColumnVarCharScalar;
import
org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprStringScalarStringGroupColumn;
import
org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprStringScalarStringScalar;
+import
org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprVarCharScalarStringScalar;
import org.apache.hadoop.hive.ql.exec.vector.expressions.StringLTrimCol;
import
org.apache.hadoop.hive.ql.exec.vector.expressions.gen.IfExprTimestampColumnColumn;
import
org.apache.hadoop.hive.ql.exec.vector.expressions.gen.IfExprTimestampColumnScalar;
@@ -149,6 +151,7 @@
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUnixTimeStamp;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFTimestamp;
import org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
import org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
import org.junit.Assert;
@@ -1129,7 +1132,7 @@ public void testBetweenFilters() throws HiveException {
// string NOT BETWEEN
children1.set(0, new ExprNodeConstantDesc(Boolean.TRUE)); // has NOT
keyword
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterStringColumnNotBetween);
// CHAR tests
@@ -1145,16 +1148,14 @@ public void testBetweenFilters() throws HiveException {
children1.add(col1Expr);
children1.add(constDesc);
children1.add(constDesc2);
- exprDesc = new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo,
udf,
- children1);
vc = new VectorizationContext("name", columns);
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterCharColumnBetween);
// CHAR NOT BETWEEN
children1.set(0, new ExprNodeConstantDesc(Boolean.TRUE)); // has NOT
keyword
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterCharColumnNotBetween);
// VARCHAR tests
@@ -1170,16 +1171,14 @@ public void testBetweenFilters() throws HiveException {
children1.add(col1Expr);
children1.add(constDesc);
children1.add(constDesc2);
- exprDesc = new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo,
udf,
- children1);
vc = new VectorizationContext("name", columns);
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterVarCharColumnBetween);
// VARCHAR NOT BETWEEN
children1.set(0, new ExprNodeConstantDesc(Boolean.TRUE)); // has NOT
keyword
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterVarCharColumnNotBetween);
// long BETWEEN
@@ -1187,12 +1186,12 @@ public void testBetweenFilters() throws HiveException {
children1.set(1, new ExprNodeColumnDesc(Long.class, "col1", "table",
false));
children1.set(2, new ExprNodeConstantDesc(10));
children1.set(3, new ExprNodeConstantDesc(20));
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterLongColumnBetween);
// long NOT BETWEEN
children1.set(0, new ExprNodeConstantDesc(Boolean.TRUE));
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterLongColumnNotBetween);
// double BETWEEN
@@ -1200,12 +1199,12 @@ public void testBetweenFilters() throws HiveException {
children1.set(1, new ExprNodeColumnDesc(Double.class, "col1", "table",
false));
children1.set(2, new ExprNodeConstantDesc(10.0d));
children1.set(3, new ExprNodeConstantDesc(20.0d));
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterDoubleColumnBetween);
// double NOT BETWEEN
children1.set(0, new ExprNodeConstantDesc(Boolean.TRUE));
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterDoubleColumnNotBetween);
// timestamp BETWEEN
@@ -1213,12 +1212,12 @@ public void testBetweenFilters() throws HiveException {
children1.set(1, new ExprNodeColumnDesc(Timestamp.class, "col1", "table",
false));
children1.set(2, new ExprNodeConstantDesc("2013-11-05 00:00:00.000"));
children1.set(3, new ExprNodeConstantDesc("2013-11-06 00:00:00.000"));
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertEquals(FilterTimestampColumnBetween.class, ve.getClass());
// timestamp NOT BETWEEN
children1.set(0, new ExprNodeConstantDesc(Boolean.TRUE));
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertEquals(FilterTimestampColumnNotBetween.class, ve.getClass());
}
@@ -1235,35 +1234,33 @@ public void testInFiltersAndExprs() throws
HiveException {
children1.add(col1Expr);
children1.add(constDesc);
children1.add(constDesc2);
- ExprNodeGenericFuncDesc exprDesc = new
ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo,
- udf, children1);
List<String> columns = new ArrayList<String>();
columns.add("col0");
columns.add("col1");
columns.add("col2");
VectorizationContext vc = new VectorizationContext("name", columns);
- VectorExpression ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ VectorExpression ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterStringColumnInList);
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.PROJECTION);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.PROJECTION);
assertTrue(ve instanceof StringColumnInList);
// long IN
children1.set(0, new ExprNodeColumnDesc(Long.class, "col1", "table",
false));
children1.set(1, new ExprNodeConstantDesc(10));
children1.set(2, new ExprNodeConstantDesc(20));
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterLongColumnInList);
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.PROJECTION);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.PROJECTION);
assertTrue(ve instanceof LongColumnInList);
// double IN
children1.set(0, new ExprNodeColumnDesc(Double.class, "col1", "table",
false));
children1.set(1, new ExprNodeConstantDesc(10d));
children1.set(2, new ExprNodeConstantDesc(20d));
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.FILTER);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterDoubleColumnInList);
- ve = vc.getVectorExpression(exprDesc,
VectorExpressionDescriptor.Mode.PROJECTION);
+ ve = createVectorExpression(vc, udf, children1,
VectorExpressionDescriptor.Mode.PROJECTION);
assertTrue(ve instanceof DoubleColumnInList);
}
@@ -1292,8 +1289,6 @@ public void testIfConditionalExprs() throws HiveException
{
children1.add(col1Expr);
children1.add(col2Expr);
children1.add(col3Expr);
- ExprNodeGenericFuncDesc exprDesc = new
ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, udf,
- children1);
List<String> columns = new ArrayList<String>();
columns.add("col0");
@@ -1301,23 +1296,22 @@ public void testIfConditionalExprs() throws
HiveException {
columns.add("col2");
columns.add("col3");
VectorizationContext vc = new VectorizationContext("name", columns);
- exprDesc.setTypeInfo(TypeInfoFactory.longTypeInfo);
- VectorExpression ve = vc.getVectorExpression(exprDesc);
+ VectorExpression ve = createVectorExpression(vc,
TypeInfoFactory.longTypeInfo, udf, children1);
assertTrue(ve instanceof IfExprLongColumnLongColumn);
// long column/scalar IF
children1.set(2, new ExprNodeConstantDesc(1L));
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.longTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprLongColumnLongScalar);
// long scalar/scalar IF
children1.set(1, new ExprNodeConstantDesc(1L));
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.longTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprLongScalarLongScalar);
// long scalar/column IF
children1.set(2, col3Expr);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.longTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprLongScalarLongColumn);
// test for double type
@@ -1327,28 +1321,27 @@ public void testIfConditionalExprs() throws
HiveException {
// double column/column IF
children1.set(1, col2Expr);
children1.set(2, col3Expr);
- exprDesc.setTypeInfo(TypeInfoFactory.doubleTypeInfo);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.doubleTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprDoubleColumnDoubleColumn);
// double column/scalar IF
children1.set(2, new ExprNodeConstantDesc(1D));
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.doubleTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprDoubleColumnDoubleScalar);
// double scalar/scalar IF
children1.set(1, new ExprNodeConstantDesc(1D));
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.doubleTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprDoubleScalarDoubleScalar);
// double scalar/column IF
children1.set(2, col3Expr);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.doubleTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprDoubleScalarDoubleColumn);
// double scalar/long column IF
children1.set(2, new ExprNodeColumnDesc(Long.class, "col3", "table",
false));
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.doubleTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprColumnCondExpr);
// Additional combinations of (long,double)X(column,scalar) for each of
the second
@@ -1362,8 +1355,7 @@ public void testIfConditionalExprs() throws HiveException
{
// timestamp column/column IF
children1.set(1, col2Expr);
children1.set(2, col3Expr);
- exprDesc.setTypeInfo(TypeInfoFactory.timestampTypeInfo);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.timestampTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprTimestampColumnColumn);
// timestamp column/scalar IF where scalar is really a CAST of a constant
to timestamp.
@@ -1371,21 +1363,21 @@ public void testIfConditionalExprs() throws
HiveException {
f.setGenericUDF(new GenericUDFTimestamp());
f.setTypeInfo(TypeInfoFactory.timestampTypeInfo);
List<ExprNodeDesc> children2 = new ArrayList<ExprNodeDesc>();
- f.setChildren(children2);
children2.add(new ExprNodeConstantDesc("2013-11-05 00:00:00.000"));
+ f.setChildren(children2);
children1.set(2, f);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.timestampTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprTimestampColumnScalar);
// timestamp scalar/scalar
children1.set(1, f);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.timestampTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprTimestampScalarScalar);
// timestamp scalar/column
children1.set(2, col3Expr);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.timestampTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprTimestampScalarColumn);
// test for boolean type
@@ -1395,23 +1387,22 @@ public void testIfConditionalExprs() throws
HiveException {
// column/column
children1.set(1, col2Expr);
children1.set(2, col3Expr);
- exprDesc.setTypeInfo(TypeInfoFactory.booleanTypeInfo);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.booleanTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprLongColumnLongColumn);
// column/scalar IF
children1.set(2, new ExprNodeConstantDesc(true));
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.booleanTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprLongColumnLongScalar);
// scalar/scalar IF
children1.set(1, new ExprNodeConstantDesc(true));
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.booleanTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprLongScalarLongScalar);
// scalar/column IF
children1.set(2, col3Expr);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.booleanTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprLongScalarLongColumn);
// test for string type
@@ -1423,23 +1414,22 @@ public void testIfConditionalExprs() throws
HiveException {
// column/column
children1.set(1, col2Expr);
children1.set(2, col3Expr);
- exprDesc.setTypeInfo(TypeInfoFactory.stringTypeInfo);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.stringTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprStringGroupColumnStringGroupColumn);
// column/scalar
children1.set(2, constDesc3);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.stringTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprStringGroupColumnStringScalar);
// scalar/scalar
children1.set(1, constDesc2);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.stringTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprStringScalarStringScalar);
// scalar/column
children1.set(2, col3Expr);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, TypeInfoFactory.stringTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprStringScalarStringGroupColumn);
// test for CHAR type
@@ -1452,23 +1442,22 @@ public void testIfConditionalExprs() throws
HiveException {
// column/column
children1.set(1, col2Expr);
children1.set(2, col3Expr);
- ve = vc.getVectorExpression(exprDesc);
- exprDesc.setTypeInfo(charTypeInfo);
+ ve = createVectorExpression(vc, TypeInfoFactory.stringTypeInfo, udf,
children1);
assertTrue(ve instanceof IfExprCondExprCondExpr);
// column/scalar
children1.set(2, constDesc3);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, charTypeInfo, udf, children1);
assertTrue(ve instanceof IfExprStringGroupColumnCharScalar);
// scalar/scalar
children1.set(1, constDesc2);
-// ve = vc.getVectorExpression(exprDesc);
-// assertTrue(ve instanceof IfExprCharScalarCharScalar);
+ ve = createVectorExpression(vc, charTypeInfo, udf, children1);
+ assertTrue(ve instanceof IfExprCharScalarStringScalar);
// scalar/column
children1.set(2, col3Expr);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, charTypeInfo, udf, children1);
assertTrue(ve instanceof IfExprCharScalarStringGroupColumn);
// test for VARCHAR type
@@ -1481,23 +1470,22 @@ public void testIfConditionalExprs() throws
HiveException {
// column/column
children1.set(1, col2Expr);
children1.set(2, col3Expr);
- exprDesc.setTypeInfo(varcharTypeInfo);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, varcharTypeInfo, udf, children1);
assertTrue(ve instanceof IfExprStringGroupColumnStringGroupColumn);
// column/scalar
children1.set(2, constDesc3);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, varcharTypeInfo, udf, children1);
assertTrue(ve instanceof IfExprStringGroupColumnVarCharScalar);
// scalar/scalar
children1.set(1, constDesc2);
-// ve = vc.getVectorExpression(exprDesc);
-// assertTrue(ve instanceof IfExprVarCharScalarVarCharScalar);
+ ve = createVectorExpression(vc, varcharTypeInfo, udf, children1);
+ assertTrue(ve instanceof IfExprVarCharScalarStringScalar);
// scalar/column
children1.set(2, col3Expr);
- ve = vc.getVectorExpression(exprDesc);
+ ve = createVectorExpression(vc, varcharTypeInfo, udf, children1);
assertTrue(ve instanceof IfExprVarCharScalarStringGroupColumn);
}
@@ -1623,4 +1611,30 @@ public void testInBloomFilter() throws Exception {
// Should be no need for child vector expressions, which would imply
casting/conversion.
Assert.assertNull(children);
}
+
+ /**
+ * Creates a vector expression with mode PROJECTION.
+ * <p>
+ * similar to {@link VectorizationContext#getVectorExpression(ExprNodeDesc)}.
+ * </p>
+ */
+ private VectorExpression createVectorExpression(VectorizationContext vc,
TypeInfo typeInfo, GenericUDFIf udf,
+ List<ExprNodeDesc> children) throws HiveException {
+ return createVectorExpression(vc, typeInfo, udf, children,
VectorExpressionDescriptor.Mode.PROJECTION);
+ }
+
+ /**
+ * Creates a vector expression of a boolean type.
+ */
+ private VectorExpression createVectorExpression(VectorizationContext vc,
GenericUDF udf, List<ExprNodeDesc> children,
+ VectorExpressionDescriptor.Mode mode) throws HiveException {
+ return createVectorExpression(vc, TypeInfoFactory.booleanTypeInfo, udf,
children, mode);
+ }
+
+ private static VectorExpression createVectorExpression(VectorizationContext
vc, TypeInfo typeInfo, GenericUDF udf,
+ List<ExprNodeDesc> children, VectorExpressionDescriptor.Mode mode)
throws HiveException {
+ ExprNodeGenericFuncDesc exprDesc = new ExprNodeGenericFuncDesc(typeInfo,
udf, children);
+ return vc.getVectorExpression(exprDesc, mode);
+ }
+
}