steffenvan commented on code in PR #1123:
URL: https://github.com/apache/jackrabbit-oak/pull/1123#discussion_r1328378793
##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntryWriter.java:
##########
@@ -118,14 +122,53 @@ public static String getPath(String entryLine) {
return entryLine.substring(0, getDelimiterPosition(entryLine));
}
+ /*
+ Currently we only have 2 types of store:
+ 1. FlatFileStore
+ 2. IncrementalFlatFileStore
+ */
public static String[] getParts(String line) {
- int pos = getDelimiterPosition(line);
- return new String[]{line.substring(0, pos), line.substring(pos + 1)};
+ // file is FlatFileStore
+ if (line.endsWith("}")) {
+ int pos = getDelimiterPosition(line);
+ return new String[]{line.substring(0, pos), line.substring(pos +
1)};
+ } else {
+ // file is IncrementalFlatFileStore
+ List<Integer> positions = getDelimiterPositions(line);
+ checkState(positions.size() >= 2, "Invalid path entry [%s]", line);
+ // there are 4 parts in incrementalFFS and default delimiter is |
+ // path|nodeData|checkpoint|operand
+ // Node's data can itself have many | so we split based on first
and last 2 |
+ String[] parts = new String[4];
+ parts[0] = line.substring(0, positions.get(0));
+ parts[1] = line.substring(positions.get(0) + 1,
positions.get(positions.size() - 2));
+ parts[2] = line.substring(positions.get(positions.size() - 2) + 1,
positions.get(positions.size() - 1));
+ parts[3] = line.substring(positions.get(positions.size() - 1) + 1);
+ return parts;
+ }
}
private static int getDelimiterPosition(String entryLine) {
int indexOfPipe = entryLine.indexOf(NodeStateEntryWriter.DELIMITER);
checkState(indexOfPipe > 0, "Invalid path entry [%s]", entryLine);
return indexOfPipe;
}
+
+ private static List<Integer> getDelimiterPositions(String entryLine) {
Review Comment:
I think this function could be refactored a bit - I'd like to avoid the
`while(true)` loop. IMO, a more functional approach could look like:
```java
private static List<Integer> getDelimiterPositions(String entryLine) {
int firstPos = entryLine.indexOf(NodeStateEntryWriter.DELIMITER);
if (firstPos == -1) {
throw new IllegalStateException(String.format("Invalid path entry
[%s]", entryLine));
}
return IntStream.iterate(firstPos,
pos -> pos >= 0,
pos ->
entryLine.indexOf(NodeStateEntryWriter.DELIMITER, pos + 1))
.boxed()
.collect(Collectors.toList());
}
```
--
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]