@Test
  // Test basic right trim to vector.
  public void testRightTrimBytesColumnVector()  {
      BytesColumnVector outV = new BytesColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
      outV.initBuffer(30); // initialize with estimated element size 35

      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);
  }
Test vectorized expression and filter evaluation for strings.
ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorStringExpressions.java