Search in sources :

Example 26 with BytesColumnVector

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

the class TestVectorStringExpressions method testColConcatVarCharScalar.

@Test
public void testColConcatVarCharScalar() {
    // has nulls, not repeating
    VectorizedRowBatch batch = makeStringBatch();
    StringGroupColConcatVarCharScalar expr = new StringGroupColConcatVarCharScalar(0, new HiveVarchar(new String(red), 14), 1);
    expr.evaluate(batch);
    BytesColumnVector outCol = (BytesColumnVector) batch.cols[1];
    int cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]);
    Assert.assertEquals(0, cmp);
    Assert.assertTrue(outCol.isNull[2]);
    int cmp2 = StringExpr.compare(greenred, 0, greenred.length, outCol.vector[1], outCol.start[1], outCol.length[1]);
    Assert.assertEquals(0, cmp2);
    Assert.assertFalse(outCol.noNulls);
    Assert.assertFalse(outCol.isRepeating);
    // no nulls, not repeating
    batch = makeStringBatch();
    batch.cols[0].noNulls = true;
    expr.evaluate(batch);
    outCol = (BytesColumnVector) batch.cols[1];
    cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]);
    Assert.assertEquals(0, cmp);
    cmp2 = StringExpr.compare(greenred, 0, greenred.length, outCol.vector[1], outCol.start[1], outCol.length[1]);
    Assert.assertEquals(0, cmp2);
    int cmp3 = StringExpr.compare(red, 0, red.length, outCol.vector[2], outCol.start[2], outCol.length[2]);
    Assert.assertEquals(0, cmp3);
    Assert.assertTrue(outCol.noNulls);
    Assert.assertFalse(outCol.isRepeating);
    // has nulls, is repeating
    batch = makeStringBatch();
    batch.cols[0].isRepeating = true;
    expr.evaluate(batch);
    outCol = (BytesColumnVector) batch.cols[1];
    cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]);
    Assert.assertEquals(0, cmp);
    Assert.assertTrue(outCol.isRepeating);
    Assert.assertFalse(outCol.noNulls);
    // no nulls, is repeating
    batch = makeStringBatch();
    batch.cols[0].isRepeating = true;
    batch.cols[0].noNulls = true;
    expr.evaluate(batch);
    outCol = (BytesColumnVector) batch.cols[1];
    cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]);
    Assert.assertEquals(0, cmp);
    Assert.assertTrue(outCol.isRepeating);
    Assert.assertTrue(outCol.noNulls);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) Test(org.junit.Test)

Example 27 with BytesColumnVector

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

the class TestVectorStringExpressions method testRightTrimBytesColumnVector.

