deniskuzZ commented on code in PR #6747:
URL: https://github.com/apache/hive/pull/6747#discussion_r3940794551
##########
serde/src/java/org/apache/hadoop/hive/serde2/lazy/fast/LazySimpleDeserializeRead.java:
##########
@@ -402,105 +453,248 @@ public String getDetailedReadPositionString() {
sb.append(" at field start position ");
sb.append(startPositions[currentTopLevelFieldIndex]);
int currentFieldLength = startPositions[currentTopLevelFieldIndex + 1] -
- startPositions[currentTopLevelFieldIndex] - 1;
+ startPositions[currentTopLevelFieldIndex] - topLevelSeparatorLen;
sb.append(" for field length ");
sb.append(currentFieldLength);
}
return sb.toString();
}
+ /**
+ * Bytes at {@code buf[off..off+dlen)} equal to {@code delim[0..dlen)}?
+ *
+ * Caller has already checked {@code buf[off] == delim[0]}, so we start at
+ * index 1 — this is only ever invoked when the first byte matched, which
+ * keeps the multi-byte hot loop from paying for a tail compare on every
+ * mismatching input byte.
+ */
+ private static boolean matchesAt(byte[] buf, int off, byte[] delim, int
dlen) {
+ for (int i = 1; i < dlen; i++) {
+ if (buf[off + i] != delim[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
/**
* Parse the byte[] and fill each field.
*
* This is an adapted version of the parse method in the LazyStruct class.
* They should parse things the same way.
+ *
+ * <p>Structure: pick one of three parsing algorithms based on the
(isEscaped,
+ * fieldDelimMulti) pair, run it to find each field's start position, then
+ * fill the trailing sentinel and record EOF. Each algorithm is a single-
+ * callsite private method — splitting them out is a readability move; the
+ * combined loops used to hide three flow-controls inside one big if/else.
+ *
+ * <p>The helpers write into {@link #startPositions} and (for the escape
+ * path) {@link #escapeCounts} directly, and stash the parse-stop cursor —
+ * how many fields they consumed, and where in the byte[] they stopped — on
+ * two instance fields {@link #parsedFieldCount} / {@link
#parsedFieldByteEnd}.
+ * Bundling those into a return value would cost a heap allocation on every
+ * row, which we can't afford here.
*/
private void topLevelParse() {
Review Comment:
consider making the dispatch flatter
````
private void topLevelParse() {
if (isEscaped) {
parseSingleByteWithEscape();
} else if (fieldDelimMulti != null) {
parseMultiByteNoEscape();
} else {
parseSingleByteNoEscape();
}
final int fieldId = parsedFieldCount;
final int fieldByteEnd = parsedFieldByteEnd;
if (fieldId == fieldCount || fieldByteEnd == end) {
Arrays.fill(
startPositions,
fieldId,
startPositions.length,
fieldByteEnd + topLevelSeparatorLen);
}
isEndOfInputReached = fieldByteEnd == end;
}
````
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]