Search in sources :

Example 6 with BytesColumnVector

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

the class TestVectorUDFAdaptor method testMultiArgumentUDF.

@Test
public void testMultiArgumentUDF() {
    // create a syntax tree for a function call "testudf(col0, col1, col2)"
    ExprNodeGenericFuncDesc funcDesc;
    TypeInfo typeInfoStr = TypeInfoFactory.stringTypeInfo;
    TypeInfo typeInfoLong = TypeInfoFactory.longTypeInfo;
    TypeInfo typeInfoDbl = TypeInfoFactory.doubleTypeInfo;
    GenericUDFBridge genericUDFBridge = new GenericUDFBridge("testudf", false, ConcatTextLongDoubleUDF.class.getName());
    List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>();
    children.add(new ExprNodeColumnDesc(typeInfoStr, "col0", "tablename", false));
    children.add(new ExprNodeColumnDesc(typeInfoLong, "col1", "tablename", false));
    children.add(new ExprNodeColumnDesc(typeInfoDbl, "col2", "tablename", false));
    VectorUDFArgDesc[] argDescs = new VectorUDFArgDesc[3];
    for (int i = 0; i < 3; i++) {
        argDescs[i] = new VectorUDFArgDesc();
        argDescs[i].setVariable(i);
    }
    funcDesc = new ExprNodeGenericFuncDesc(typeInfoStr, genericUDFBridge, genericUDFBridge.getUdfName(), children);
    // create the adaptor for this function call to work in vector mode
    VectorUDFAdaptor vudf = null;
    try {
        vudf = new VectorUDFAdaptor(funcDesc, 3, "String", argDescs);
    } catch (HiveException e) {
        // We should never get here.
        assertTrue(false);
        throw new RuntimeException(e);
    }
    // with no nulls
    VectorizedRowBatch b = getBatchStrDblLongWithStrOut();
    vudf.evaluate(b);
    byte[] result = null;
    byte[] result2 = null;
    try {
        result = "red:1:1.0".getBytes("UTF-8");
        result2 = "blue:0:0.0".getBytes("UTF-8");
    } catch (Exception e) {
        ;
    }
    BytesColumnVector out = (BytesColumnVector) b.cols[3];
    int cmp = StringExpr.compare(result, 0, result.length, out.vector[1], out.start[1], out.length[1]);
    assertEquals(0, cmp);
    assertTrue(out.noNulls);
    // with nulls
    b = getBatchStrDblLongWithStrOut();
    b.cols[1].noNulls = false;
    vudf.evaluate(b);
    out = (BytesColumnVector) b.cols[3];
    assertFalse(out.noNulls);
    assertTrue(out.isNull[1]);
    // with all input columns repeating
    b = getBatchStrDblLongWithStrOut();
    b.cols[0].isRepeating = true;
    b.cols[1].isRepeating = true;
    b.cols[2].isRepeating = true;
    vudf.evaluate(b);
    out = (BytesColumnVector) b.cols[3];
    assertTrue(out.isRepeating);
    cmp = StringExpr.compare(result2, 0, result2.length, out.vector[0], out.start[0], out.length[0]);
    assertEquals(0, cmp);
    assertTrue(out.noNulls);
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ArrayList(java.util.ArrayList) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) ConcatTextLongDoubleUDF(org.apache.hadoop.hive.ql.exec.vector.udf.legacy.ConcatTextLongDoubleUDF) Test(org.junit.Test)

Example 7 with BytesColumnVector

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

the class TestVectorExpressionWriters method testSetterText.

