@Test
  public void testStringColCompareStringColProjection() throws HiveException {
    VectorizedRowBatch batch;
    VectorExpression expr;
    long [] outVector;

    /* input data
     *
     * col0       col1
     * ===============
     * blue       red
     * green      green
     * red        blue
     * NULL       red            col0 data is empty string if we un-set NULL property
     */

    // nulls possible on left, right
    batch = makeStringBatchForColColCompare();
    expr = new StringGroupColLessStringGroupColumn(0, 1, 3);
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);
    Assert.assertFalse(batch.cols[3].isNull[1]);
    Assert.assertEquals(0, outVector[1]);
    Assert.assertFalse(batch.cols[3].isNull[2]);
    Assert.assertEquals(0, outVector[2]);
    Assert.assertTrue(batch.cols[3].isNull[3]);

    // no nulls possible
    batch = makeStringBatchForColColCompare();
    batch.cols[0].noNulls = true;
    batch.cols[1].noNulls = true;
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertTrue(batch.cols[3].noNulls);
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);
    Assert.assertFalse(batch.cols[3].isNull[1]);
    Assert.assertEquals(0, outVector[1]);
    Assert.assertFalse(batch.cols[3].isNull[2]);
    Assert.assertEquals(0, outVector[2]);
    Assert.assertFalse(batch.cols[3].isNull[3]);
    Assert.assertEquals(1, outVector[3]);

    // nulls on left, no nulls on right
    batch = makeStringBatchForColColCompare();
    batch.cols[1].noNulls = true;
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);
    Assert.assertFalse(batch.cols[3].isNull[1]);
    Assert.assertEquals(0, outVector[1]);
    Assert.assertFalse(batch.cols[3].isNull[2]);
    Assert.assertEquals(0, outVector[2]);
    Assert.assertTrue(batch.cols[3].isNull[3]);

    // nulls on right, no nulls on left
    batch = makeStringBatchForColColCompare();
    batch.cols[0].noNulls = true;
    batch.cols[1].isNull[3] = true;
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);
    Assert.assertFalse(batch.cols[3].isNull[1]);
    Assert.assertEquals(0, outVector[1]);
    Assert.assertFalse(batch.cols[3].isNull[2]);
    Assert.assertEquals(0, outVector[2]);
    Assert.assertTrue(batch.cols[3].isNull[3]);

    // Now vary isRepeating
    // nulls possible on left, right

    // left repeats
    batch = makeStringBatchForColColCompare();
    batch.cols[0].isRepeating = true;
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);
    Assert.assertFalse(batch.cols[3].isNull[1]);
    Assert.assertEquals(1, outVector[1]);
    Assert.assertFalse(batch.cols[3].isNull[2]);
    Assert.assertEquals(0, outVector[2]);
    Assert.assertFalse(batch.cols[3].isNull[3]);
    Assert.assertEquals(1, outVector[3]);


    // right repeats
    batch = makeStringBatchForColColCompare();
    batch.cols[1].isRepeating = true;
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertFalse(batch.cols[3].noNulls);
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);
    Assert.assertFalse(batch.cols[3].isNull[1]);
    Assert.assertEquals(1, outVector[1]);
    Assert.assertFalse(batch.cols[3].isNull[2]);
    Assert.assertEquals(0, outVector[2]);
    Assert.assertTrue(batch.cols[3].isNull[3]);

    // left and right repeat
    batch = makeStringBatchForColColCompare();
    batch.cols[0].isRepeating = true;
    batch.cols[1].isRepeating = true;
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertTrue(batch.cols[3].isRepeating);
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);

    // Now vary isRepeating
    // nulls possible only on left

    // left repeats
    batch = makeStringBatchForColColCompare();
    batch.cols[0].isRepeating = true;
    batch.cols[1].noNulls = true;
    expr.evaluate(batch);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertEquals(4, batch.size);
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);
    Assert.assertFalse(batch.cols[3].isNull[1]);
    Assert.assertEquals(1, outVector[1]);
    Assert.assertFalse(batch.cols[3].isNull[2]);
    Assert.assertEquals(0, outVector[2]);
    Assert.assertFalse(batch.cols[3].isNull[3]);
    Assert.assertEquals(1, outVector[3]);

    // left repeats and is null
    batch = makeStringBatchForColColCompare();
    batch.cols[0].isRepeating = true;
    batch.cols[1].noNulls = true;
    batch.cols[0].isNull[0] = true;
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    Assert.assertFalse(batch.cols[3].noNulls);
    Assert.assertTrue(batch.cols[3].isRepeating);
    Assert.assertTrue(batch.cols[3].isNull[0]);

    // right repeats
    batch = makeStringBatchForColColCompare();
    batch.cols[1].isRepeating = true;
    batch.cols[1].noNulls = true;
    expr.evaluate(batch);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertEquals(4, batch.size);
    Assert.assertFalse(batch.cols[3].noNulls);
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);
    Assert.assertFalse(batch.cols[3].isNull[1]);
    Assert.assertEquals(1, outVector[1]);
    Assert.assertFalse(batch.cols[3].isNull[2]);
    Assert.assertEquals(0, outVector[2]);
    Assert.assertTrue(batch.cols[3].isNull[3]);

    // left and right repeat
    batch = makeStringBatchForColColCompare();
    batch.cols[0].isRepeating = true;
    batch.cols[1].isRepeating = true;
    batch.cols[1].noNulls = true;
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertTrue(batch.cols[3].isRepeating);
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);



    // Now vary isRepeating
    // nulls possible only on right

    // left repeats
    batch = makeStringBatchForColColCompare();
    batch.cols[0].isRepeating = true;
    batch.cols[0].noNulls = true;
    batch.cols[1].isNull[0] = true;
    expr.evaluate(batch);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertEquals(4, batch.size);
    Assert.assertFalse(batch.cols[3].noNulls);
    Assert.assertTrue(batch.cols[3].isNull[0]);
    Assert.assertFalse(batch.cols[3].isNull[1]);
    Assert.assertEquals(1, outVector[1]);
    Assert.assertFalse(batch.cols[3].isNull[2]);
    Assert.assertEquals(0, outVector[2]);
    Assert.assertFalse(batch.cols[3].isNull[3]);
    Assert.assertEquals(1, outVector[3]);

    // right repeats
    batch = makeStringBatchForColColCompare();
    batch.cols[1].isRepeating = true;
    batch.cols[0].noNulls = true;
    expr.evaluate(batch);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertEquals(4, batch.size);
    Assert.assertFalse(batch.cols[3].noNulls);
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);
    Assert.assertFalse(batch.cols[3].isNull[1]);
    Assert.assertEquals(1, outVector[1]);
    Assert.assertFalse(batch.cols[3].isNull[2]);
    Assert.assertEquals(0, outVector[2]);
    Assert.assertFalse(batch.cols[3].isNull[3]);
    Assert.assertEquals(1, outVector[3]);

    // right repeats and is null
    batch = makeStringBatchForColColCompare();
    batch.cols[1].isRepeating = true;
    batch.cols[0].noNulls = true;
    batch.cols[1].isNull[0] = true;
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    Assert.assertFalse(batch.cols[3].noNulls);
    Assert.assertTrue(batch.cols[3].isRepeating);
    Assert.assertTrue(batch.cols[3].isNull[0]);

    // left and right repeat
    batch = makeStringBatchForColColCompare();
    batch.cols[0].isRepeating = true;
    batch.cols[1].isRepeating = true;
    batch.cols[0].noNulls = true;
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    outVector = ((LongColumnVector) batch.cols[3]).vector;
    Assert.assertTrue(batch.cols[3].isRepeating);
    Assert.assertFalse(batch.cols[3].isNull[0]);
    Assert.assertEquals(1, outVector[0]);

    // left and right repeat and right is null
    batch = makeStringBatchForColColCompare();
    batch.cols[0].isRepeating = true;
    batch.cols[1].isRepeating = true;
    batch.cols[0].noNulls = true;
    batch.cols[1].isNull[0] = true;
    expr.evaluate(batch);
    Assert.assertEquals(4, batch.size);
    Assert.assertFalse(batch.cols[3].noNulls);
    Assert.assertTrue(batch.cols[3].isRepeating);
    Assert.assertTrue(batch.cols[3].isNull[0]);
  }
Test vectorized expression and filter evaluation for strings.
ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorStringExpressions.java