public static boolean findMatch(int valueIndex, byte[] valueBytes, List<byte[]> actualValues, int actualCount, boolean[] actualTaken, int[] actualToValueMap) { for (int i = 0; i < actualCount; i++) { if (!actualTaken[i]) { byte[] actualBytes = actualValues.get(i); if (StringExpr.compare(valueBytes, 0, valueBytes.length, actualBytes, 0, actualBytes.length) == 0) { actualToValueMap[i] = valueIndex; actualTaken[i] = true; return true; } } } return false; }
public void minmaxValue(byte[] bytes, int start, int length) { if (isNull) { isNull = false; assign(bytes, start, length); } else if (StringExpr.compare( bytes, start, length, this.bytes, 0, this.length) > 0) { assign(bytes, start, length); } }
public void minmaxValue(byte[] bytes, int start, int length) { if (isNull) { isNull = false; assign(bytes, start, length); } else if (StringExpr.compare( bytes, start, length, this.bytes, 0, this.length) < 0) { assign(bytes, start, length); } }
public void checkValue(byte[] bytes, int start, int length) { if (isNull) { isNull = false; assign(bytes, start, length); } else if (StringExpr.compare( bytes, start, length, this.bytes, 0, this.length) < 0) { assign(bytes, start, length); } }
public void checkValue(byte[] bytes, int start, int length) { if (isNull) { isNull = false; assign(bytes, start, length); } else if (StringExpr.compare( bytes, start, length, this.bytes, 0, this.length) > 0) { assign(bytes, start, length); } }
@Test public void testVectorTrim() throws HiveException { VectorizedRowBatch b = makeTrimBatch(); VectorExpression expr = new StringTrim(0, 1); expr.evaluate(b); BytesColumnVector outV = (BytesColumnVector) b.cols[1]; Assert.assertEquals(0, StringExpr.compare(emptyString, 0, 0, outV.vector[0], 0, 0)); Assert.assertEquals(0, StringExpr.compare(blanksLeft, 2, 3, outV.vector[1], outV.start[1], outV.length[1])); Assert.assertEquals(0, StringExpr.compare(blanksRight, 0, 3, outV.vector[2], outV.start[2], outV.length[2])); Assert.assertEquals(0, StringExpr.compare(blanksBoth, 2, 3, outV.vector[3], outV.start[3], outV.length[3])); Assert.assertEquals(0, StringExpr.compare(red, 0, 3, outV.vector[4], outV.start[4], outV.length[4])); Assert.assertEquals(0, StringExpr.compare(blankString, 0, 0, outV.vector[5], outV.start[5], outV.length[5])); }
@Test public void testVectorLTrim() throws HiveException { VectorizedRowBatch b = makeTrimBatch(); VectorExpression expr = new StringLTrim(0, 1); expr.evaluate(b); BytesColumnVector outV = (BytesColumnVector) b.cols[1]; Assert.assertEquals(0, StringExpr.compare(emptyString, 0, 0, outV.vector[0], 0, 0)); Assert.assertEquals(0, StringExpr.compare(blanksLeft, 2, 3, outV.vector[1], outV.start[1], outV.length[1])); Assert.assertEquals(0, StringExpr.compare(blanksRight, 0, 5, outV.vector[2], outV.start[2], outV.length[2])); Assert.assertEquals(0, StringExpr.compare(blanksBoth, 2, 5, outV.vector[3], outV.start[3], outV.length[3])); Assert.assertEquals(0, StringExpr.compare(red, 0, 3, outV.vector[4], outV.start[4], outV.length[4])); Assert.assertEquals(0, StringExpr.compare(blankString, 0, 0, outV.vector[5], outV.start[5], outV.length[5])); }
@Test public void testVectorRTrim() throws HiveException { VectorizedRowBatch b = makeTrimBatch(); VectorExpression expr = new StringRTrim(0, 1); expr.evaluate(b); BytesColumnVector outV = (BytesColumnVector) b.cols[1]; Assert.assertEquals(0, StringExpr.compare(emptyString, 0, 0, outV.vector[0], 0, 0)); Assert.assertEquals(0, StringExpr.compare(blanksLeft, 0, 5, outV.vector[1], outV.start[1], outV.length[1])); Assert.assertEquals(0, StringExpr.compare(blanksRight, 0, 3, outV.vector[2], outV.start[2], outV.length[2])); Assert.assertEquals(0, StringExpr.compare(blanksBoth, 0, 5, outV.vector[3], outV.start[3], outV.length[3])); Assert.assertEquals(0, StringExpr.compare(red, 0, 3, outV.vector[4], outV.start[4], outV.length[4])); Assert.assertEquals(0, StringExpr.compare(blankString, 0, 0, outV.vector[5], outV.start[5], outV.length[5])); }
int cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); Assert.assertTrue(outCol.isNull[2]); int cmp2 = StringExpr.compare(greenred, 0, greenred.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); cmp2 = StringExpr.compare(greenred, 0, greenred.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); int cmp3 = StringExpr.compare(red, 0, red.length, outCol.vector[2], outCol.start[2], outCol.length[2]); Assert.assertEquals(0, cmp3); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); expr.evaluate(batch);
int cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); Assert.assertTrue(outCol.isNull[2]); int cmp2 = StringExpr.compare(redgreen, 0, redgreen.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); cmp2 = StringExpr.compare(redgreen, 0, redgreen.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); int cmp3 = StringExpr.compare(red, 0, red.length, outCol.vector[2], outCol.start[2], outCol.length[2]); Assert.assertEquals(0, cmp3); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); expr.evaluate(batch);
@Test public void testCastBooleanToString() throws HiveException { byte[] t = toBytes("TRUE"); byte[] f = toBytes("FALSE"); VectorizedRowBatch b = TestVectorMathFunctions.getBatchForStringMath(); LongColumnVector inV = (LongColumnVector) b.cols[1]; BytesColumnVector resultV = (BytesColumnVector) b.cols[2]; inV.vector[1] = 1; VectorExpression expr = new CastBooleanToStringViaLongToString(1, 2); expr.evaluate(b); Assert.assertEquals(0, StringExpr.compare(f, 0, f.length, resultV.vector[0], resultV.start[0], resultV.length[0])); Assert.assertEquals(0, StringExpr.compare(t, 0, t.length, resultV.vector[1], resultV.start[1], resultV.length[1])); }
@Test public void testColUpper() throws HiveException { // no nulls, not repeating /* We don't test all the combinations because (at least currently) * the logic is inherited to be the same as testColLower, which checks all the cases). */ VectorizedRowBatch batch = makeStringBatchMixedCase(); StringUpper expr = new StringUpper(0, 1); batch.cols[0].noNulls = true; expr.evaluate(batch); BytesColumnVector outCol = (BytesColumnVector) batch.cols[1]; int cmp = StringExpr.compare(mixedUpUpper, 0, mixedUpUpper.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); Assert.assertTrue(outCol.noNulls); }
int cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); Assert.assertTrue(outCol.isNull[2]); int cmp2 = StringExpr.compare(greenred, 0, greenred.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); cmp2 = StringExpr.compare(greenred, 0, greenred.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); int cmp3 = StringExpr.compare(red, 0, red.length, outCol.vector[2], outCol.start[2], outCol.length[2]); Assert.assertEquals(0, cmp3); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); expr.evaluate(batch);
int cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); Assert.assertTrue(outCol.isNull[2]); int cmp2 = StringExpr.compare(redgreen, 0, redgreen.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); cmp2 = StringExpr.compare(redgreen, 0, redgreen.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); int cmp3 = StringExpr.compare(red, 0, red.length, outCol.vector[2], outCol.start[2], outCol.length[2]); Assert.assertEquals(0, cmp3); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); expr.evaluate(batch);
expr.evaluate(batch); BytesColumnVector outCol = (BytesColumnVector) batch.cols[1]; int cmp = StringExpr.compare(mixedUpLower, 0, mixedUpLower.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); Assert.assertTrue(outCol.isNull[2]); int cmp2 = StringExpr.compare(green, 0, green.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(mixedUpLower, 0, mixedUpLower.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(mixedUpLower, 0, mixedUpLower.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(mixedUpLower, 0, mixedUpLower.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp);
int cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); Assert.assertTrue(outCol.isNull[2]); int cmp2 = StringExpr.compare(redgreen, 0, redgreen.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); cmp2 = StringExpr.compare(redgreen, 0, redgreen.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); int cmp3 = StringExpr.compare(red, 0, red.length, outCol.vector[2], outCol.start[2], outCol.length[2]); Assert.assertEquals(0, cmp3); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); expr.evaluate(batch);
int cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); Assert.assertTrue(outCol.isNull[2]); int cmp2 = StringExpr.compare(greenred, 0, greenred.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); cmp2 = StringExpr.compare(greenred, 0, greenred.length, outCol.vector[1], outCol.start[1], outCol.length[1]); Assert.assertEquals(0, cmp2); int cmp3 = StringExpr.compare(red, 0, red.length, outCol.vector[2], outCol.start[2], outCol.length[2]); Assert.assertEquals(0, cmp3); expr.evaluate(batch); outCol = (BytesColumnVector) batch.cols[1]; cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0], outCol.start[0], outCol.length[0]); Assert.assertEquals(0, cmp); expr.evaluate(batch);
@Test public void testCastDecimalToString() throws HiveException { VectorizedRowBatch b = getBatchDecimalString(); VectorExpression expr = new CastDecimalToString(0, 1); expr.setInputTypeInfos(new TypeInfo[] {TypeInfoFactory.decimalTypeInfo}); expr.transientInit(); expr.evaluate(b); BytesColumnVector r = (BytesColumnVector) b.cols[1]; // As of HIVE-8745, these decimal values should be trimmed of trailing zeros. byte[] v = toBytes("1.10"); assertTrue(((Integer) v.length).toString() + " " + r.length[0], v.length == r.length[0]); Assert.assertEquals(0, StringExpr.compare(v, 0, v.length, r.vector[0], r.start[0], r.length[0])); v = toBytes("-2.20"); Assert.assertEquals(0, StringExpr.compare(v, 0, v.length, r.vector[1], r.start[1], r.length[1])); v = toBytes("9999999999999999.00"); Assert.assertEquals(0, StringExpr.compare(v, 0, v.length, r.vector[2], r.start[2], r.length[2])); }
@Test public void testCastLongToString() throws HiveException { VectorizedRowBatch b = TestVectorMathFunctions.getBatchForStringMath(); BytesColumnVector resultV = (BytesColumnVector) b.cols[2]; b.cols[1].noNulls = true; VectorExpression expr = new CastLongToString(1, 2); expr.setInputTypeInfos(new TypeInfo[] {TypeInfoFactory.longTypeInfo}); expr.transientInit(); expr.evaluate(b); byte[] num255 = toBytes("255"); Assert.assertEquals(0, StringExpr.compare(num255, 0, num255.length, resultV.vector[1], resultV.start[1], resultV.length[1])); }