private void testSetterText(TypeInfo type) throws HiveException {
    Text t1 = new Text("alpha");
    Text t2 = new Text("beta");
    BytesColumnVector bcv = new BytesColumnVector(vectorSize);
    bcv.noNulls = false;
    bcv.initBuffer();
    bcv.setVal(0, t1.getBytes(), 0, t1.getLength());
    bcv.isNull[1] = true;
    bcv.setVal(2, t2.getBytes(), 0, t2.getLength());
    bcv.isNull[3] = true;
    bcv.setVal(4, t1.getBytes(), 0, t1.getLength());
    Object[] values = new Object[this.vectorSize];
    VectorExpressionWriter vew = getWriter(type);
    for (int i = 0; i < vectorSize; i++) {
        // setValue() should be able to handle null input
        values[i] = null;
        Writable w = (Writable) vew.setValue(values[i], bcv, i);
        if (w != null) {
            byte[] val = new byte[bcv.length[i]];
            System.arraycopy(bcv.vector[i], bcv.start[i], val, 0, bcv.length[i]);
            Writable expected = getWritableValue(type, val);
            Assert.assertEquals(expected, w);
        } else {
            Assert.assertTrue(bcv.isNull[i]);
        }
    }
}
Also used : BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) Writable(org.apache.hadoop.io.Writable) LongWritable(org.apache.hadoop.io.LongWritable) BytesWritable(org.apache.hadoop.io.BytesWritable) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) IntWritable(org.apache.hadoop.io.IntWritable) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) BooleanWritable(org.apache.hadoop.io.BooleanWritable) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) FloatWritable(org.apache.hadoop.io.FloatWritable) Text(org.apache.hadoop.io.Text)

Example 8 with BytesColumnVector

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

the class TestVectorStringExpressions method testVectorLTrim.

@Test
public void testVectorLTrim() {
    VectorizedRowBatch b = makeTrimBatch();
    VectorExpression expr = new StringLTrim(0, 1);
    expr.evaluate(b);
    BytesColumnVector outV = (BytesColumnVector) b.cols[1];
    Assert.assertEquals(0, StringExpr.compare(emptyString, 0, 0, outV.vector[0], 0, 0));
    Assert.assertEquals(0, StringExpr.compare(blanksLeft, 2, 3, outV.vector[1], outV.start[1], outV.length[1]));
    Assert.assertEquals(0, StringExpr.compare(blanksRight, 0, 5, outV.vector[2], outV.start[2], outV.length[2]));
    Assert.assertEquals(0, StringExpr.compare(blanksBoth, 2, 5, outV.vector[3], outV.start[3], outV.length[3]));
    Assert.assertEquals(0, StringExpr.compare(red, 0, 3, outV.vector[4], outV.start[4], outV.length[4]));
    Assert.assertEquals(0, StringExpr.compare(blankString, 0, 0, outV.vector[5], outV.start[5], outV.length[5]));
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) Test(org.junit.Test)

Example 9 with BytesColumnVector

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

the class TestVectorStringExpressions method testTruncateBytesColumnVector.

