Search in sources :

Example 56 with VectorizedRowBatch

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

the class TestVectorArithmeticExpressions method longColAddLongScalarNoNulls.

private void longColAddLongScalarNoNulls(boolean checked) throws HiveException {
    VectorizedRowBatch vrg = getVectorizedRowBatchSingleLongVector(VectorizedRowBatch.DEFAULT_SIZE);
    VectorExpression expr;
    if (checked) {
        expr = new LongColAddLongScalarChecked(0, 23, 1);
        expr.setOutputTypeInfo(TypeInfoFactory.getPrimitiveTypeInfo("bigint"));
    } else {
        expr = new LongColAddLongScalar(0, 23, 1);
    }
    expr.evaluate(vrg);
    // verify
    for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
        Assert.assertEquals(i * 37 + 23, ((LongColumnVector) vrg.cols[1]).vector[i]);
    }
    Assert.assertTrue(((LongColumnVector) vrg.cols[1]).noNulls);
    Assert.assertFalse(((LongColumnVector) vrg.cols[1]).isRepeating);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TestVectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch) LongColAddLongScalar(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColAddLongScalar) LongColAddLongScalarChecked(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.LongColAddLongScalarChecked) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 57 with VectorizedRowBatch

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

the class TestVectorArithmeticExpressions method testDecimalColSubtractDecimalColumn.

// Spot check decimal column-column subtract
@Test
public void testDecimalColSubtractDecimalColumn() throws HiveException {
    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    VectorExpression expr = new DecimalColSubtractDecimalColumn(0, 1, 2);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
    // test without nulls
    expr.evaluate(b);
    assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("0.20")));
    assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("-4.30")));
    assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("-1.00")));
    // test that underflow produces NULL
    b = getVectorizedRowBatch3DecimalCols();
    DecimalColumnVector c0 = (DecimalColumnVector) b.cols[0];
    // set to min possible value
    c0.vector[0].set(HiveDecimal.create("-9999999999999999.99"));
    r = (DecimalColumnVector) b.cols[2];
    // will cause underflow for result at position 0, must yield NULL
    expr.evaluate(b);
    assertTrue(!r.noNulls && 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) DecimalColSubtractDecimalColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.DecimalColSubtractDecimalColumn) Test(org.junit.Test)

Example 58 with VectorizedRowBatch

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

the class TestVectorArithmeticExpressions method getVectorizedRowBatch2LongInLongOut.

private VectorizedRowBatch getVectorizedRowBatch2LongInLongOut() {
    VectorizedRowBatch batch = new VectorizedRowBatch(3);
    LongColumnVector lcv, lcv2;
    lcv = new LongColumnVector();
    for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
        lcv.vector[i] = i * 37;
    }
    batch.cols[0] = lcv;
    lcv2 = new LongColumnVector();
    batch.cols[1] = lcv2;
    for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
        lcv2.vector[i] = i * 37;
    }
    batch.cols[2] = new LongColumnVector();
    batch.size = VectorizedRowBatch.DEFAULT_SIZE;
    return batch;
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TestVectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 59 with VectorizedRowBatch

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

the class TestVectorArithmeticExpressions method testDecimalScalarModuloDecimalColumn.

// Spot check decimal scalar-column modulo
@Test
public void testDecimalScalarModuloDecimalColumn() throws HiveException {
    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    HiveDecimal d = HiveDecimal.create("2.00");
    VectorExpression expr = new DecimalScalarModuloDecimalColumn(d, 0, 2);
    // test without nulls
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("0.80")));
    assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("2.00")));
    // entry 2 will be null due to zero-divide
    assertFalse(r.noNulls);
    assertTrue(r.isNull[2]);
    // try again with some different data values
    DecimalColumnVector in = (DecimalColumnVector) b.cols[0];
    expr = new DecimalScalarModuloDecimalColumn(d, 0, 2);
    in.vector[0].set(HiveDecimal.create("0.50"));
    in.vector[1].set(HiveDecimal.create("0.80"));
    in.vector[2].set(HiveDecimal.create("0.70"));
    expr.evaluate(b);
    assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("0.00")));
    assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("0.40")));
    assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("0.60")));
}
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) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) DecimalScalarModuloDecimalColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.DecimalScalarModuloDecimalColumn) Test(org.junit.Test)

Example 60 with VectorizedRowBatch

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

the class TestVectorArithmeticExpressions method testLongColDivideLongColumn.

@Test
public void testLongColDivideLongColumn() throws HiveException {
    /* Testing for equality of doubles after a math operation is
     * not always reliable so use this as a tolerance.
     */
    final double eps = 1e-7d;
    VectorizedRowBatch batch = getVectorizedRowBatch2LongInDoubleOut();
    LongColDivideLongColumn expr = new LongColDivideLongColumn(0, 1, 2);
    batch.cols[0].isNull[1] = true;
    batch.cols[0].noNulls = false;
    batch.cols[1].noNulls = false;
    DoubleColumnVector out = (DoubleColumnVector) batch.cols[2];
    // Set so we can verify they are reset by operation
    out.noNulls = true;
    out.isRepeating = true;
    expr.evaluate(batch);
    // 0/0 for entry 0 should work but generate NaN
    assertFalse(out.noNulls);
    assertTrue(out.isNull[0]);
    assertTrue(Double.isNaN(out.vector[0]));
    // verify NULL output in entry 1 is correct
    assertTrue(out.isNull[1]);
    assertTrue(Double.isNaN(out.vector[1]));
    // check entries beyond first 2
    for (int i = 2; i != batch.size; i++) {
        assertTrue(out.vector[i] > 1.0d - eps && out.vector[i] < 1.0d + eps);
    }
    assertFalse(out.noNulls);
    assertFalse(out.isRepeating);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TestVectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) Test(org.junit.Test)

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