use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorStringExpressions method testAssignBytesColumnVector.
@Test
public // Test basic assign to vector.
void testAssignBytesColumnVector() {
BytesColumnVector outV = new BytesColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
// initialize with estimated element size 35
outV.initBuffer(35);
int i = 0;
int expectedResultLen;
Assert.assertTrue(StringExpr.characterCount(blue, 0, blue.length) == 4);
StringExpr.assign(outV, i, blue, 0, blue.length);
expectedResultLen = blue.length;
Assert.assertTrue(vectorEqual(outV, i, blue, 0, expectedResultLen));
i++;
Assert.assertTrue(StringExpr.characterCount(redgreen, 0, redgreen.length) == 8);
StringExpr.assign(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.assign(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.assign(outV, i, blanksLeft, 0, blanksLeft.length);
expectedResultLen = blanksLeft.length;
Assert.assertTrue(vectorEqual(outV, i, blanksLeft, 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.assign(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.assign(outV, i, sentenceBlankRanges, 0, sentenceBlankRangesLen - 3);
expectedResultLen = sentenceBlankRangesLen - 3;
Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 0, expectedResultLen));
i++;
// Some non-zero offsets.
Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 4, sentenceBlankRangesLen - 4) == 16);
StringExpr.assign(outV, i, sentenceBlankRanges, 4, sentenceBlankRangesLen - 4);
expectedResultLen = sentenceBlankRangesLen - 4;
Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 4, expectedResultLen));
Assert.assertTrue(vectorCharacterCount(outV, i) == 16);
i++;
Assert.assertTrue(StringExpr.characterCount(sentenceBlankRanges, 7, 17) == 13);
StringExpr.assign(outV, i, sentenceBlankRanges, 7, 17);
expectedResultLen = 17;
Assert.assertTrue(vectorEqual(outV, i, sentenceBlankRanges, 7, expectedResultLen));
Assert.assertTrue(vectorCharacterCount(outV, i) == 13);
i++;
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorStringExpressions method makeTrimBatch.
// Make a batch to test the trim functions.
private VectorizedRowBatch makeTrimBatch() {
VectorizedRowBatch b = new VectorizedRowBatch(2);
BytesColumnVector inV = new BytesColumnVector();
BytesColumnVector outV = new BytesColumnVector();
b.cols[0] = inV;
b.cols[1] = outV;
inV.setRef(0, emptyString, 0, 0);
inV.setRef(1, blanksLeft, 0, blanksLeft.length);
inV.setRef(2, blanksRight, 0, blanksRight.length);
inV.setRef(3, blanksBoth, 0, blanksBoth.length);
inV.setRef(4, red, 0, red.length);
inV.setRef(5, blankString, 0, blankString.length);
b.size = 5;
return b;
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorStringExpressions method testLoadBytesColumnVectorByRef.
@Test
public // set values by reference, copy the data out, and verify equality
void testLoadBytesColumnVectorByRef() {
BytesColumnVector bcv = new BytesColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
String s = "red";
byte[] b = null;
try {
b = s.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
for (int i = 0; i != VectorizedRowBatch.DEFAULT_SIZE; i++) {
bcv.setRef(i, b, 0, b.length);
}
// verify
byte[] v = new byte[b.length];
for (int i = 0; i != VectorizedRowBatch.DEFAULT_SIZE; i++) {
Assert.assertTrue(bcv.length[i] == b.length);
System.arraycopy(bcv.vector[i], bcv.start[i], v, 0, b.length);
Assert.assertTrue(Arrays.equals(b, v));
}
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorStringExpressions method testLoadBytesColumnVectorByValueLargeData.
@Test
public // the buffer to expand.
void testLoadBytesColumnVectorByValueLargeData() {
BytesColumnVector bcv = new BytesColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
// initialize with estimated element size 10
bcv.initBuffer(10);
// Record initial buffer size
int initialBufferSize = bcv.bufferSize();
String s = "0123456789";
while (s.length() < 500) {
s += s;
}
byte[] b = null;
try {
b = s.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
for (int i = 0; i != VectorizedRowBatch.DEFAULT_SIZE; i++) {
bcv.setVal(i, b, 0, b.length);
}
// Current buffer size should be larger than initial size
Assert.assertTrue(bcv.bufferSize() > initialBufferSize);
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorStringExpressions method testStringLikePatternType.
@Test
public void testStringLikePatternType() throws UnsupportedEncodingException, HiveException {
FilterStringColLikeStringScalar expr;
VectorizedRowBatch vrb = VectorizedRowGroupGenUtil.getVectorizedRowBatch(1, 1, 1);
vrb.cols[0] = new BytesColumnVector(1);
BytesColumnVector bcv = (BytesColumnVector) vrb.cols[0];
vrb.size = 0;
// BEGIN pattern
expr = new FilterStringColLikeStringScalar(0, "abc%".getBytes());
expr.evaluate(vrb);
Assert.assertEquals(FilterStringColLikeStringScalar.BeginChecker.class, expr.checker.getClass());
// END pattern
expr = new FilterStringColLikeStringScalar(0, "%abc".getBytes("UTF-8"));
expr.evaluate(vrb);
Assert.assertEquals(FilterStringColLikeStringScalar.EndChecker.class, expr.checker.getClass());
// MIDDLE pattern
expr = new FilterStringColLikeStringScalar(0, "%abc%".getBytes());
expr.evaluate(vrb);
Assert.assertEquals(FilterStringColLikeStringScalar.MiddleChecker.class, expr.checker.getClass());
// CHAIN pattern
expr = new FilterStringColLikeStringScalar(0, "%abc%de".getBytes());
expr.evaluate(vrb);
Assert.assertEquals(FilterStringColLikeStringScalar.ChainedChecker.class, expr.checker.getClass());
// COMPLEX pattern
expr = new FilterStringColLikeStringScalar(0, "%abc_%de".getBytes());
expr.evaluate(vrb);
Assert.assertEquals(FilterStringColLikeStringScalar.ComplexChecker.class, expr.checker.getClass());
// NONE pattern
expr = new FilterStringColLikeStringScalar(0, "abc".getBytes());
expr.evaluate(vrb);
Assert.assertEquals(FilterStringColLikeStringScalar.NoneChecker.class, expr.checker.getClass());
}
Aggregations