Search in sources :

Example 31 with BytesColumnVector

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

the class TestVectorStringExpressions method testRightTrimAndTruncateBytesColumnVector.

@Test
public // Test basic right trim and truncate to vector.
void testRightTrimAndTruncateBytesColumnVector() {
    BytesColumnVector outV = new BytesColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
    // initialize with estimated element size 35
    outV.initBuffer(35);
    int i = 0;
    // This first section repeats the tests of testRightTrimWithOffset with a large maxLength parameter.
    // (i.e. too large to have an effect).
    int largeMaxLength = 100;
    int expectedResultLen;
    // Nothing to trim (ASCII).
    Assert.assertTrue(StringExpr.characterCount(blue, 0, blue.length) == 4);
    StringExpr.rightTrimAndTruncate(outV, i, blue, 0, blue.length, largeMaxLength);
    expectedResultLen = blue.length;
    Assert.assertTrue(vectorEqual(outV, i, blue, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(redgreen, 0, redgreen.length) == 8);
    StringExpr.rightTrimAndTruncate(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.rightTrimAndTruncate(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.rightTrimAndTruncate(outV, i, blanksLeft, 0, blanksLeft.length, largeMaxLength);
    expectedResultLen = blanksLeft.length;
    Assert.assertTrue(vectorEqual(outV, i, blanksLeft, 0, expectedResultLen));
    i++;
    // Simple trims.
    Assert.assertTrue(StringExpr.characterCount(blanksRight, 0, blanksRight.length) == 5);
    StringExpr.rightTrimAndTruncate(outV, i, blanksRight, 0, blanksRight.length, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, blanksBoth, 0, blanksBoth.length, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, blankString, 0, blankString.length, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, blankRanges, 0, blankRanges.length, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, blanksRight, 1, blanksRight.length - 1, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, blanksBoth, 4, blanksBoth.length - 4, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, blanksBoth, 5, blanksBoth.length - 5, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, blankString, 1, blankString.length - 1, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, blankRanges, 4, blankRanges.length - 4, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, blankRanges, 6, blankRanges.length - 6, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, blankRanges, 7, blankRanges.length - 7, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, blankRanges, 7, 8 - 7, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, multiByte, 0, 4, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, multiByte, 0, 5, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, multiByte, 0, 9, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, multiByte, 3, 1, largeMaxLength);
    expectedResultLen = 0;
    Assert.assertTrue(vectorEqual(outV, i, multiByte, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 0);
    i++;
    addMultiByteCharRightPadded1_2(multiByte);
    Assert.assertTrue(StringExpr.characterCount(multiByte, 3, 2) == 2);
    StringExpr.rightTrimAndTruncate(outV, i, multiByte, 3, 2, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, sentenceOne, 0, sentenceOneLen, largeMaxLength);
    expectedResultLen = sentenceOneLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOne, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOne, 0, sentenceOneLen - 3) == 9);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOne, 0, sentenceOneLen - 3, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, sentenceTwo, 0, sentenceTwoLen, largeMaxLength);
    expectedResultLen = sentenceTwoLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwo, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwo, 0, sentenceTwoLen - 5) == 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwo, 0, sentenceTwoLen - 5, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen, largeMaxLength);
    expectedResultLen = sentenceOnePaddedLeftLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedLeft, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen - 3) == 3 + 9);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen - 3, largeMaxLength);
    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);
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen) == 2 + 13);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen, largeMaxLength);
    expectedResultLen = sentenceTwoPaddedLeftLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedLeft, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen - 5) == 2 + 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen - 5, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen, largeMaxLength);
    expectedResultLen = sentenceOnePaddedRightLen - 4;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedRight, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen - 3 - 4) == 9);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen - 3 - 4, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen, largeMaxLength);
    expectedResultLen = sentenceTwoPaddedRightLen - 1;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedRight, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen - 5 - 1) == 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen - 5 - 1, largeMaxLength);
    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.rightTrimAndTruncate(outV, i, sentenceBlankRanges, 0, sentenceBlankRangesLen, largeMaxLength);
    expectedResultLen = sentenceBlankRangesLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 0, sentenceBlankRangesLen - 3) == 16);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceBlankRanges, 0, sentenceBlankRangesLen - 3, largeMaxLength);
    expectedResultLen = sentenceBlankRangesLen - 3;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 7, 17) == 13);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceBlankRanges, 7, 17, largeMaxLength);
    expectedResultLen = 12;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 7, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 8);
    i++;
    // This next section repeats the tests of testRightTrimWithOffset with a maxLength parameter that is
    // exactly the number of current characters in the string.  This shouldn't affect the trim.
    // Nothing to trim (ASCII).
    Assert.assertTrue(StringExpr.characterCount(blue, 0, blue.length) == 4);
    StringExpr.rightTrimAndTruncate(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.rightTrimAndTruncate(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.rightTrimAndTruncate(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.rightTrimAndTruncate(outV, i, blanksLeft, 0, blanksLeft.length, 5);
    expectedResultLen = blanksLeft.length;
    Assert.assertTrue(vectorEqual(outV, i, blanksLeft, 0, expectedResultLen));
    i++;
    // Simple trims.
    Assert.assertTrue(StringExpr.characterCount(blanksRight, 0, blanksRight.length) == 5);
    StringExpr.rightTrimAndTruncate(outV, i, blanksRight, 0, blanksRight.length, 5);
    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.rightTrimAndTruncate(outV, i, blanksBoth, 0, blanksBoth.length, 7);
    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.rightTrimAndTruncate(outV, i, blankString, 0, blankString.length, 2);
    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.rightTrimAndTruncate(outV, i, blankRanges, 0, blankRanges.length, 30);
    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.rightTrimAndTruncate(outV, i, blanksRight, 1, blanksRight.length - 1, 4);
    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.rightTrimAndTruncate(outV, i, blanksBoth, 4, blanksBoth.length - 4, 3);
    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.rightTrimAndTruncate(outV, i, blanksBoth, 5, blanksBoth.length - 5, 2);
    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.rightTrimAndTruncate(outV, i, blankString, 1, blankString.length - 1, 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.rightTrimAndTruncate(outV, i, blankRanges, 4, blankRanges.length - 4, 26);
    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.rightTrimAndTruncate(outV, i, blankRanges, 6, blankRanges.length - 6, 24);
    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.rightTrimAndTruncate(outV, i, blankRanges, 7, blankRanges.length - 7, 23);
    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.rightTrimAndTruncate(outV, i, blankRanges, 7, 8 - 7, 1);
    expectedResultLen = 0;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 7, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 0);
    i++;
    // Multi-byte trims.
    multiByte = new byte[100];
    addMultiByteCharRightPadded1_1(multiByte);
    Assert.assertTrue(StringExpr.characterCount(multiByte, 0, 4) == 2);
    StringExpr.rightTrimAndTruncate(outV, i, multiByte, 0, 4, 2);
    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.rightTrimAndTruncate(outV, i, multiByte, 0, 5, 3);
    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.rightTrimAndTruncate(outV, i, multiByte, 0, 9, 4);
    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.rightTrimAndTruncate(outV, i, multiByte, 3, 1, 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.rightTrimAndTruncate(outV, i, multiByte, 3, 2, 2);
    expectedResultLen = 1;
    Assert.assertTrue(vectorEqual(outV, i, multiByte, 3, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 1);
    i++;
    sentenceOne = new byte[100];
    sentenceOneLen = addMultiByteCharSentenceOne(sentenceOne, 0);
    Assert.assertTrue(StringExpr.characterCount(sentenceOne, 0, sentenceOneLen) == 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOne, 0, sentenceOneLen, 10);
    expectedResultLen = sentenceOneLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOne, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOne, 0, sentenceOneLen - 3) == 9);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOne, 0, sentenceOneLen - 3, 9);
    expectedResultLen = sentenceOneLen - 3;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOne, 0, expectedResultLen));
    i++;
    sentenceTwo = new byte[100];
    sentenceTwoLen = addMultiByteCharSentenceTwo(sentenceTwo, 0);
    Assert.assertTrue(StringExpr.characterCount(sentenceTwo, 0, sentenceTwoLen) == 13);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwo, 0, sentenceTwoLen, 13);
    expectedResultLen = sentenceTwoLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwo, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwo, 0, sentenceTwoLen - 5) == 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwo, 0, sentenceTwoLen - 5, 10);
    expectedResultLen = sentenceTwoLen - 5;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwo, 0, expectedResultLen));
    i++;
    // Left pad longer strings with multi-byte characters.
    sentenceOnePaddedLeft = new byte[100];
    start = addPads(sentenceOnePaddedLeft, 0, 3);
    sentenceOnePaddedLeftLen = addMultiByteCharSentenceOne(sentenceOnePaddedLeft, start);
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen) == 3 + 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen, 3 + 10);
    expectedResultLen = sentenceOnePaddedLeftLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedLeft, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen - 3) == 3 + 9);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen - 3, 3 + 9);
    expectedResultLen = sentenceOnePaddedLeftLen - 3;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedLeft, 0, expectedResultLen));
    i++;
    sentenceTwoPaddedLeft = new byte[100];
    start = addPads(sentenceTwoPaddedLeft, 0, 2);
    sentenceTwoPaddedLeftLen = addMultiByteCharSentenceTwo(sentenceTwoPaddedLeft, start);
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen) == 2 + 13);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen, 2 + 13);
    expectedResultLen = sentenceTwoPaddedLeftLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedLeft, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen - 5) == 2 + 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen - 5, 2 + 10);
    expectedResultLen = sentenceTwoPaddedLeftLen - 5;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedLeft, 0, expectedResultLen));
    i++;
    // Right pad longer strings with multi-byte characters.
    sentenceOnePaddedRight = new byte[100];
    start = addMultiByteCharSentenceOne(sentenceOnePaddedRight, 0);
    sentenceOnePaddedRightLen = addPads(sentenceOnePaddedRight, start, 4);
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen) == 10 + 4);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen, 10 + 4);
    expectedResultLen = sentenceOnePaddedRightLen - 4;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedRight, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen - 3 - 4) == 9);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen - 3 - 4, 9);
    expectedResultLen = sentenceOnePaddedRightLen - 3 - 4;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedRight, 0, expectedResultLen));
    i++;
    sentenceTwoPaddedRight = new byte[100];
    start = addMultiByteCharSentenceTwo(sentenceTwoPaddedRight, 0);
    sentenceTwoPaddedRightLen = addPads(sentenceTwoPaddedRight, start, 1);
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen) == 13 + 1);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen, 13 + 1);
    expectedResultLen = sentenceTwoPaddedRightLen - 1;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedRight, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen - 5 - 1) == 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen - 5 - 1, 10);
    expectedResultLen = sentenceTwoPaddedRightLen - 5 - 1;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedRight, 0, expectedResultLen));
    i++;
    // Multi-byte characters with blank ranges.
    sentenceBlankRanges = new byte[100];
    sentenceBlankRangesLen = addMultiByteCharSentenceBlankRanges(sentenceBlankRanges, 0);
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 0, sentenceBlankRangesLen) == 17);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceBlankRanges, 0, sentenceBlankRangesLen, 17);
    expectedResultLen = sentenceBlankRangesLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 0, sentenceBlankRangesLen - 3) == 16);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceBlankRanges, 0, sentenceBlankRangesLen - 3, 16);
    expectedResultLen = sentenceBlankRangesLen - 3;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 7, 17) == 13);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceBlankRanges, 7, 17, largeMaxLength);
    expectedResultLen = 12;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 7, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 8);
    i++;
    // This next section repeats the tests of testRightTrimWithOffset with a maxLength parameter that is
    // less than the number of current characters in the string and thus affects the trim.
    // Nothing to trim (ASCII).
    Assert.assertTrue(StringExpr.characterCount(blue, 0, blue.length) == 4);
    StringExpr.rightTrimAndTruncate(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.rightTrimAndTruncate(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.rightTrimAndTruncate(outV, i, ascii_sentence, 0, ascii_sentence.length, 30);
    expectedResultLen = 30;
    Assert.assertTrue(vectorEqual(outV, i, ascii_sentence, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(blanksLeft, 0, blanksLeft.length) == 5);
    StringExpr.rightTrimAndTruncate(outV, i, blanksLeft, 0, blanksLeft.length, 1);
    expectedResultLen = 0;
    Assert.assertTrue(vectorEqual(outV, i, blanksLeft, 0, expectedResultLen));
    i++;
    // Simple trims.
    Assert.assertTrue(StringExpr.characterCount(blanksRight, 0, blanksRight.length) == 5);
    StringExpr.rightTrimAndTruncate(outV, i, blanksRight, 0, blanksRight.length, 4);
    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.rightTrimAndTruncate(outV, i, blanksBoth, 0, blanksBoth.length, 6);
    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.rightTrimAndTruncate(outV, i, blankString, 0, blankString.length, 1);
    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.rightTrimAndTruncate(outV, i, blankRanges, 0, blankRanges.length, 19);
    expectedResultLen = 15;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 0, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 15);
    i++;
    // Offset trims.
    Assert.assertTrue(StringExpr.characterCount(blanksRight, 1, blanksRight.length - 1) == 4);
    StringExpr.rightTrimAndTruncate(outV, i, blanksRight, 1, blanksRight.length - 1, 3);
    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.rightTrimAndTruncate(outV, i, blanksBoth, 4, blanksBoth.length - 4, 2);
    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.rightTrimAndTruncate(outV, i, blanksBoth, 5, blanksBoth.length - 5, 1);
    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.rightTrimAndTruncate(outV, i, blankString, 1, blankString.length - 1, 1);
    expectedResultLen = 0;
    Assert.assertTrue(vectorEqual(outV, i, blankString, 1, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 0);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankRanges, 3, 6) == 6);
    StringExpr.rightTrimAndTruncate(outV, i, blankRanges, 3, 6, 5);
    expectedResultLen = 4;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 3, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 4);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankRanges, 6, blankRanges.length - 6) == 24);
    StringExpr.rightTrimAndTruncate(outV, i, blankRanges, 6, blankRanges.length - 6, 22);
    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.rightTrimAndTruncate(outV, i, blankRanges, 7, blankRanges.length - 7, 10);
    expectedResultLen = 8;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 7, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 8);
    i++;
    Assert.assertTrue(StringExpr.characterCount(blankRanges, 7, 8 - 7) == 1);
    StringExpr.rightTrimAndTruncate(outV, i, blankRanges, 7, 8 - 7, 1);
    expectedResultLen = 0;
    Assert.assertTrue(vectorEqual(outV, i, blankRanges, 7, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 0);
    i++;
    // Multi-byte trims.
    multiByte = new byte[100];
    addMultiByteCharRightPadded1_1(multiByte);
    Assert.assertTrue(StringExpr.characterCount(multiByte, 0, 4) == 2);
    StringExpr.rightTrimAndTruncate(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.rightTrimAndTruncate(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.rightTrimAndTruncate(outV, i, multiByte, 0, 9, 3);
    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.rightTrimAndTruncate(outV, i, multiByte, 3, 1, 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.rightTrimAndTruncate(outV, i, multiByte, 3, 2, 1);
    expectedResultLen = 1;
    Assert.assertTrue(vectorEqual(outV, i, multiByte, 3, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 1);
    i++;
    sentenceOne = new byte[100];
    sentenceOneLen = addMultiByteCharSentenceOne(sentenceOne, 0);
    Assert.assertTrue(StringExpr.characterCount(sentenceOne, 0, sentenceOneLen) == 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOne, 0, sentenceOneLen, 7);
    expectedResultLen = sentenceOneLen - 9;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOne, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOne, 0, sentenceOneLen - 3) == 9);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOne, 0, sentenceOneLen - 3, 6);
    expectedResultLen = 13;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOne, 0, expectedResultLen));
    i++;
    sentenceTwo = new byte[100];
    sentenceTwoLen = addMultiByteCharSentenceTwo(sentenceTwo, 0);
    Assert.assertTrue(StringExpr.characterCount(sentenceTwo, 0, sentenceTwoLen) == 13);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwo, 0, sentenceTwoLen, 13);
    expectedResultLen = sentenceTwoLen;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwo, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwo, 0, sentenceTwoLen - 5) == 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwo, 0, sentenceTwoLen - 5, 10);
    expectedResultLen = sentenceTwoLen - 5;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwo, 0, expectedResultLen));
    i++;
    // Left pad longer strings with multi-byte characters.
    sentenceOnePaddedLeft = new byte[100];
    start = addPads(sentenceOnePaddedLeft, 0, 3);
    sentenceOnePaddedLeftLen = addMultiByteCharSentenceOne(sentenceOnePaddedLeft, start);
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen) == 3 + 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen, 3 + 8);
    expectedResultLen = sentenceOnePaddedLeftLen - 6;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedLeft, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen - 3) == 3 + 9);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOnePaddedLeft, 0, sentenceOnePaddedLeftLen - 3, 3 + 6);
    expectedResultLen = 16;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedLeft, 0, expectedResultLen));
    i++;
    sentenceTwoPaddedLeft = new byte[100];
    start = addPads(sentenceTwoPaddedLeft, 0, 2);
    sentenceTwoPaddedLeftLen = addMultiByteCharSentenceTwo(sentenceTwoPaddedLeft, start);
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen) == 2 + 13);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen, 7);
    expectedResultLen = 10;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedLeft, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen - 5) == 2 + 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwoPaddedLeft, 0, sentenceTwoPaddedLeftLen - 5, 6);
    expectedResultLen = 10;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedLeft, 0, expectedResultLen));
    i++;
    // Right pad longer strings with multi-byte characters.
    sentenceOnePaddedRight = new byte[100];
    start = addMultiByteCharSentenceOne(sentenceOnePaddedRight, 0);
    sentenceOnePaddedRightLen = addPads(sentenceOnePaddedRight, start, 4);
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen) == 10 + 4);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen, 10);
    expectedResultLen = sentenceOnePaddedRightLen - 4;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedRight, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen - 3 - 4) == 9);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceOnePaddedRight, 0, sentenceOnePaddedRightLen - 3 - 4, 7);
    expectedResultLen = 17;
    Assert.assertTrue(vectorEqual(outV, i, sentenceOnePaddedRight, 0, expectedResultLen));
    i++;
    sentenceTwoPaddedRight = new byte[100];
    start = addMultiByteCharSentenceTwo(sentenceTwoPaddedRight, 0);
    sentenceTwoPaddedRightLen = addPads(sentenceTwoPaddedRight, start, 1);
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen) == 13 + 1);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen, 13);
    expectedResultLen = sentenceTwoPaddedRightLen - 1;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedRight, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen - 5 - 1) == 10);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceTwoPaddedRight, 0, sentenceTwoPaddedRightLen - 5 - 1, 4);
    expectedResultLen = 8;
    Assert.assertTrue(vectorEqual(outV, i, sentenceTwoPaddedRight, 0, expectedResultLen));
    i++;
    // Multi-byte characters with blank ranges.
    sentenceBlankRanges = new byte[100];
    sentenceBlankRangesLen = addMultiByteCharSentenceBlankRanges(sentenceBlankRanges, 0);
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 0, sentenceBlankRangesLen) == 17);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceBlankRanges, 0, sentenceBlankRangesLen, 4);
    expectedResultLen = 7;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 0, sentenceBlankRangesLen - 3) == 16);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceBlankRanges, 0, sentenceBlankRangesLen - 3, 6);
    expectedResultLen = 11;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 0, expectedResultLen));
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 4, 12) == 8);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceBlankRanges, 4, 12, 6);
    expectedResultLen = 7;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 4, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 5);
    i++;
    Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 7, 17) == 13);
    StringExpr.rightTrimAndTruncate(outV, i, sentenceBlankRanges, 7, 17, 11);
    expectedResultLen = 12;
    Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 7, expectedResultLen));
    Assert.assertTrue(vectorCharacterCount(outV, i) == 8);
    i++;
}
Also used : BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) Test(org.junit.Test)

