Search in sources :

Example 1 with UDFLike

use of org.apache.hadoop.hive.ql.udf.UDFLike in project hive by apache.

the class TestVectorStringExpressions method testStringLikeRandomized.

@Test
public void testStringLikeRandomized() throws HiveException, UnsupportedEncodingException {
    final String[] patterns = new String[] { "ABC%", "%ABC", "%ABC%", "ABC%DEF", "ABC%DEF%", "%ABC%DEF", "%ABC%DEF%", "ABC%DEF%EFG", "%ABC%DEF%EFG", "%ABC%DEF%EFG%H" };
    long positive = 0;
    long negative = 0;
    Random control = new Random(1234);
    UDFLike udf = new UDFLike();
    for (String pattern : patterns) {
        VectorExpression expr = new FilterStringColLikeStringScalar(0, pattern.getBytes("utf-8"));
        VectorizedRowBatch batch = VectorizedRowGroupGenUtil.getVectorizedRowBatch(1, 1, 1);
        batch.cols[0] = new BytesColumnVector(1);
        BytesColumnVector bcv = (BytesColumnVector) batch.cols[0];
        Text pText = new Text(pattern);
        for (int i = 0; i < 1024; i++) {
            String input = generateCandidate(control, pattern);
            BooleanWritable like = udf.evaluate(new Text(input), pText);
            batch.reset();
            bcv.initBuffer();
            byte[] utf8 = input.getBytes("utf-8");
            bcv.setVal(0, utf8, 0, utf8.length);
            bcv.noNulls = true;
            batch.size = 1;
            expr.evaluate(batch);
            if (like.get()) {
                positive++;
            } else {
                negative++;
            }
            assertEquals(String.format("Checking '%s' against '%s'", input, pattern), like.get(), (batch.size != 0));
        }
    }
    LOG.info(String.format("Randomized testing: ran %d positive tests and %d negative tests", positive, negative));
}
Also used : Text(org.apache.hadoop.io.Text) VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) Random(java.util.Random) BooleanWritable(org.apache.hadoop.io.BooleanWritable) UDFLike(org.apache.hadoop.hive.ql.udf.UDFLike) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) Test(org.junit.Test)

Aggregations

Random (java.util.Random)1 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)1 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)1 UDFLike (org.apache.hadoop.hive.ql.udf.UDFLike)1 BooleanWritable (org.apache.hadoop.io.BooleanWritable)1 Text (org.apache.hadoop.io.Text)1 Test (org.junit.Test)1