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

Enable to pass a list of jsonpointers like to whitelist/blacklist in jsonparser #235

Open
rmannibucau opened this issue Feb 24, 2020 · 9 comments

Comments

@rmannibucau
Copy link

When you know what you read, passing some whitelist/blacklist of parser events to skip can enable to reduce memory consumption and optimize the execution.

This is somehow related to jakartaee/jsonb-api#224 (comment)

Side note: can need to generalize jsonpointer syntax to support wildcards for arrays.

@emattheis
Copy link

This is an intriguing idea. The set of pointers could determine whether or not the parser automatically skips over events. Might be tricky to specify this in a non-ambiguous way, though, in the face of contradictory whitelist/blacklists.

@jjspiegel
Copy link

Parsers should already be able to skip allocating memory for events that are not consumed by the caller. I see no advantage to pushing query processing or redaction inside the parser.

@rmannibucau
Copy link
Author

Spec defines JsonPointer, if a set can be passed to the parser then it sounds easy to impl and configure.
Today there is only next() and next enable getXXX access so there is no way to skip anything.

@jjspiegel
Copy link

jjspiegel commented Feb 24, 2020

No, there is also skipObject() and skipArray(). And there is no requirement that next() has to materialize anything. Materialization can be postponed until getXXX is actually called.

@emattheis
Copy link

I don't think memory consumption is the real concern here. Skipping is implied when getXXX is not called. Perhaps the documentation should be clearer in this regard, but it's an implementation detail. From an API perspective, it is clear.

That being said, I could definitely see JsonParser#skipTo(JsonPointer) being useful since JSON-P seems to be embracing RFC 6901. It wouldn't be much of a stretch to enable registering whitelist/blacklist pointers as part of the config when generating a JsonParserFactory, either.

@rmannibucau
Copy link
Author

There is a requirement to materialize next by design, you cant impl getString if you didnt stored it somewhere - mem, disk, ... - so requirement is built in.

For ex, you cant skip an event string value today, even if you know it does 10g (yes xml in json but it exists).

SkipTo is ok but id expect more a jsonParserFactory.createParser(...., new JsonPointer[]{....}) to be able to pass multiple ones

@jjspiegel
Copy link

The ability to evaluate JsonPointer over JsonParser is reasonable but I don't think this should be added to the parser api. The parser api should remain independent of specific path evaluation languages. There is no reason this functionality can't be implemented outside of the parser. And the premise that next() requires string materialization is not correct.

@emattheis
Copy link

@rmannibucau A parser can basically tell by the first character what the event is. No need to move any further until asked to. If getXXX() is never called, the parser can advance to the next token while discarding all the characters it examines.

@jjspiegel That makes sense. Something like JsonPointer#seek(JsonParser) would do the trick.

@rmannibucau
Copy link
Author

No, even not called value is materialized - at least in byte[], check out all impl out there. API requires it by its design so parser api cant read some document it should and jsonb cant support some mapping it could forking jsonp.

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

3 participants