Search in sources :

Example 1 with LongColAddLongColumn

use of org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColAddLongColumn in project hive by apache.

the class TestVectorArithmeticExpressions method testLongColAddLongColumn.

@Test
public void testLongColAddLongColumn() {
    int seed = 17;
    VectorizedRowBatch vrg = VectorizedRowGroupGenUtil.getVectorizedRowBatch(VectorizedRowBatch.DEFAULT_SIZE, 6, seed);
    LongColumnVector lcv0 = (LongColumnVector) vrg.cols[0];
    LongColumnVector lcv1 = (LongColumnVector) vrg.cols[1];
    LongColumnVector lcv2 = (LongColumnVector) vrg.cols[2];
    LongColumnVector lcv3 = (LongColumnVector) vrg.cols[3];
    LongColumnVector lcv4 = (LongColumnVector) vrg.cols[4];
    LongColumnVector lcv5 = (LongColumnVector) vrg.cols[5];
    LongColAddLongColumn expr = new LongColAddLongColumn(0, 1, 2);
    expr.evaluate(vrg);
    for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
        assertEquals((i + 1) * seed * 3, lcv2.vector[i]);
    }
    assertTrue(lcv2.noNulls);
    // Now set one column nullable
    lcv1.noNulls = false;
    lcv1.isNull[1] = true;
    // set output isRepeating to true to make sure it gets over-written
    lcv2.isRepeating = true;
    // similarly with noNulls
    lcv2.noNulls = true;
    expr.evaluate(vrg);
    assertTrue(lcv2.isNull[1]);
    assertFalse(lcv2.noNulls);
    assertFalse(lcv2.isRepeating);
    verifyLongNullDataVectorEntries(lcv2, vrg.selected, vrg.selectedInUse, vrg.size);
    // Now set other column nullable too
    lcv0.noNulls = false;
    lcv0.isNull[1] = true;
    lcv0.isNull[3] = true;
    expr.evaluate(vrg);
    assertTrue(lcv2.isNull[1]);
    assertTrue(lcv2.isNull[3]);
    assertFalse(lcv2.noNulls);
    verifyLongNullDataVectorEntries(lcv2, vrg.selected, vrg.selectedInUse, vrg.size);
    // Now test with repeating flag
    lcv3.isRepeating = true;
    LongColAddLongColumn expr2 = new LongColAddLongColumn(3, 4, 5);
    expr2.evaluate(vrg);
    for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
        assertEquals(seed * (4 + 5 * (i + 1)), lcv5.vector[i]);
    }
    // Repeating with other as nullable
    lcv4.noNulls = false;
    lcv4.isNull[0] = true;
    expr2.evaluate(vrg);
    assertTrue(lcv5.isNull[0]);
    assertFalse(lcv5.noNulls);
    verifyLongNullDataVectorEntries(lcv5, vrg.selected, vrg.selectedInUse, vrg.size);
    // Repeating null value
    lcv3.isRepeating = true;
    lcv3.noNulls = false;
    lcv3.isNull[0] = true;
    expr2.evaluate(vrg);
    assertFalse(lcv5.noNulls);
    assertTrue(lcv5.isRepeating);
    assertTrue(lcv5.isNull[0]);
    verifyLongNullDataVectorEntries(lcv5, vrg.selected, vrg.selectedInUse, vrg.size);
    // Neither input has nulls. Verify that this propagates to output.
    vrg.selectedInUse = false;
    lcv0.noNulls = true;
    lcv1.noNulls = true;
    lcv0.isRepeating = false;
    lcv1.isRepeating = false;
    // set output noNulls to true to make sure it gets over-written
    lcv2.noNulls = false;
    // similarly with isRepeating
    lcv2.isRepeating = true;
    expr.evaluate(vrg);
    assertTrue(lcv2.noNulls);
    assertFalse(lcv2.isRepeating);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TestVectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch) LongColAddLongColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColAddLongColumn) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) Test(org.junit.Test)

Example 2 with LongColAddLongColumn

use of org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColAddLongColumn in project hive by apache.

the class TestVectorArithmeticExpressions method longColAddLongColumnUtil.

