Search in sources :

Example 21 with LongColumnVector

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

the class TestVectorFilterExpressions method testFilterLongIn.

/**
   * Test the IN filter VectorExpression classes.
   */
@Test
public void testFilterLongIn() {
    int seed = 17;
    VectorizedRowBatch vrb = VectorizedRowGroupGenUtil.getVectorizedRowBatch(5, 2, seed);
    LongColumnVector lcv0 = (LongColumnVector) vrb.cols[0];
    long[] inList = { 5, 20 };
    FilterLongColumnInList f = new FilterLongColumnInList(0);
    f.setInListValues(inList);
    VectorExpression expr1 = f;
    // Basic case
    lcv0.vector[0] = 5;
    lcv0.vector[1] = 20;
    lcv0.vector[2] = 17;
    lcv0.vector[3] = 15;
    lcv0.vector[4] = 10;
    expr1.evaluate(vrb);
    assertEquals(2, vrb.size);
    assertTrue(vrb.selectedInUse);
    assertEquals(0, vrb.selected[0]);
    assertEquals(1, vrb.selected[1]);
    // With nulls
    VectorizedRowBatch vrb1 = VectorizedRowGroupGenUtil.getVectorizedRowBatch(5, 2, seed);
    lcv0 = (LongColumnVector) vrb1.cols[0];
    lcv0.vector[0] = 5;
    lcv0.vector[1] = 20;
    lcv0.vector[2] = 17;
    lcv0.vector[3] = 15;
    lcv0.vector[4] = 10;
    lcv0.noNulls = false;
    lcv0.isNull[0] = true;
    lcv0.isNull[2] = true;
    expr1.evaluate(vrb1);
    assertEquals(1, vrb1.size);
    assertTrue(vrb1.selectedInUse);
    assertEquals(1, vrb1.selected[0]);
    // With nulls and selected
    VectorizedRowBatch vrb2 = VectorizedRowGroupGenUtil.getVectorizedRowBatch(7, 2, seed);
    vrb2.selectedInUse = true;
    vrb2.selected[0] = 1;
    vrb2.selected[1] = 2;
    vrb2.selected[2] = 4;
    vrb2.size = 3;
    lcv0 = (LongColumnVector) vrb2.cols[0];
    lcv0.vector[0] = 5;
    lcv0.vector[1] = 20;
    lcv0.vector[2] = 17;
    lcv0.vector[3] = 15;
    lcv0.vector[4] = 10;
    lcv0.vector[5] = 19;
    lcv0.vector[6] = 21;
    lcv0.noNulls = false;
    lcv0.isNull[0] = true;
    lcv0.isNull[2] = true;
    lcv0.isNull[5] = true;
    expr1.evaluate(vrb2);
    assertEquals(1, vrb2.size);
    assertEquals(1, vrb2.selected[0]);
    // Repeating non null
    VectorizedRowBatch vrb3 = VectorizedRowGroupGenUtil.getVectorizedRowBatch(7, 2, seed);
    lcv0 = (LongColumnVector) vrb3.cols[0];
    lcv0.isRepeating = true;
    lcv0.vector[0] = 5;
    lcv0.vector[1] = 20;
    lcv0.vector[2] = 17;
    lcv0.vector[3] = 15;
    lcv0.vector[4] = 10;
    expr1.evaluate(vrb3);
    assertEquals(7, vrb3.size);
    assertFalse(vrb3.selectedInUse);
    assertTrue(lcv0.isRepeating);
    // Repeating null
    lcv0.noNulls = false;
    lcv0.vector[0] = 5;
    lcv0.isNull[0] = true;
    expr1.evaluate(vrb3);
    assertEquals(0, vrb3.size);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) Test(org.junit.Test)

Example 22 with LongColumnVector

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

the class TestVectorFilterExpressions method testFilterLongColGreaterLongColumn.

@Test
public void testFilterLongColGreaterLongColumn() {
    int seed = 17;
    VectorizedRowBatch b = VectorizedRowGroupGenUtil.getVectorizedRowBatch(VectorizedRowBatch.DEFAULT_SIZE, 2, seed);
    LongColumnVector lcv0 = (LongColumnVector) b.cols[0];
    LongColumnVector lcv1 = (LongColumnVector) b.cols[1];
    b.size = 3;
    FilterLongColGreaterLongColumn expr = new FilterLongColGreaterLongColumn(0, 1);
    // Basic case
    lcv0.vector[0] = 10;
    lcv0.vector[1] = 10;
    lcv0.vector[2] = 10;
    lcv1.vector[0] = 20;
    lcv1.vector[1] = 1;
    lcv1.vector[2] = 7;
    expr.evaluate(b);
    assertEquals(2, b.size);
    assertEquals(1, b.selected[0]);
    assertEquals(2, b.selected[1]);
    // handle null with selected in use
    lcv0.noNulls = false;
    lcv0.isNull[1] = true;
    expr.evaluate(b);
    assertEquals(1, b.size);
    assertEquals(2, b.selected[0]);
    // handle repeating
    b.size = 3;
    b.selectedInUse = false;
    lcv0.isRepeating = true;
    lcv0.noNulls = true;
    expr.evaluate(b);
    assertEquals(2, b.size);
    // handle repeating null
    b.size = 3;
    b.selectedInUse = false;
    lcv0.isNull[0] = true;
    lcv0.noNulls = false;
    expr.evaluate(b);
    assertEquals(0, b.size);
    // handle null on both sizes (not repeating)
    b.size = 3;
    b.selectedInUse = false;
    lcv0.isRepeating = false;
    lcv1.noNulls = false;
    lcv1.isNull[2] = true;
    expr.evaluate(b);
    assertEquals(0, b.size);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) FilterLongColGreaterLongColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.FilterLongColGreaterLongColumn) Test(org.junit.Test)