@Test
public // Test basic right trim to vector.
void testRightTrimBytesColumnVector() {
    BytesColumnVector outV = new BytesColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
    // initialize with estimated element size 35
    outV.initBuffer(30);
    int i = 0;
    int expectedResultLen;
    // Nothing to trim (ASCII).
    Assert.assertTrue(StringExpr.characterCount(blue, 0, blue.length) == 4);
    StringExpr.rightTrim(outV, i, blue, 0, blue.length);
    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.rightTrim(outV, i, redgreen, 0, redgreen.length);
    expectedResultLen = redgreen.length;
    Assert.assertTrue(vectorEqual(outV, i, redgreen, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(ascii_sentence, 0, ascii_sentence.length) == 31);
    StringExpr.rightTrim(outV, i, ascii_sentence, 0, ascii_sentence.length);
    expectedResultLen = ascii_sentence.length;
    Assert.assertTrue(vectorEqual(outV, i, ascii_sentence, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksLeft, 0, blanksLeft.length) == 5);
    StringExpr.rightTrim(outV, i, blanksLeft, 0, blanksLeft.length);
    expectedResultLen = blanksLeft.length;
    Assert.assertTrue(vectorEqual(outV, i, blanksLeft, 0, expectedResultLen));
    i++;
    // Simple trims.
    Assert.assertTrue(StringExpr.characterCount(blanksRight, 0, blanksRight.length) == 5);
    StringExpr.rightTrim(outV, i, blanksRight, 0, blanksRight.length);
    expectedResultLen = 3;
    Assert.assertTrue(vectorEqual(outV, i, blanksRight, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 3);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksBoth, 0, blanksBoth.length) == 7);
    StringExpr.rightTrim(outV, i, blanksBoth, 0, blanksBoth.length);
    expectedResultLen = 5;
    Assert.assertTrue(vectorEqual(outV, i, blanksBoth, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 5);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankString, 0, blankString.length) == 2);
    StringExpr.rightTrim(outV, i, blankString, 0, blankString.length);
    expectedResultLen = 0;
    Assert.assertTrue(vectorEqual(outV, i, blankString, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 0);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankRanges, 0, blankRanges.length) == 30);
    StringExpr.rightTrim(outV, i, blankRanges, 0, blankRanges.length);
    expectedResultLen = blankRanges.length - 4;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 26);
    i++;
    // Offset trims.
    Assert.assertTrue(StringExpr.characterCount(blanksRight, 1, blanksRight.length - 1) == 4);
    StringExpr.rightTrim(outV, i, blanksRight, 1, blanksRight.length - 1);
    expectedResultLen = 2;
    Assert.assertTrue(vectorEqual(outV, i, blanksRight, 1, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 2);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksBoth, 4, blanksBoth.length - 4) == 3);
    StringExpr.rightTrim(outV, i, blanksBoth, 4, blanksBoth.length - 4);
    expectedResultLen = 1;
    Assert.assertTrue(vectorEqual(outV, i, blanksBoth, 4, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 1);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksBoth, 5, blanksBoth.length - 5) == 2);
    StringExpr.rightTrim(outV, i, blanksBoth, 5, blanksBoth.length - 5);
    expectedResultLen = 0;
    Assert.assertTrue(vectorEqual(outV, i, blanksBoth, 5, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 0);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankString, 1, blankString.length - 1) == 1);
    StringExpr.rightTrim(outV, i, blankString, 1, blankString.length - 1);
    expectedResultLen = 0;
    Assert.assertTrue(vectorEqual(outV, i, blankString, 1, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 0);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankRanges, 4, blankRanges.length - 4) == 26);
    StringExpr.rightTrim(outV, i, blankRanges, 4, blankRanges.length - 4);
    expectedResultLen = blankRanges.length - 4 - 4;
    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.rightTrim(outV, i, blankRanges, 6, blankRanges.length - 6);
    expectedResultLen = blankRanges.length - 6 - 4;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 6, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 20);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankRanges, 7, blankRanges.length - 7) == 23);
    StringExpr.rightTrim(outV, i, blankRanges, 7, blankRanges.length - 7);
    expectedResultLen = blankRanges.length - 7 - 4;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 7, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 19);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankRanges, 7, 8 - 7) == 1);
    StringExpr.rightTrim(outV, i, blankRanges, 7, 8 - 7);
    expectedResultLen = 0;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 7, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 0);
    i++;
    // Multi-byte trims.
    byte[] multiByte = new byte[100];
    addMultiByteCharRightPadded1_1(multiByte);
    Assert.assertTrue(StringExpr.characterCount(multiByte, 0, 4) == 2);
    StringExpr.rightTrim(outV, i, multiByte, 0, 4);
    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.rightTrim(outV, i, multiByte, 0, 5);
    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.rightTrim(outV, i, multiByte, 0, 9);
    expectedResultLen = 8;
    Assert.assertTrue(vectorEqual(outV, i, multiByte, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 3);
    i++;
    addMultiByteCharRightPadded1_1(multiByte);
    Assert.assertTrue(StringExpr.characterCount(multiByte, 3, 1) == 1);
    StringExpr.rightTrim(outV, i, multiByte, 3, 1);
    expectedResultLen = 0;
    Assert.assertTrue(vectorEqual(outV, i, multiByte, 3, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 0);
    i++;
    addMultiByteCharRightPadded1_2(multiByte);
    Assert.assertTrue(StringExpr.characterCount(multiByte, 3, 2) == 2);
    StringExpr.rightTrim(outV, i, multiByte, 3, 2);
    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.rightTrim(outV, i, sentenceOne, 0, sentenceOneLen);
    expectedResultLen = sentenceOneLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOne, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOne, 0, sentenceOneLen - 3) == 9);
    StringExpr.rightTrim(outV, i, sentenceOne, 0, sentenceOneLen - 3);
    expectedResultLen = sentenceOneLen - 3;
    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.rightTrim(outV, i, sentenceTwo, 0, sentenceTwoLen);
    expectedResultLen = sentenceTwoLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwo, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwo, 0, sentenceTwoLen - 5) == 10);
    StringExpr.rightTrim(outV, i, sentenceTwo, 0, sentenceTwoLen - 5);
    expectedResultLen = sentenceTwoLen - 5;
    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.rightTrim(outV, i, sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen);
    expectedResultLen = sentenceOnePaddedLeftLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedLeft, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen - 3) == 3 + 9);
    StringExpr.rightTrim(outV, i, sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen - 3);
    expectedResultLen = sentenceOnePaddedLeftLen - 3;
    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.rightTrim(outV, i, sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen);
    expectedResultLen = sentenceTwoPaddedLeftLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedLeft, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen - 5) == 2 + 10);
    StringExpr.rightTrim(outV, i, sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen - 5);
    expectedResultLen = sentenceTwoPaddedLeftLen - 5;
    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.rightTrim(outV, i, sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen);
    expectedResultLen = sentenceOnePaddedRightLen - 4;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedRight, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen - 3 - 4) == 9);
    StringExpr.rightTrim(outV, i, sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen - 3 - 4);
    expectedResultLen = sentenceOnePaddedRightLen - 3 - 4;
    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.rightTrim(outV, i, sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen);
    expectedResultLen = sentenceTwoPaddedRightLen - 1;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedRight, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen - 5 - 1) == 10);
    StringExpr.rightTrim(outV, i, sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen - 5 - 1);
    expectedResultLen = sentenceTwoPaddedRightLen - 5 - 1;
    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.rightTrim(outV, i, sentenceBlankRanges, 0, sentenceBlankRangesLen);
    expectedResultLen = sentenceBlankRangesLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 0, sentenceBlankRangesLen - 3) == 16);
    StringExpr.rightTrim(outV, i, sentenceBlankRanges, 0, sentenceBlankRangesLen - 3);
    expectedResultLen = sentenceBlankRangesLen - 3;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 7, 17) == 13);
    StringExpr.rightTrim(outV, i, sentenceBlankRanges, 7, 17);
    expectedResultLen = 12;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 7, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 8);
}
Also used : BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) Test(org.junit.Test)