@Test
public // Test basic truncate to vector.
void testTruncateBytesColumnVector() {
    BytesColumnVector outV = new BytesColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
    // initialize with estimated element size 35
    outV.initBuffer(35);
    int i = 0;
    int largeMaxLength = 100;
    int expectedResultLen;
    // No truncate (ASCII) -- maximum length large.
    Assert.assertTrue(StringExpr.characterCount(blue, 0, blue.length) == 4);
    StringExpr.truncate(outV, i, blue, 0, blue.length, largeMaxLength);
    expectedResultLen = blue.length;
    Assert.assertTrue(vectorEqual(outV, i, blue, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 4);
    i++;
    Assert.assertTrue(StringExpr.characterCount(redgreen, 0, redgreen.length) == 8);
    StringExpr.truncate(outV, i, redgreen, 0, redgreen.length, largeMaxLength);
    expectedResultLen = redgreen.length;
    Assert.assertTrue(vectorEqual(outV, i, redgreen, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(ascii_sentence, 0, ascii_sentence.length) == 31);
    StringExpr.truncate(outV, i, ascii_sentence, 0, ascii_sentence.length, largeMaxLength);
    expectedResultLen = ascii_sentence.length;
    Assert.assertTrue(vectorEqual(outV, i, ascii_sentence, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksLeft, 0, blanksLeft.length) == 5);
    StringExpr.truncate(outV, i, blanksLeft, 0, blanksLeft.length, largeMaxLength);
    expectedResultLen = blanksLeft.length;
    Assert.assertTrue(vectorEqual(outV, i, blanksLeft, 0, expectedResultLen));
    i++;
    // No truncate (ASCII) -- same maximum length.
    Assert.assertTrue(StringExpr.characterCount(blue, 0, blue.length) == 4);
    StringExpr.truncate(outV, i, blue, 0, blue.length, 4);
    expectedResultLen = blue.length;
    Assert.assertTrue(vectorEqual(outV, i, blue, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 4);
    i++;
    Assert.assertTrue(StringExpr.characterCount(redgreen, 0, redgreen.length) == 8);
    StringExpr.truncate(outV, i, redgreen, 0, redgreen.length, 8);
    expectedResultLen = redgreen.length;
    Assert.assertTrue(vectorEqual(outV, i, redgreen, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(ascii_sentence, 0, ascii_sentence.length) == 31);
    StringExpr.truncate(outV, i, ascii_sentence, 0, ascii_sentence.length, 31);
    expectedResultLen = ascii_sentence.length;
    Assert.assertTrue(vectorEqual(outV, i, ascii_sentence, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksLeft, 0, blanksLeft.length) == 5);
    StringExpr.truncate(outV, i, blanksLeft, 0, blanksLeft.length, 5);
    expectedResultLen = blanksLeft.length;
    Assert.assertTrue(vectorEqual(outV, i, blanksLeft, 0, expectedResultLen));
    i++;
    // Simple truncation.
    Assert.assertTrue(StringExpr.characterCount(blue, 0, blue.length) == 4);
    StringExpr.truncate(outV, i, blue, 0, blue.length, 3);
    expectedResultLen = 3;
    Assert.assertTrue(vectorEqual(outV, i, blue, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 3);
    i++;
    Assert.assertTrue(StringExpr.characterCount(redgreen, 0, redgreen.length) == 8);
    StringExpr.truncate(outV, i, redgreen, 0, redgreen.length, 6);
    expectedResultLen = 6;
    Assert.assertTrue(vectorEqual(outV, i, redgreen, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(ascii_sentence, 0, ascii_sentence.length) == 31);
    StringExpr.truncate(outV, i, ascii_sentence, 0, ascii_sentence.length, 14);
    expectedResultLen = 14;
    Assert.assertTrue(vectorEqual(outV, i, ascii_sentence, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksLeft, 0, blanksLeft.length) == 5);
    StringExpr.truncate(outV, i, blanksLeft, 0, blanksLeft.length, 2);
    expectedResultLen = 2;
    Assert.assertTrue(vectorEqual(outV, i, blanksLeft, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksRight, 0, blanksRight.length) == 5);
    StringExpr.truncate(outV, i, blanksRight, 0, blanksRight.length, 4);
    expectedResultLen = 4;
    Assert.assertTrue(vectorCharacterCount(outV, i) == 4);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksBoth, 0, blanksBoth.length) == 7);
    StringExpr.truncate(outV, i, blanksBoth, 0, blanksBoth.length, 2);
    expectedResultLen = 2;
    Assert.assertTrue(vectorEqual(outV, i, blanksBoth, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 2);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankString, 0, blankString.length) == 2);
    StringExpr.truncate(outV, i, blankString, 0, blankString.length, 1);
    expectedResultLen = 1;
    Assert.assertTrue(vectorEqual(outV, i, blankString, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 1);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankRanges, 0, blankRanges.length) == 30);
    StringExpr.truncate(outV, i, blankRanges, 0, blankRanges.length, 29);
    expectedResultLen = 29;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 29);
    i++;
    // Offset truncation.
    Assert.assertTrue(StringExpr.characterCount(blanksRight, 1, blanksRight.length - 1) == 4);
    StringExpr.truncate(outV, i, blanksRight, 1, blanksRight.length - 1, 3);
    expectedResultLen = 3;
    Assert.assertTrue(vectorEqual(outV, i, blanksRight, 1, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 3);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksBoth, 4, blanksBoth.length - 4) == 3);
    StringExpr.truncate(outV, i, blanksBoth, 4, blanksBoth.length - 4, 2);
    expectedResultLen = 2;
    Assert.assertTrue(vectorEqual(outV, i, blanksBoth, 4, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 2);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksBoth, 5, blanksBoth.length - 5) == 2);
    StringExpr.truncate(outV, i, blanksBoth, 5, blanksBoth.length - 5, 1);
    expectedResultLen = 1;
    Assert.assertTrue(vectorEqual(outV, i, blanksBoth, 5, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 1);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankRanges, 4, blankRanges.length - 4) == 26);
    StringExpr.truncate(outV, i, blankRanges, 4, blankRanges.length - 4, 22);
    expectedResultLen = 22;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 4, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 22);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankRanges, 6, blankRanges.length - 6) == 24);
    StringExpr.truncate(outV, i, blankRanges, 6, blankRanges.length - 6, 7);
    expectedResultLen = 7;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 6, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 7);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankRanges, 7, blankRanges.length - 7) == 23);
    StringExpr.truncate(outV, i, blankRanges, 7, blankRanges.length - 7, 20);
    expectedResultLen = 20;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 7, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 20);
    i++;
    // Multi-byte truncation.
    byte[] multiByte = new byte[100];
    addMultiByteCharRightPadded1_1(multiByte);
    Assert.assertTrue(StringExpr.characterCount(multiByte, 0, 4) == 2);
    StringExpr.truncate(outV, i, multiByte, 0, 4, 1);
    expectedResultLen = 3;
    Assert.assertTrue(vectorEqual(outV, i, multiByte, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 1);
    i++;
    addMultiByteCharRightPadded1_2(multiByte);
    Assert.assertTrue(StringExpr.characterCount(multiByte, 0, 5) == 3);
    StringExpr.truncate(outV, i, multiByte, 0, 5, 2);
    expectedResultLen = 4;
    Assert.assertTrue(vectorEqual(outV, i, multiByte, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 2);
    i++;
    addMultiByteCharRightPadded1_3(multiByte);
    Assert.assertTrue(StringExpr.characterCount(multiByte, 0, 9) == 4);
    StringExpr.truncate(outV, i, multiByte, 0, 9, 2);
    expectedResultLen = 5;
    Assert.assertTrue(vectorEqual(outV, i, multiByte, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 2);
    i++;
    addMultiByteCharRightPadded1_2(multiByte);
    Assert.assertTrue(StringExpr.characterCount(multiByte, 3, 2) == 2);
    StringExpr.truncate(outV, i, multiByte, 3, 2, 1);
    expectedResultLen = 1;
    Assert.assertTrue(vectorEqual(outV, i, multiByte, 3, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 1);
    i++;
    byte[] sentenceOne = new byte[100];
    int sentenceOneLen = addMultiByteCharSentenceOne(sentenceOne, 0);
    Assert.assertTrue(StringExpr.characterCount(sentenceOne, 0, sentenceOneLen) == 10);
    StringExpr.truncate(outV, i, sentenceOne, 0, sentenceOneLen, 8);
    expectedResultLen = 20;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOne, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOne, 0, sentenceOneLen - 3) == 9);
    StringExpr.truncate(outV, i, sentenceOne, 0, sentenceOneLen - 3, 3);
    expectedResultLen = 9;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOne, 0, expectedResultLen));
    i++;
    byte[] sentenceTwo = new byte[100];
    int sentenceTwoLen = addMultiByteCharSentenceTwo(sentenceTwo, 0);
    Assert.assertTrue(StringExpr.characterCount(sentenceTwo, 0, sentenceTwoLen) == 13);
    StringExpr.truncate(outV, i, sentenceTwo, 0, sentenceTwoLen, 9);
    expectedResultLen = 16;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwo, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwo, 0, sentenceTwoLen - 5) == 10);
    StringExpr.truncate(outV, i, sentenceTwo, 0, sentenceTwoLen - 5, 6);
    expectedResultLen = 11;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwo, 0, expectedResultLen));
    i++;
    int start;
    // Left pad longer strings with multi-byte characters.
    byte[] sentenceOnePaddedLeft = new byte[100];
    start = addPads(sentenceOnePaddedLeft, 0, 3);
    int sentenceOnePaddedLeftLen = addMultiByteCharSentenceOne(sentenceOnePaddedLeft, start);
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen) == 3 + 10);
    StringExpr.truncate(outV, i, sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen, 4);
    expectedResultLen = 6;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedLeft, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen - 3) == 3 + 9);
    StringExpr.truncate(outV, i, sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen - 3, 7);
    expectedResultLen = 13;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedLeft, 0, expectedResultLen));
    i++;
    byte[] sentenceTwoPaddedLeft = new byte[100];
    start = addPads(sentenceTwoPaddedLeft, 0, 2);
    int sentenceTwoPaddedLeftLen = addMultiByteCharSentenceTwo(sentenceTwoPaddedLeft, start);
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen) == 2 + 13);
    StringExpr.truncate(outV, i, sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen, 14);
    expectedResultLen = 24;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedLeft, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen - 5) == 2 + 10);
    StringExpr.truncate(outV, i, sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen - 5, 9);
    expectedResultLen = 15;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedLeft, 0, expectedResultLen));
    i++;
    // Right pad longer strings with multi-byte characters.
    byte[] sentenceOnePaddedRight = new byte[100];
    start = addMultiByteCharSentenceOne(sentenceOnePaddedRight, 0);
    int sentenceOnePaddedRightLen = addPads(sentenceOnePaddedRight, start, 4);
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen) == 10 + 4);
    StringExpr.truncate(outV, i, sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen, 1);
    expectedResultLen = 3;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedRight, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen - 3 - 4) == 9);
    StringExpr.truncate(outV, i, sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen - 3 - 4, 5);
    expectedResultLen = 13;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedRight, 0, expectedResultLen));
    i++;
    byte[] sentenceTwoPaddedRight = new byte[100];
    start = addMultiByteCharSentenceTwo(sentenceTwoPaddedRight, 0);
    int sentenceTwoPaddedRightLen = addPads(sentenceTwoPaddedRight, start, 1);
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen) == 13 + 1);
    StringExpr.truncate(outV, i, sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen, 6);
    expectedResultLen = 11;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedRight, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen - 5 - 1) == 10);
    StringExpr.truncate(outV, i, sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen - 5 - 1, 8);
    expectedResultLen = 14;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedRight, 0, expectedResultLen));
    i++;
    // Multi-byte characters with blank ranges.
    byte[] sentenceBlankRanges = new byte[100];
    int sentenceBlankRangesLen = addMultiByteCharSentenceBlankRanges(sentenceBlankRanges, 0);
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 0, sentenceBlankRangesLen) == 17);
    StringExpr.truncate(outV, i, sentenceBlankRanges, 0, sentenceBlankRangesLen, 4);
    expectedResultLen = 9;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 0, sentenceBlankRangesLen - 3) == 16);
    StringExpr.truncate(outV, i, sentenceBlankRanges, 0, sentenceBlankRangesLen - 3, 14);
    expectedResultLen = 23;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 7, 17) == 13);
    StringExpr.truncate(outV, i, sentenceBlankRanges, 7, 17, 11);
    expectedResultLen = 15;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 7, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 11);
    i++;
}
Also used : BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) Test(org.junit.Test)

