Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Results do not match other implementations #60

Open
2 of 4 tasks
cburgmer opened this issue Feb 3, 2020 · 5 comments
Open
2 of 4 tasks

Results do not match other implementations #60

cburgmer opened this issue Feb 3, 2020 · 5 comments

Comments

@cburgmer
Copy link

cburgmer commented Feb 3, 2020

The following queries provide results that do not match those of other implementations of JSONPath
(compare https://cburgmer.github.io/json-path-comparison/):

  • $.2
    Input:

    {"a": "first", "2": "second", "b": "third"}
    

    Expected output:

    ["second"]
    

    Error:

    Exception in thread "main" org.antlr.v4.runtime.misc.ParseCancellationException
    	at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:66)
    	at org.antlr.v4.runtime.Parser.match(Parser.java:206)
    	at org.jsfr.json.compiler.JsonPathParser.childNode(JsonPathParser.java:672)
    	at org.jsfr.json.compiler.JsonPathParser.relativePath(JsonPathParser.java:272)
    	at org.jsfr.json.compiler.JsonPathParser.path(JsonPathParser.java:159)
    	at org.jsfr.json.compiler.JsonPathCompiler.compile(JsonPathCompiler.java:283)
    	at org.jsfr.json.compiler.JsonPathCompiler.compile(JsonPathCompiler.java:273)
    	at org.jsfr.json.JsonSurfer.collectAll(JsonSurfer.java:262)
    	at query.App.main(App.java:27)
    Caused by: org.antlr.v4.runtime.InputMismatchException
    	at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:61)
    	... 8 more
    
  • $[-1]
    Input:

    ["first", "second", "third"]
    

    Expected output:

    ["third"]
    

    Actual output:

    []
    
  • $[-1:]
    Input:

    ["first", "second", "third"]
    

    Expected output:

    ["third"]
    

    Actual output:

    ["first", "second", "third"]
    
  • $[?(@.key=="some.value")]
    Input:

    [{"key": "some"}, {"key": "value"}, {"key": "some.value"}]
    

    Expected output:

    [{"key": "some.value"}]
    

    Error:

    line 1:11 token recognition error at: '"'
    line 1:22 token recognition error at: '"'
    line 1:12 no viable alternative at input '@.key==some'
    Exception in thread "main" org.antlr.v4.runtime.misc.ParseCancellationException
    	at org.antlr.v4.runtime.BailErrorStrategy.recover(BailErrorStrategy.java:51)
    	at org.jsfr.json.compiler.JsonPathParser.filterExpr(JsonPathParser.java:947)
    	at org.jsfr.json.compiler.JsonPathParser.filter(JsonPathParser.java:768)
    	at org.jsfr.json.compiler.JsonPathParser.relativePath(JsonPathParser.java:307)
    	at org.jsfr.json.compiler.JsonPathParser.path(JsonPathParser.java:159)
    	at org.jsfr.json.compiler.JsonPathCompiler.compile(JsonPathCompiler.java:283)
    	at org.jsfr.json.compiler.JsonPathCompiler.compile(JsonPathCompiler.java:273)
    	at org.jsfr.json.JsonSurfer.collectAll(JsonSurfer.java:262)
    	at query.App.main(App.java:27)
    Caused by: org.antlr.v4.runtime.NoViableAltException
    	at org.antlr.v4.runtime.atn.ParserATNSimulator.noViableAlt(ParserATNSimulator.java:2026)
    	at org.antlr.v4.runtime.atn.ParserATNSimulator.execATN(ParserATNSimulator.java:467)
    	at org.antlr.v4.runtime.atn.ParserATNSimulator.adaptivePredict(ParserATNSimulator.java:393)
    	at org.jsfr.json.compiler.JsonPathParser.filterExpr(JsonPathParser.java:843)
    	... 7 more
    

For reference, the output was generated by the program in https://github.com/cburgmer/json-path-comparison/tree/master/implementations/Java_com.github.jsurfer.

@wanglingsong
Copy link
Owner

I can try to fix the last case first

wanglingsong added a commit that referenced this issue Feb 17, 2020
@wanglingsong
Copy link
Owner

Due to the streaming nature of JsonSurfer, Case 2 and 3 with negative step are very hard to implement

@cburgmer
Copy link
Author

Just out of curiosity, for a query $[-n] you could keep a window with n entries. When the stream stops you pick the first entry from that window and have your candidate.
The upper memory limit for the window would depend on the size of the entries in the list you are processing. This is very likely no different to what you are currently doing, just n times (= constant) more.

@wanglingsong
Copy link
Owner

Cool. It does make sense. I will try.

@wanglingsong
Copy link
Owner

I've just reviewed source code and couldn't figure out a quick fix. So Case 2 & 3 won't be supported in near release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants