Search in sources :

Example 96 with VectorizedRowBatch

use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.

the class TestVectorArithmeticExpressions method testDecimalColMultiplyDecimalScalar.

/* Spot check correctness of decimal column multiply decimal scalar. The case for
   * addition checks all the cases for the template, so don't do that redundantly here.
   */
@Test
public void testDecimalColMultiplyDecimalScalar() throws HiveException {
    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    HiveDecimal d = HiveDecimal.create(2);
    VectorExpression expr = new DecimalColMultiplyDecimalScalar(0, d, 2);
    // test without nulls
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("2.40")));
    assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("-6.60")));
    assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("0")));
    // test that overflow produces null
    b = getVectorizedRowBatch3DecimalCols();
    DecimalColumnVector in = (DecimalColumnVector) b.cols[0];
    // set to max possible value
    in.vector[0].set(HiveDecimal.create("9999999999999999.99"));
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[2];
    assertFalse(r.noNulls);
    assertTrue(r.isNull[0]);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TestVectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) DecimalColMultiplyDecimalScalar(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.DecimalColMultiplyDecimalScalar) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) Test(org.junit.Test)

Example 97 with VectorizedRowBatch

use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.

the class TestVectorConditionalExpressions method testLongScalarScalarIfExpr.

@Test
public void testLongScalarScalarIfExpr() throws HiveException {
    VectorizedRowBatch batch = getBatch4LongVectors();
    VectorExpression expr = new IfExprLongScalarLongScalar(0, 100, 200, 3);
    LongColumnVector r = (LongColumnVector) batch.cols[3];
    expr.evaluate(batch);
    assertEquals(200, r.vector[0]);
    assertEquals(200, r.vector[1]);
    assertEquals(100, r.vector[2]);
    assertEquals(100, r.vector[3]);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) IfExprLongScalarLongScalar(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.IfExprLongScalarLongScalar) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) Test(org.junit.Test)

Example 98 with VectorizedRowBatch

use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.

the class TestVectorConditionalExpressions method testIfExprStringScalarStringScalar.

@Test
public void testIfExprStringScalarStringScalar() throws HiveException {
    // standard case
    VectorizedRowBatch batch = getBatch1Long3BytesVectors();
    byte[] scalar1 = getUTF8Bytes("scalar1");
    byte[] scalar2 = getUTF8Bytes("scalar2");
    VectorExpression expr = new IfExprStringScalarStringScalar(0, scalar1, scalar2, 3);
    BytesColumnVector r = (BytesColumnVector) batch.cols[3];
    expr.evaluate(batch);
    assertTrue(getString(r, 0).equals("scalar2"));
    assertTrue(getString(r, 1).equals("scalar2"));
    assertTrue(getString(r, 2).equals("scalar1"));
    assertTrue(getString(r, 3).equals("scalar1"));
    assertFalse(r.isRepeating);
    // repeating case for first (boolean flag) argument to IF
    batch = getBatch1Long3BytesVectors();
    batch.cols[0].isRepeating = true;
    expr.evaluate(batch);
    r = (BytesColumnVector) batch.cols[3];
    assertTrue(r.isRepeating);
    assertTrue(getString(r, 0).equals("scalar2"));
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) IfExprStringScalarStringScalar(org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprStringScalarStringScalar) Test(org.junit.Test)

Example 99 with VectorizedRowBatch

use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.

the class TestVectorConditionalExpressions method getBatch1Long3BytesVectors.

private VectorizedRowBatch getBatch1Long3BytesVectors() {
    VectorizedRowBatch batch = new VectorizedRowBatch(4);
    LongColumnVector lv = new LongColumnVector();
    // set first argument to IF -- boolean flag
    lv.vector[0] = 0;
    lv.vector[1] = 0;
    lv.vector[2] = 1;
    lv.vector[3] = 1;
    batch.cols[0] = lv;
    // set second argument to IF
    BytesColumnVector v = new BytesColumnVector();
    v.initBuffer();
    setString(v, 0, "arg2_0");
    setString(v, 1, "arg2_1");
    setString(v, 2, "arg2_2");
    setString(v, 3, "arg2_3");
    batch.cols[1] = v;
    // set third argument to IF
    v = new BytesColumnVector();
    v.initBuffer();
    setString(v, 0, "arg3_0");
    setString(v, 1, "arg3_1");
    setString(v, 2, "arg3_2");
    setString(v, 3, "arg3_3");
    batch.cols[2] = v;
    // set output column
    v = new BytesColumnVector();
    v.initBuffer();
    batch.cols[3] = v;
    batch.size = 4;
    return batch;
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 100 with VectorizedRowBatch

use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.

the class TestVectorConditionalExpressions method getBatch1Long3DoubleVectors.

private VectorizedRowBatch getBatch1Long3DoubleVectors() {
    VectorizedRowBatch batch = new VectorizedRowBatch(4);
    LongColumnVector lv = new LongColumnVector();
    // set first argument to IF -- boolean flag
    lv.vector[0] = 0;
    lv.vector[1] = 0;
    lv.vector[2] = 1;
    lv.vector[3] = 1;
    batch.cols[0] = lv;
    // set second argument to IF
    DoubleColumnVector v = new DoubleColumnVector();
    v.vector[0] = -1;
    v.vector[1] = -2;
    v.vector[2] = -3;
    v.vector[3] = -4;
    batch.cols[1] = v;
    // set third argument to IF
    v = new DoubleColumnVector();
    v.vector[0] = 1;
    v.vector[1] = 2;
    v.vector[2] = 3;
    v.vector[3] = 4;
    batch.cols[2] = v;
    // set output column
    batch.cols[3] = new DoubleColumnVector();
    batch.size = 4;
    return batch;
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Aggregations

VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)401 Test (org.junit.Test)214 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)157 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)98 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)83 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)64 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)40 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)32 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)30 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)28 VectorizedParquetRecordReader (org.apache.hadoop.hive.ql.io.parquet.vector.VectorizedParquetRecordReader)26 Configuration (org.apache.hadoop.conf.Configuration)23 IOException (java.io.IOException)20 HiveConf (org.apache.hadoop.hive.conf.HiveConf)20 VectorExtractRow (org.apache.hadoop.hive.ql.exec.vector.VectorExtractRow)19 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)18 VectorizationContext (org.apache.hadoop.hive.ql.exec.vector.VectorizationContext)18 Timestamp (java.sql.Timestamp)17 VectorUDFAdaptor (org.apache.hadoop.hive.ql.exec.vector.udf.VectorUDFAdaptor)16 VectorizedRowBatchCtx (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatchCtx)15