Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@ public class NestedPathFinder
public static String toNormalizedJsonPath(List<NestedPathPart> paths)
{
if (paths.isEmpty()) {
return "$.";
return "$";
}
StringBuilder bob = new StringBuilder();
boolean first = true;
for (NestedPathPart partFinder : paths) {
if (partFinder instanceof NestedPathField) {
if (first) {
bob.append("$.");
} else {
bob.append(".");
bob.append("$");
}
final String id = partFinder.getPartIdentifier();
if (id.contains(".") || id.contains("'") || id.contains("\"") || id.contains("[") || id.contains("]")) {
bob.append("['").append(id).append("']");
} else {
bob.append(".");
bob.append(id);
}
} else if (partFinder instanceof NestedPathArrayElement) {
Expand Down Expand Up @@ -124,16 +123,20 @@ public static List<NestedPathPart> parseJsonPath(@Nullable String path)
quoteMark = i;
partMark = i + 1;
} else if (current == '\'' && quoteMark >= 0 && path.charAt(i - 1) != '\\') {
if (path.charAt(i + 1) != ']') {
if (arrayMark >= 0) {
continue;
}
badFormatJsonPath(path, "closing ' must immediately precede ']'");
}

parts.add(new NestedPathField(getPathSubstring(path, partMark, i)));
dotMark = -1;
quoteMark = -1;
// chomp to next char to eat closing array
if (++i == path.length()) {
break;
}
if (path.charAt(i) != ']') {
badFormatJsonPath(path, "closing ' must immediately precede ']'");
}
partMark = i + 1;
arrayMark = -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static Iterable<Object[]> constructorFeeder()
@Before
public void setUp()
{

queryableAdapter = new QueryableIndexStorageAdapter(TestIndex.getMMappedTestIndex());
frameSegment = FrameTestUtil.adapterToFrameSegment(queryableAdapter, frameType);
frameAdapter = frameSegment.asStorageAdapter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,14 @@ public void testParseJsonPath()
NestedPathFinder.toNormalizedJqPath(pathParts)
);
Assert.assertEquals(
"$.['x.y.z][\\']][]'].['13234.12[]][23'].['fo.o'].['.b.a.r.']",
"$['x.y.z][\\']][]']['13234.12[]][23']['fo.o']['.b.a.r.']",
NestedPathFinder.toNormalizedJsonPath(pathParts)
);

pathParts = NestedPathFinder.parseJsonPath("$['hell'o']");
Assert.assertEquals(1, pathParts.size());
Assert.assertEquals("hell'o", pathParts.get(0).getPartIdentifier());
Assert.assertEquals("$['hell'o']", NestedPathFinder.toNormalizedJsonPath(pathParts));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ public void testGroupByAllPaths() throws Exception
.build()
),
ImmutableList.of(
new Object[]{"[\"$.\"]", 5L},
new Object[]{"[\"$\"]", 5L},
new Object[]{"[\"$.n.x\",\"$.array[0]\",\"$.array[1]\"]", 2L}
)
);
Expand Down