Example 32 with BytesColumnVector

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

the class TestVectorTimestampExpressions method getVectorizedRowBatchStringLong.

private VectorizedRowBatch getVectorizedRowBatchStringLong(byte[] vector, int start, int length) {
    VectorizedRowBatch batch = new VectorizedRowBatch(2, 1);
    BytesColumnVector bcv = new BytesColumnVector(1);
    bcv.vector[0] = vector;
    bcv.start[0] = start;
    bcv.length[0] = length;
    batch.cols[0] = bcv;
    batch.cols[1] = new LongColumnVector(1);
    batch.size = 1;
    return batch;
}
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)

Example 33 with BytesColumnVector

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

the class TestVectorTypeCasts method getBatchDecimalString.

private VectorizedRowBatch getBatchDecimalString() {
    VectorizedRowBatch b = new VectorizedRowBatch(2);
    DecimalColumnVector dv;
    short scale = 2;
    b.cols[0] = dv = new DecimalColumnVector(18, scale);
    b.cols[1] = new BytesColumnVector();
    b.size = 3;
    dv.vector[0].set(HiveDecimal.create("1.1"));
    dv.vector[1].set(HiveDecimal.create("-2.2"));
    dv.vector[2].set(HiveDecimal.create("9999999999999999.00"));
    return b;
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)

