Search in sources :

Example 1 with LongColumnVector

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

the class TestConstantVectorExpression method testConstantExpression.

@Test
public void testConstantExpression() {
    ConstantVectorExpression longCve = new ConstantVectorExpression(0, 17);
    ConstantVectorExpression doubleCve = new ConstantVectorExpression(1, 17.34);
    String str = "alpha";
    ConstantVectorExpression bytesCve = new ConstantVectorExpression(2, str.getBytes());
    HiveDecimal decVal = HiveDecimal.create("25.8");
    ConstantVectorExpression decimalCve = new ConstantVectorExpression(3, decVal, "decimal");
    ConstantVectorExpression nullCve = new ConstantVectorExpression(4, "string", true);
    int size = 20;
    VectorizedRowBatch vrg = VectorizedRowGroupGenUtil.getVectorizedRowBatch(size, 5, 0);
    LongColumnVector lcv = (LongColumnVector) vrg.cols[0];
    DoubleColumnVector dcv = new DoubleColumnVector(size);
    BytesColumnVector bcv = new BytesColumnVector(size);
    DecimalColumnVector dv = new DecimalColumnVector(5, 1);
    BytesColumnVector bcvn = new BytesColumnVector(size);
    vrg.cols[1] = dcv;
    vrg.cols[2] = bcv;
    vrg.cols[3] = dv;
    vrg.cols[4] = bcvn;
    longCve.evaluate(vrg);
    doubleCve.evaluate(vrg);
    bytesCve.evaluate(vrg);
    decimalCve.evaluate(vrg);
    nullCve.evaluate(vrg);
    assertTrue(lcv.isRepeating);
    assertTrue(dcv.isRepeating);
    assertTrue(bcv.isRepeating);
    assertEquals(17, lcv.vector[0]);
    assertTrue(17.34 == dcv.vector[0]);
    assertTrue(bcvn.isRepeating);
    assertTrue(bcvn.isNull[0]);
    assertTrue(!bcvn.noNulls);
    byte[] alphaBytes = "alpha".getBytes();
    assertTrue(bcv.length[0] == alphaBytes.length);
    assertTrue(sameFirstKBytes(alphaBytes, bcv.vector[0], alphaBytes.length));
    // Evaluation of the bytes Constant Vector Expression after the vector is
    // modified. 
    ((BytesColumnVector) (vrg.cols[2])).vector[0] = "beta".getBytes();
    bytesCve.evaluate(vrg);
    assertTrue(bcv.length[0] == alphaBytes.length);
    assertTrue(sameFirstKBytes(alphaBytes, bcv.vector[0], alphaBytes.length));
    assertTrue(25.8 == dv.vector[0].getHiveDecimal().doubleValue());
    // Evaluation of the decimal Constant Vector Expression after the vector is
    // modified.    
    ((DecimalColumnVector) (vrg.cols[3])).vector[0].set(HiveDecimal.create("39.7"));
    decimalCve.evaluate(vrg);
    assertTrue(25.8 == dv.vector[0].getHiveDecimal().doubleValue());
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) Test(org.junit.Test)

Example 2 with LongColumnVector

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

the class TestVectorConditionalExpressions method testLongScalarScalarIfExpr.

@Test
public void testLongScalarScalarIfExpr() {
    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 3 with LongColumnVector

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

the class TestVectorConditionalExpressions method testLongColumnScalarIfExpr.

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

Example 4 with LongColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector 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)

Example 5 with LongColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector 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)

Aggregations

LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)223 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)116 Test (org.junit.Test)67 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)50 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)36 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)25 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)24 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)17 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)14 Random (java.util.Random)12 Configuration (org.apache.hadoop.conf.Configuration)8 VectorizedParquetRecordReader (org.apache.hadoop.hive.ql.io.parquet.vector.VectorizedParquetRecordReader)7 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)7 StructColumnVector (org.apache.hadoop.hive.ql.exec.vector.StructColumnVector)6 Path (org.apache.hadoop.fs.Path)5 LongWritable (org.apache.hadoop.io.LongWritable)5 IOException (java.io.IOException)4 Timestamp (java.sql.Timestamp)4 JoinUtil (org.apache.hadoop.hive.ql.exec.JoinUtil)4 IntervalDayTimeColumnVector (org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector)4