You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2013/06/13 21:29:52 UTC

svn commit: r1492825 - in /hive/branches/vectorization/ql/src: java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java

Author: hashutosh
Date: Thu Jun 13 19:29:52 2013
New Revision: 1492825

URL: http://svn.apache.org/r1492825
Log:
HIVE-4714 : Vectorized Sum of scalar subtract column returns negative result when positive exected (Jitendra Nath Pandey via Ashutosh Chauhan)

Modified:
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
    hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java

Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java?rev=1492825&r1=1492824&r2=1492825&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java Thu Jun 13 19:29:52 2013
@@ -443,23 +443,23 @@ public class VectorizationContext {
       } catch (Exception ex) {
         throw new HiveException(ex);
       }
-    } else if ( (rightExpr instanceof ExprNodeColumnDesc) &&
-        (leftExpr instanceof ExprNodeConstantDesc) ) {
+    } else if ( (leftExpr instanceof ExprNodeConstantDesc) &&
+        (rightExpr instanceof ExprNodeColumnDesc) ) {
       ExprNodeColumnDesc rightColDesc = (ExprNodeColumnDesc) rightExpr;
       ExprNodeConstantDesc constDesc = (ExprNodeConstantDesc) leftExpr;
       int inputCol = getInputColumnIndex(rightColDesc.getColumn());
       String colType = rightColDesc.getTypeString();
       String scalarType = constDesc.getTypeString();
-      String className = getBinaryColumnScalarExpressionClassName(colType,
+      String className = getBinaryScalarColumnExpressionClassName(colType,
           scalarType, method);
       String outputColType = getOutputColType(colType, scalarType, method);
       int outputCol = ocm.allocateOutputColumn(outputColType);
       try {
         expr = (VectorExpression) Class.forName(className).
-            getDeclaredConstructors()[0].newInstance(inputCol,
-            getScalarValue(constDesc), outputCol);
+            getDeclaredConstructors()[0].newInstance(getScalarValue(constDesc),
+            inputCol, outputCol);
       } catch (Exception ex) {
-        throw new HiveException(ex);
+        throw new HiveException("Could not instantiate: "+className, ex);
       }
     } else if ( (rightExpr instanceof ExprNodeColumnDesc) &&
         (leftExpr instanceof ExprNodeColumnDesc) ) {

Modified: hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java?rev=1492825&r1=1492824&r2=1492825&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java (original)
+++ hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java Thu Jun 13 19:29:52 2013
@@ -18,6 +18,7 @@ import org.apache.hadoop.hive.ql.exec.ve
 import org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColModuloLongColumn;
 import org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColMultiplyLongColumn;
 import org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColSubtractLongColumn;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongScalarSubtractLongColumn;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
 import org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc;
 import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc;
@@ -28,11 +29,13 @@ import org.apache.hadoop.hive.ql.udf.UDF
 import org.apache.hadoop.hive.ql.udf.UDFOPMod;
 import org.apache.hadoop.hive.ql.udf.UDFOPMultiply;
 import org.apache.hadoop.hive.ql.udf.UDFOPPlus;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPAnd;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPGreaterThan;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPLessThan;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPOr;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
 import org.junit.Test;
 
 public class TestVectorizationContext {
@@ -237,6 +240,28 @@ public class TestVectorizationContext {
     assertEquals(veOr.getChildExpressions()[1].getClass(), FilterDoubleColLessDoubleScalar.class);
   }
 
+  @Test
+  public void testVectorizeScalarColumnExpression() throws HiveException {
+    ExprNodeGenericFuncDesc scalarMinusConstant = new ExprNodeGenericFuncDesc();
+    GenericUDF gudf = new GenericUDFBridge("-", true, UDFOPMinus.class);
+    scalarMinusConstant.setGenericUDF(gudf);
+    List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>(2);
+    ExprNodeConstantDesc constDesc = new ExprNodeConstantDesc(TypeInfoFactory.longTypeInfo, 20);
+    ExprNodeColumnDesc colDesc = new ExprNodeColumnDesc(Long.class, "a", "table", false);
+
+    children.add(constDesc);
+    children.add(colDesc);
+
+    scalarMinusConstant.setChildExprs(children);
+
+    Map<String, Integer> columnMap = new HashMap<String, Integer>();
+    columnMap.put("a", 0);
+
+    VectorizationContext vc = new VectorizationContext(columnMap, 2);
+    VectorExpression ve = vc.getVectorExpression(scalarMinusConstant);
+
+    assertEquals(ve.getClass(), LongScalarSubtractLongColumn.class);
+  }
 
   @Test
   public void testFilterWithNegativeScalar() throws HiveException {