Example 34 with BytesColumnVector

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

the class TestVectorizedORCReader method checkVectorizedReader.

private void checkVectorizedReader() throws Exception {
    Reader vreader = OrcFile.createReader(testFilePath, OrcFile.readerOptions(conf));
    Reader reader = OrcFile.createReader(testFilePath, OrcFile.readerOptions(conf));
    RecordReaderImpl vrr = (RecordReaderImpl) vreader.rows();
    RecordReaderImpl rr = (RecordReaderImpl) reader.rows();
    VectorizedRowBatch batch = reader.getSchema().createRowBatch();
    OrcStruct row = null;
    // Check Vectorized ORC reader against ORC row reader
    while (vrr.nextBatch(batch)) {
        for (int i = 0; i < batch.size; i++) {
            row = (OrcStruct) rr.next(row);
            for (int j = 0; j < batch.cols.length; j++) {
                Object a = (row.getFieldValue(j));
                ColumnVector cv = batch.cols[j];
                // if the value is repeating, use row 0
                int rowId = cv.isRepeating ? 0 : i;
                // make sure the null flag agrees
                if (a == null) {
                    Assert.assertEquals(true, !cv.noNulls && cv.isNull[rowId]);
                } else if (a instanceof BooleanWritable) {
                    // Boolean values are stores a 1's and 0's, so convert and compare
                    Long temp = (long) (((BooleanWritable) a).get() ? 1 : 0);
                    long b = ((LongColumnVector) cv).vector[rowId];
                    Assert.assertEquals(temp.toString(), Long.toString(b));
                } else if (a instanceof TimestampWritable) {
                    // Timestamps are stored as long, so convert and compare
                    TimestampWritable t = ((TimestampWritable) a);
                    TimestampColumnVector tcv = ((TimestampColumnVector) cv);
                    Assert.assertEquals(t.getTimestamp(), tcv.asScratchTimestamp(rowId));
                } else if (a instanceof DateWritable) {
                    // Dates are stored as long, so convert and compare
                    DateWritable adt = (DateWritable) a;
                    long b = ((LongColumnVector) cv).vector[rowId];
                    Assert.assertEquals(adt.get().getTime(), DateWritable.daysToMillis((int) b));
                } else if (a instanceof HiveDecimalWritable) {
                    // Decimals are stored as BigInteger, so convert and compare
                    HiveDecimalWritable dec = (HiveDecimalWritable) a;
                    HiveDecimalWritable b = ((DecimalColumnVector) cv).vector[i];
                    Assert.assertEquals(dec, b);
                } else if (a instanceof DoubleWritable) {
                    double b = ((DoubleColumnVector) cv).vector[rowId];
                    assertEquals(a.toString(), Double.toString(b));
                } else if (a instanceof Text) {
                    BytesColumnVector bcv = (BytesColumnVector) cv;
                    Text b = new Text();
                    b.set(bcv.vector[rowId], bcv.start[rowId], bcv.length[rowId]);
                    assertEquals(a, b);
                } else if (a instanceof IntWritable || a instanceof LongWritable || a instanceof ByteWritable || a instanceof ShortWritable) {
                    assertEquals(a.toString(), Long.toString(((LongColumnVector) cv).vector[rowId]));
                } else {
                    assertEquals("huh", a.getClass().getName());
                }
            }
        }
        // Check repeating
        Assert.assertEquals(false, batch.cols[0].isRepeating);
        Assert.assertEquals(false, batch.cols[1].isRepeating);
        Assert.assertEquals(false, batch.cols[2].isRepeating);
        Assert.assertEquals(true, batch.cols[3].isRepeating);
        Assert.assertEquals(false, batch.cols[4].isRepeating);
        Assert.assertEquals(false, batch.cols[5].isRepeating);
        Assert.assertEquals(false, batch.cols[6].isRepeating);
        Assert.assertEquals(false, batch.cols[7].isRepeating);
        Assert.assertEquals(false, batch.cols[8].isRepeating);
        Assert.assertEquals(false, batch.cols[9].isRepeating);
        // Check non null
        Assert.assertEquals(false, batch.cols[0].noNulls);
        Assert.assertEquals(false, batch.cols[1].noNulls);
        Assert.assertEquals(true, batch.cols[2].noNulls);
        Assert.assertEquals(true, batch.cols[3].noNulls);
        Assert.assertEquals(false, batch.cols[4].noNulls);
        Assert.assertEquals(false, batch.cols[5].noNulls);
        Assert.assertEquals(false, batch.cols[6].noNulls);
        Assert.assertEquals(false, batch.cols[7].noNulls);
        Assert.assertEquals(false, batch.cols[8].noNulls);
        Assert.assertEquals(false, batch.cols[9].noNulls);
    }
    Assert.assertEquals(false, rr.nextBatch(batch));
}
Also used : TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Text(org.apache.hadoop.io.Text) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) ColumnVector(org.apache.hadoop.hive.ql.exec.vector.ColumnVector) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) BooleanWritable(org.apache.hadoop.io.BooleanWritable) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongWritable(org.apache.hadoop.io.LongWritable) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) IntWritable(org.apache.hadoop.io.IntWritable)

