diff --git ql/.gitignore ql/.gitignore index 916e17c..bd39306 100644 --- ql/.gitignore +++ ql/.gitignore @@ -1 +1,2 @@ dependency-reduced-pom.xml +/bin diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java index 535e4b3..a7d00ac 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java @@ -651,70 +651,6 @@ public static boolean isCustomUDF(ExprNodeGenericFuncDesc expr) { return !isNativeFunc; } - /** - * Handles only the special case of unary operators on a constant. - * @param exprDesc - * @return The same expression if no folding done, else return the constant - * expression. - * @throws HiveException - */ - ExprNodeDesc foldConstantsForUnaryExpression(ExprNodeDesc exprDesc) throws HiveException { - if (!(exprDesc instanceof ExprNodeGenericFuncDesc)) { - return exprDesc; - } - - if (exprDesc.getChildren() == null || (exprDesc.getChildren().size() != 1) ) { - return exprDesc; - } - - ExprNodeConstantDesc foldedChild = null; - if (!( exprDesc.getChildren().get(0) instanceof ExprNodeConstantDesc)) { - - // try recursive folding - ExprNodeDesc expr = foldConstantsForUnaryExpression(exprDesc.getChildren().get(0)); - if (expr instanceof ExprNodeConstantDesc) { - foldedChild = (ExprNodeConstantDesc) expr; - } - } else { - foldedChild = (ExprNodeConstantDesc) exprDesc.getChildren().get(0); - } - - if (foldedChild == null) { - return exprDesc; - } - - ObjectInspector childoi = foldedChild.getWritableObjectInspector(); - GenericUDF gudf = ((ExprNodeGenericFuncDesc) exprDesc).getGenericUDF(); - - if (gudf instanceof GenericUDFOPNegative || gudf instanceof GenericUDFOPPositive - || castExpressionUdfs.contains(gudf.getClass()) - || ((gudf instanceof GenericUDFBridge) - && castExpressionUdfs.contains(((GenericUDFBridge) gudf).getUdfClass()))) { - ExprNodeEvaluator evaluator = ExprNodeEvaluatorFactory.get(exprDesc); - ObjectInspector output = evaluator.initialize(childoi); - Object constant = evaluator.evaluate(null); - Object java = ObjectInspectorUtils.copyToStandardJavaObject(constant, output); - return new ExprNodeConstantDesc(exprDesc.getTypeInfo(), java); - } - - return exprDesc; - } - - /* Fold simple unary expressions in all members of the input list and return new list - * containing results. - */ - private List foldConstantsForUnaryExprs(List childExpr) - throws HiveException { - List constantFoldedChildren = new ArrayList(); - if (childExpr != null) { - for (ExprNodeDesc expr : childExpr) { - expr = this.foldConstantsForUnaryExpression(expr); - constantFoldedChildren.add(expr); - } - } - return constantFoldedChildren; - } - private VectorExpression getConstantVectorExpression(Object constantValue, TypeInfo typeInfo, Mode mode) throws HiveException { String type = typeInfo.getTypeName(); @@ -903,8 +839,6 @@ private VectorExpression instantiateExpression(Class vclass, TypeInfo returnT private VectorExpression getGenericUdfVectorExpression(GenericUDF udf, List childExpr, Mode mode, TypeInfo returnType) throws HiveException { - List constantFoldedChildren = foldConstantsForUnaryExprs(childExpr); - childExpr = constantFoldedChildren; //First handle special cases if (udf instanceof GenericUDFBetween) { return getBetweenFilterExpression(childExpr, mode, returnType); @@ -936,7 +870,7 @@ private VectorExpression getGenericUdfVectorExpression(GenericUDF udf, udfClass = ((GenericUDFBridge) udf).getUdfClass(); } - VectorExpression ve = getVectorExpressionForUdf(udfClass, constantFoldedChildren, mode, returnType); + VectorExpression ve = getVectorExpressionForUdf(udfClass, childExpr, mode, returnType); if (ve == null) { throw new HiveException("Udf: "+udf.getClass().getSimpleName()+", is not supported"); @@ -1010,9 +944,8 @@ private VectorExpression getInExpression(List childExpr, Mode mode String colType = colExpr.getTypeString(); // prepare arguments for createVectorExpression - List childrenForInList = - foldConstantsForUnaryExprs(childExpr.subList(1, childExpr.size())); - + List childrenForInList = childExpr; + /* This method assumes that the IN list has no NULL entries. That is enforced elsewhere, * in the Vectorizer class. If NULL is passed in as a list entry, behavior is not defined. * If in the future, NULL values are allowed in the IN list, be sure to handle 3-valued @@ -1281,7 +1214,7 @@ private VectorExpression getBetweenFilterExpression(List childExpr String colType = commonType.getTypeName(); // prepare arguments for createVectorExpression - List childrenAfterNot = foldConstantsForUnaryExprs(castChildren); + List childrenAfterNot = castChildren; // determine class Class cl = null; diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagate.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagate.java index 3c8940f..c16e8aa 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagate.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagate.java @@ -77,11 +77,6 @@ public ConstantPropagate() {} */ @Override public ParseContext transform(ParseContext pactx) throws SemanticException { - if (pactx.getConf().getBoolVar(ConfVars.HIVE_VECTORIZATION_ENABLED)) { - // Constant propagate is currently conflict with vectorizer, disabling constant propagate - // if the later is enabled. - return pactx; - } if (pactx.getConf().getBoolVar(ConfVars.HIVEOPTSORTMERGEBUCKETMAPJOIN)) { return pactx; } diff --git ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java index 2329f52..0612647 100644 --- ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java +++ ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java @@ -1189,26 +1189,6 @@ public void testIfConditionalExprs() throws HiveException { children1.set(2, col3Expr); ve = vc.getVectorExpression(exprDesc); assertTrue(ve instanceof IfExprStringScalarStringColumn); - } - - @Test - public void testFoldConstantsForUnaryExpression() throws HiveException { - ExprNodeConstantDesc constDesc = new ExprNodeConstantDesc(new Integer(1)); - GenericUDFToDecimal udf = new GenericUDFToDecimal(); - udf.setTypeInfo(new DecimalTypeInfo(5, 2)); - List children = new ArrayList(); - children.add(constDesc); - ExprNodeGenericFuncDesc exprDesc = new ExprNodeGenericFuncDesc(); - exprDesc.setGenericUDF(udf); - exprDesc.setChildren(children); - exprDesc.setTypeInfo(new DecimalTypeInfo(5, 2)); - Map columnMap = new HashMap(); - columnMap.put("col1", 1); - VectorizationContext vc = new VectorizationContext(columnMap, 1); - ExprNodeDesc constFoldNodeDesc = vc.foldConstantsForUnaryExpression(exprDesc); - assertTrue(constFoldNodeDesc instanceof ExprNodeConstantDesc); - assertTrue(((HiveDecimal) - (((ExprNodeConstantDesc)constFoldNodeDesc).getValue())).toString().equals("1")); } }