Example 28 with BytesColumnVector

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

the class TestVectorStringExpressions method makeStringBatch.

VectorizedRowBatch makeStringBatch() {
    // create a batch with one string ("Bytes") column
    VectorizedRowBatch batch = new VectorizedRowBatch(3);
    BytesColumnVector v = new BytesColumnVector();
    batch.cols[0] = v;
    // to hold output if needed
    batch.cols[1] = new BytesColumnVector();
    // to hold boolean output
    batch.cols[2] = new LongColumnVector(batch.size);
    /*
     * Add these 3 values:
     *
     * red
     * green
     * NULL
     */
    v.setRef(0, red, 0, red.length);
    v.isNull[0] = false;
    v.setRef(1, green, 0, green.length);
    v.isNull[1] = false;
    v.setRef(2, emptyString, 0, emptyString.length);
    v.isNull[2] = true;
    v.noNulls = false;
    batch.size = 3;
    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 29 with BytesColumnVector

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

the class TestVectorStringExpressions method testColConcatCharScalar.

@Test
public void testColConcatCharScalar() {
    // has nulls, not repeating
    VectorizedRowBatch batch = makeStringBatch();
    StringGroupColConcatCharScalar expr = new StringGroupColConcatCharScalar(0, new HiveChar(new String(red), 6), 1);
    expr.evaluate(batch);
    BytesColumnVector outCol = (BytesColumnVector) batch.cols[1];
    int cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]);
    Assert.assertEquals(0, cmp);
    Assert.assertTrue(outCol.isNull[2]);
    int cmp2 = StringExpr.compare(greenred, 0, greenred.length, outCol.vector[1], outCol.start[1], outCol.length[1]);
    Assert.assertEquals(0, cmp2);
    Assert.assertFalse(outCol.noNulls);
    Assert.assertFalse(outCol.isRepeating);
    // no nulls, not repeating
    batch = makeStringBatch();
    batch.cols[0].noNulls = true;
    expr.evaluate(batch);
    outCol = (BytesColumnVector) batch.cols[1];
    cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]);
    Assert.assertEquals(0, cmp);
    cmp2 = StringExpr.compare(greenred, 0, greenred.length, outCol.vector[1], outCol.start[1], outCol.length[1]);
    Assert.assertEquals(0, cmp2);
    int cmp3 = StringExpr.compare(red, 0, red.length, outCol.vector[2], outCol.start[2], outCol.length[2]);
    Assert.assertEquals(0, cmp3);
    Assert.assertTrue(outCol.noNulls);
    Assert.assertFalse(outCol.isRepeating);
    // has nulls, is repeating
    batch = makeStringBatch();
    batch.cols[0].isRepeating = true;
    expr.evaluate(batch);
    outCol = (BytesColumnVector) batch.cols[1];
    cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]);
    Assert.assertEquals(0, cmp);
    Assert.assertTrue(outCol.isRepeating);
    Assert.assertFalse(outCol.noNulls);
    // no nulls, is repeating
    batch = makeStringBatch();
    batch.cols[0].isRepeating = true;
    batch.cols[0].noNulls = true;
    expr.evaluate(batch);
    outCol = (BytesColumnVector) batch.cols[1];
    cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]);
    Assert.assertEquals(0, cmp);
    Assert.assertTrue(outCol.isRepeating);
    Assert.assertTrue(outCol.noNulls);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) HiveChar(org.apache.hadoop.hive.common.type.HiveChar) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) Test(org.junit.Test)

Example 30 with BytesColumnVector

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

the class TestVectorStringExpressions method testVectorRTrim.

@Test
public void testVectorRTrim() {
    VectorizedRowBatch b = makeTrimBatch();
    VectorExpression expr = new StringRTrim(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, 0, 5, outV.vector[1], outV.start[1], outV.length[1]));
    Assert.assertEquals(0, StringExpr.compare(blanksRight, 0, 3, outV.vector[2], outV.start[2], outV.length[2]));
    Assert.assertEquals(0, StringExpr.compare(blanksBoth, 0, 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)

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