Example 35 with BytesColumnVector

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

the class VectorizedColumnReaderTestBase method binaryRead.

protected void binaryRead(boolean isDictionaryEncoding) throws Exception {
    Configuration conf = new Configuration();
    conf.set(IOConstants.COLUMNS, "binary_field_some_null");
    conf.set(IOConstants.COLUMNS_TYPES, "string");
    conf.setBoolean(ColumnProjectionUtils.READ_ALL_COLUMNS, false);
    conf.set(ColumnProjectionUtils.READ_COLUMN_IDS_CONF_STR, "0");
    VectorizedParquetRecordReader reader = createParquetReader("message test { required binary binary_field_some_null;}", conf);
    VectorizedRowBatch previous = reader.createValue();
    int c = 0;
    try {
        while (reader.next(NullWritable.get(), previous)) {
            BytesColumnVector vector = (BytesColumnVector) previous.cols[0];
            boolean noNull = true;
            for (int i = 0; i < vector.vector.length; i++) {
                if (c == nElements) {
                    break;
                }
                String actual;
                assertEquals("Null assert failed at " + c, isNull(c), vector.isNull[i]);
                if (!vector.isNull[i]) {
                    actual = new String(ArrayUtils.subarray(vector.vector[i], vector.start[i], vector.start[i] + vector.length[i]));
                    assertEquals("failed at " + c, getStr(isDictionaryEncoding, c), actual);
                } else {
                    noNull = false;
                }
                c++;
            }
            assertEquals("No Null check failed at " + c, noNull, vector.noNulls);
            assertFalse(vector.isRepeating);
        }
        assertEquals("It doesn't exit at expected position", nElements, c);
    } finally {
        reader.close();
    }
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) Configuration(org.apache.hadoop.conf.Configuration) VectorizedParquetRecordReader(org.apache.hadoop.hive.ql.io.parquet.vector.VectorizedParquetRecordReader) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)

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