private void longColAddLongColumnUtil(boolean isChecked) throws HiveException {
    int seed = 17;
    VectorizedRowBatch vrg = VectorizedRowGroupGenUtil.getVectorizedRowBatch(VectorizedRowBatch.DEFAULT_SIZE, 6, seed);
    LongColumnVector lcv0 = (LongColumnVector) vrg.cols[0];
    LongColumnVector lcv1 = (LongColumnVector) vrg.cols[1];
    LongColumnVector lcv2 = (LongColumnVector) vrg.cols[2];
    LongColumnVector lcv3 = (LongColumnVector) vrg.cols[3];
    LongColumnVector lcv4 = (LongColumnVector) vrg.cols[4];
    LongColumnVector lcv5 = (LongColumnVector) vrg.cols[5];
    VectorExpression expr;
    if (isChecked) {
        expr = new LongColAddLongColumnChecked(0, 1, 2);
        expr.setOutputTypeInfo(TypeInfoFactory.getPrimitiveTypeInfo("bigint"));
    } else {
        expr = new LongColAddLongColumn(0, 1, 2);
    }
    expr.evaluate(vrg);
    for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
        assertEquals((i + 1) * seed * 3, lcv2.vector[i]);
    }
    assertTrue(lcv2.noNulls);
    // Now set one column nullable
    lcv1.noNulls = false;
    lcv1.isNull[1] = true;
    // set output isRepeating to true to make sure it gets over-written
    lcv2.isRepeating = true;
    // similarly with noNulls
    lcv2.noNulls = true;
    expr.evaluate(vrg);
    assertTrue(lcv2.isNull[1]);
    assertFalse(lcv2.noNulls);
    assertFalse(lcv2.isRepeating);
    verifyLongNullDataVectorEntries(lcv2, vrg.selected, vrg.selectedInUse, vrg.size);
    // Now set other column nullable too
    lcv0.noNulls = false;
    lcv0.isNull[1] = true;
    lcv0.isNull[3] = true;
    expr.evaluate(vrg);
    assertTrue(lcv2.isNull[1]);
    assertTrue(lcv2.isNull[3]);
    assertFalse(lcv2.noNulls);
    verifyLongNullDataVectorEntries(lcv2, vrg.selected, vrg.selectedInUse, vrg.size);
    // Now test with repeating flag
    lcv3.isRepeating = true;
    VectorExpression expr2;
    if (isChecked) {
        expr2 = new LongColAddLongColumnChecked(3, 4, 5);
        expr2.setOutputTypeInfo(TypeInfoFactory.getPrimitiveTypeInfo("bigint"));
    } else {
        expr2 = new LongColAddLongColumn(3, 4, 5);
    }
    expr2.evaluate(vrg);
    for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
        assertEquals(seed * (4 + 5 * (i + 1)), lcv5.vector[i]);
    }
    // Repeating with other as nullable
    lcv4.noNulls = false;
    lcv4.isNull[0] = true;
    expr2.evaluate(vrg);
    assertTrue(lcv5.isNull[0]);
    assertFalse(lcv5.noNulls);
    verifyLongNullDataVectorEntries(lcv5, vrg.selected, vrg.selectedInUse, vrg.size);
    // Repeating null value
    lcv3.isRepeating = true;
    lcv3.noNulls = false;
    lcv3.isNull[0] = true;
    expr2.evaluate(vrg);
    assertFalse(lcv5.noNulls);
    assertTrue(lcv5.isRepeating);
    assertTrue(lcv5.isNull[0]);
    verifyLongNullDataVectorEntries(lcv5, vrg.selected, vrg.selectedInUse, vrg.size);
    // Neither input has nulls. Verify that this propagates to output.
    vrg.selectedInUse = false;
    lcv0.noNulls = true;
    lcv1.noNulls = true;
    lcv0.isRepeating = false;
    lcv1.isRepeating = false;
    lcv2.reset();
    expr.evaluate(vrg);
    assertTrue(lcv2.noNulls);
    assertFalse(lcv2.isRepeating);
}
Also used : LongColAddLongColumnChecked(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColAddLongColumnChecked) VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TestVectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch) LongColAddLongColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColAddLongColumn) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 3 with LongColAddLongColumn

use of org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColAddLongColumn in project hive by apache.

the class TestVectorizationContext method testArithmeticExpressionVectorization.

