diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/StringSubstrColStartLen.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/StringSubstrColStartLen.java index c396030..6c21a38 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/StringSubstrColStartLen.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/StringSubstrColStartLen.java @@ -110,6 +110,10 @@ static void populateSubstrOffsets(byte[] utf8String, int start, int len, int sub substrStart = length + substrStart; } + if (substrLength == 0) { + return; + } + int endIdx = substrStart + substrLength - 1; for (int i = start; i != end; ++i) { if ((utf8String[i] & 0xc0) != 0x80) { diff --git ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorStringExpressions.java ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorStringExpressions.java index 28123a8..917d7ef 100644 --- ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorStringExpressions.java +++ ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorStringExpressions.java @@ -1570,6 +1570,36 @@ public void testSubstrStartLen() throws UnsupportedEncodingException { ) ); + //Testing substring index starting with 1 and zero length + + outV.isRepeating = true; + outV.noNulls = false; + + expr = new StringSubstrColStartLen(0, 1, 0, 1); + outCol = (BytesColumnVector) batch.cols[1]; + expr.evaluate(batch); + Assert.assertEquals(3, batch.size); + Assert.assertTrue(outCol.noNulls); + Assert.assertFalse(outCol.isRepeating); + Assert.assertEquals(0, + StringExpr.compare( + data1, 1, 0, outCol.vector[0], outCol.start[0], outCol.length[0] + ) + ); + + Assert.assertEquals(0, + StringExpr.compare( + data2, 1, 0, outCol.vector[1], outCol.start[1], outCol.length[1] + ) + ); + + Assert.assertEquals(0, + StringExpr.compare( + data3, 1, 0, outCol.vector[2], outCol.start[2], outCol.length[2] + ) + ); + + //Testing substring index starting with 0 and length equal to array length outV.isRepeating = true;