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));
}
Aggregations