Example 23 with LongColumnVector

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

the class TestVectorGenericDateExpressions method validateDateDiff.

private void validateDateDiff(VectorizedRowBatch batch, LongColumnVector date1, LongColumnVector date2, VectorExpression.Type colType1, VectorExpression.Type colType2) {
    VectorExpression udf = new VectorUDFDateDiffColCol(0, 1, 2);
    udf.setInputTypes(colType1, colType2);
    udf.evaluate(batch);
    LongColumnVector output = (LongColumnVector) batch.cols[2];
    for (int i = 0; i < date1.vector.length; i++) {
        if (date1.isNull[i] || date2.isNull[i]) {
            Assert.assertTrue(output.isNull[i]);
        } else {
            Assert.assertEquals(date1.vector[i] - date2.vector[i], output.vector[i]);
        }
    }
}
Also used : LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 24 with LongColumnVector

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

the class TestVectorGenericDateExpressions method testDateDiffColScalar.

@Test
public void testDateDiffColScalar() {
    for (VectorExpression.Type colType1 : dateTimestampStringTypes) {
        for (VectorExpression.Type scalarType2 : dateTimestampStringTypes) {
            LongColumnVector date1 = newRandomLongColumnVector(10000, size);
            LongColumnVector output = new LongColumnVector(size);
            VectorizedRowBatch batch = new VectorizedRowBatch(2, size);
            batch.cols[0] = castTo(date1, colType1);
            batch.cols[1] = output;
            long scalar2 = newRandom(1000);
            validateDateDiff(batch, date1, scalar2, colType1, scalarType2);
            TestVectorizedRowBatch.addRandomNulls(date1);
            batch.cols[0] = castTo(date1, colType1);
            validateDateDiff(batch, date1, scalar2, colType1, scalarType2);
        }
    }
    VectorExpression udf;
    byte[] bytes = "error".getBytes(utf8);
    VectorizedRowBatch batch = new VectorizedRowBatch(2, 1);
    udf = new VectorUDFDateDiffColScalar(0, 0L, 1);
    udf.setInputTypes(VectorExpression.Type.TIMESTAMP, VectorExpression.Type.STRING);
    batch.cols[0] = new BytesColumnVector(1);
    batch.cols[1] = new LongColumnVector(1);
    BytesColumnVector bcv = (BytesColumnVector) batch.cols[0];
    bcv.vector[0] = bytes;
    bcv.start[0] = 0;
    bcv.length[0] = bytes.length;
    udf.evaluate(batch);
    Assert.assertEquals(batch.cols[1].isNull[0], true);
    udf = new VectorUDFDateDiffColScalar(0, bytes, 1);
    udf.setInputTypes(VectorExpression.Type.TIMESTAMP, VectorExpression.Type.STRING);
    batch.cols[0] = new LongColumnVector(1);
    batch.cols[1] = new LongColumnVector(1);
    udf.evaluate(batch);
    Assert.assertEquals(batch.cols[1].isNull[0], true);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TestVectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) Test(org.junit.Test)

Example 25 with LongColumnVector

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

the class TestVectorGenericDateExpressions method validateDate.

private void validateDate(VectorizedRowBatch batch, VectorExpression.Type colType, LongColumnVector date) {
    VectorExpression udf;
    if (colType == VectorExpression.Type.STRING) {
        udf = new VectorUDFDateString(0, 1);
    } else if (colType == VectorExpression.Type.TIMESTAMP) {
        udf = new VectorUDFDateTimestamp(0, 1);
    } else {
        udf = new VectorUDFDateLong(0, 1);
    }
    udf.setInputTypes(colType);
    udf.evaluate(batch);
    LongColumnVector output = (LongColumnVector) batch.cols[1];
    for (int i = 0; i < size; i++) {
        String actual;
        if (output.isNull[i]) {
            actual = null;
        } else {
            actual = new String(toString(output.vector[i]));
        }
        if (date.isNull[i]) {
            Assert.assertTrue(output.isNull[i]);
        } else {
            String expected = formatter.format(new Date(DateWritable.daysToMillis((int) date.vector[i])));
            Assert.assertEquals(expected, actual);
        }
    }
}
Also used : LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) Date(java.sql.Date)

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