Example 10 with BytesColumnVector

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

the class TestVectorStringExpressions method makeStringBatchForColColCompare.

private VectorizedRowBatch makeStringBatchForColColCompare() {
    VectorizedRowBatch batch = new VectorizedRowBatch(4);
    BytesColumnVector v = new BytesColumnVector();
    batch.cols[0] = v;
    BytesColumnVector v2 = new BytesColumnVector();
    batch.cols[1] = v2;
    batch.cols[2] = new BytesColumnVector();
    batch.cols[3] = new LongColumnVector();
    v.setRef(0, blue, 0, blue.length);
    v.isNull[0] = false;
    v.setRef(1, green, 0, green.length);
    v.isNull[1] = false;
    v.setRef(2, red, 0, red.length);
    v.isNull[2] = false;
    v.setRef(3, emptyString, 0, emptyString.length);
    v.isNull[3] = true;
    v.noNulls = false;
    v2.setRef(0, red, 0, red.length);
    v2.isNull[0] = false;
    v2.setRef(1, green, 0, green.length);
    v2.isNull[1] = false;
    v2.setRef(2, blue, 0, blue.length);
    v2.isNull[2] = false;
    v2.setRef(3, red, 0, red.length);
    v2.isNull[3] = false;
    v2.noNulls = false;
    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

BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)124 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)66 Test (org.junit.Test)50 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)44 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)12 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)10 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)8 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)8 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)8 Text (org.apache.hadoop.io.Text)8 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Path (org.apache.hadoop.fs.Path)4 JoinUtil (org.apache.hadoop.hive.ql.exec.JoinUtil)4 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)4 TypeDescription (org.apache.orc.TypeDescription)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ParseException (java.text.ParseException)3 Random (java.util.Random)3