deniskuzZ commented on code in PR #5624: URL: https://github.com/apache/hive/pull/5624#discussion_r2167425863
########## ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSubstr.java: ########## @@ -172,32 +170,69 @@ public BytesWritable evaluate(BytesWritable bw, IntWritable pos, IntWritable len } private BytesWritable evaluateInternal(BytesWritable bw, int pos, int len) { - if (len <= 0) { return new BytesWritable(); } - int[] index = makeIndex(pos, len, bw.getLength()); - if (index == null) { + byte[] b = Arrays.copyOf(bw.getBytes(), bw.getLength()); + StringSubstrColStartLen.populateSubstrOffsets(b, 0, b.length, craetePos(pos), len, index); + if (index[0] == -1) { return new BytesWritable(); } - return new BytesWritable(Arrays.copyOfRange(bw.getBytes(), index[0], index[1])); + return new BytesWritable(arrayCopy(b, index[0], index[1])); + } + + private BytesWritable evaluateInternal(BytesWritable bw, int pos) { + byte[] b = Arrays.copyOf(bw.getBytes(), bw.getLength()); + int offset = StringSubstrColStart.getSubstrStartOffset(b, 0, b.length, craetePos(pos)); + if (offset == -1) { + return new BytesWritable(); + } + + return new BytesWritable(arrayCopy(b, offset, bw.getLength() - offset)); } public BytesWritable evaluate(BytesWritable bw, IntWritable pos){ - return evaluate(bw, pos, maxValue); + if ((bw == null) || (pos == null)) { + return null; + } + return evaluateInternal(bw, pos.get()); } public BytesWritable evaluate(BytesWritable bw, LongWritable pos){ - return evaluate(bw, pos, maxLongValue); + if ((bw == null) || (pos == null)) { + return null; + } + + return evaluateInternal(bw, (int) pos.get()); } @Override public StatEstimator getStatEstimator() { return new SubStrStatEstimator(); } + private byte[] arrayCopy(byte[] src, int pos, int len) { Review Comment: @ryukobayashi, in Java, array indices cannot be negative -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org