@Test
public void testArithmeticExpressionVectorization() throws HiveException {
    /**
     * Create original expression tree for following
     * (plus (minus (plus col1 col2) col3) (multiply col4 (mod col5 col6)) )
     */
    GenericUDFOPPlus udf1 = new GenericUDFOPPlus();
    GenericUDFOPMinus udf2 = new GenericUDFOPMinus();
    GenericUDFOPMultiply udf3 = new GenericUDFOPMultiply();
    GenericUDFOPPlus udf4 = new GenericUDFOPPlus();
    GenericUDFOPMod udf5 = new GenericUDFOPMod();
    ExprNodeGenericFuncDesc sumExpr = new ExprNodeGenericFuncDesc();
    sumExpr.setTypeInfo(TypeInfoFactory.intTypeInfo);
    sumExpr.setGenericUDF(udf1);
    ExprNodeGenericFuncDesc minusExpr = new ExprNodeGenericFuncDesc();
    minusExpr.setTypeInfo(TypeInfoFactory.intTypeInfo);
    minusExpr.setGenericUDF(udf2);
    ExprNodeGenericFuncDesc multiplyExpr = new ExprNodeGenericFuncDesc();
    multiplyExpr.setTypeInfo(TypeInfoFactory.intTypeInfo);
    multiplyExpr.setGenericUDF(udf3);
    ExprNodeGenericFuncDesc sum2Expr = new ExprNodeGenericFuncDesc();
    sum2Expr.setTypeInfo(TypeInfoFactory.intTypeInfo);
    sum2Expr.setGenericUDF(udf4);
    ExprNodeGenericFuncDesc modExpr = new ExprNodeGenericFuncDesc();
    modExpr.setTypeInfo(TypeInfoFactory.intTypeInfo);
    modExpr.setGenericUDF(udf5);
    ExprNodeColumnDesc col1Expr = new ExprNodeColumnDesc(Long.class, "col1", "table", false);
    ExprNodeColumnDesc col2Expr = new ExprNodeColumnDesc(Long.class, "col2", "table", false);
    ExprNodeColumnDesc col3Expr = new ExprNodeColumnDesc(Long.class, "col3", "table", false);
    ExprNodeColumnDesc col4Expr = new ExprNodeColumnDesc(Long.class, "col4", "table", false);
    ExprNodeColumnDesc col5Expr = new ExprNodeColumnDesc(Long.class, "col5", "table", false);
    ExprNodeColumnDesc col6Expr = new ExprNodeColumnDesc(Long.class, "col6", "table", false);
    List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>(2);
    List<ExprNodeDesc> children2 = new ArrayList<ExprNodeDesc>(2);
    List<ExprNodeDesc> children3 = new ArrayList<ExprNodeDesc>(2);
    List<ExprNodeDesc> children4 = new ArrayList<ExprNodeDesc>(2);
    List<ExprNodeDesc> children5 = new ArrayList<ExprNodeDesc>(2);
    children1.add(minusExpr);
    children1.add(multiplyExpr);
    sumExpr.setChildren(children1);
    children2.add(sum2Expr);
    children2.add(col3Expr);
    minusExpr.setChildren(children2);
    children3.add(col1Expr);
    children3.add(col2Expr);
    sum2Expr.setChildren(children3);
    children4.add(col4Expr);
    children4.add(modExpr);
    multiplyExpr.setChildren(children4);
    children5.add(col5Expr);
    children5.add(col6Expr);
    modExpr.setChildren(children5);
    VectorizationContext vc = new VectorizationContext("name");
    vc.addInitialColumn("col1");
    vc.addInitialColumn("col2");
    vc.addInitialColumn("col3");
    vc.addInitialColumn("col4");
    vc.addInitialColumn("col5");
    vc.addInitialColumn("col6");
    vc.finishedAddingInitialColumns();
    // Generate vectorized expression
    VectorExpression ve = vc.getVectorExpression(sumExpr, VectorExpressionDescriptor.Mode.PROJECTION);
    // Verify vectorized expression
    assertTrue(ve instanceof LongColAddLongColumn);
    assertEquals(2, ve.getChildExpressions().length);
    VectorExpression childExpr1 = ve.getChildExpressions()[0];
    VectorExpression childExpr2 = ve.getChildExpressions()[1];
    System.out.println(ve.toString());
    // TODO: HIVE-20985 disabled output column reuse
    // assertEquals(6, ve.getOutputColumnNum());
    assertEquals(10, ve.getOutputColumnNum());
    assertTrue(childExpr1 instanceof LongColSubtractLongColumn);
    assertEquals(1, childExpr1.getChildExpressions().length);
    assertTrue(childExpr1.getChildExpressions()[0] instanceof LongColAddLongColumn);
    assertEquals(7, childExpr1.getOutputColumnNum());
    assertEquals(6, childExpr1.getChildExpressions()[0].getOutputColumnNum());
    assertTrue(childExpr2 instanceof LongColMultiplyLongColumn);
    assertEquals(1, childExpr2.getChildExpressions().length);
    assertTrue(childExpr2.getChildExpressions()[0] instanceof LongColModuloLongColumn);
    // TODO: HIVE-20985 disabled output column reuse
    // assertEquals(8, childExpr2.getOutputColumnNum());
    // assertEquals(6, childExpr2.getChildExpressions()[0].getOutputColumnNum());
    assertEquals(9, childExpr2.getOutputColumnNum());
    assertEquals(8, childExpr2.getChildExpressions()[0].getOutputColumnNum());
}
Also used : GenericUDFOPMultiply(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPMultiply) GenericUDFOPMod(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPMod) ArrayList(java.util.ArrayList) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) LongColSubtractLongColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColSubtractLongColumn) GenericUDFOPPlus(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPPlus) GenericUDFOPMinus(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPMinus) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) VectorExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) LongColAddLongColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColAddLongColumn) LongColModuloLongColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColModuloLongColumn) LongColMultiplyLongColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColMultiplyLongColumn) Test(org.junit.Test)

Aggregations

LongColAddLongColumn (org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColAddLongColumn)3 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)2 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)2 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)1 LongColAddLongColumnChecked (org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColAddLongColumnChecked)1 LongColModuloLongColumn (org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColModuloLongColumn)1 LongColMultiplyLongColumn (org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColMultiplyLongColumn)1 LongColSubtractLongColumn (org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColSubtractLongColumn)1 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)1 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)1 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)1 GenericUDFOPMinus (org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPMinus)1 GenericUDFOPMod (org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPMod)1 GenericUDFOPMultiply (org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPMultiply)1 GenericUDFOPPlus (org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPPlus)1