Re: making the backend's json parser work in frontend code
Robert Haas <robertmhaas@gmail.com>
From: Robert Haas <robertmhaas@gmail.com>
To: David Steele <david@pgmasters.net>
Cc: "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2020-01-17T21:33:48Z
Lists: pgsql-hackers
Attachments
- v2-0001-Adjust-src-include-utils-jsonapi.h-so-it-s-not-ba.patch (application/octet-stream) patch v2-0001
- v2-0002-Split-JSON-lexer-parser-from-json-data-type-suppo.patch (application/octet-stream) patch v2-0002
- v2-0004-WIP-Return-errors-rather-than-using-ereport.patch (application/octet-stream) patch v2-0004
- v2-0003-Remove-jsonapi.c-s-lex_accept.patch (application/octet-stream) patch v2-0003
On Fri, Jan 17, 2020 at 12:36 PM David Steele <david@pgmasters.net> wrote: > It seems to work just fine. I didn't stress it too hard but I did put > in one escape and a multi-byte character and check the various data types. Cool. > I used the callbacks because that's the first method I found but it > seems like json_lex() might be easier to use in practice. Ugh, really? That doesn't seem like it would be nice at all. > I think it's an issue that the entire string must be passed to the lexer > at once. That will not be great for large manifests. However, I don't > think it will be all that hard to implement an optional "want more" > callback in the lexer so JSON data can be fed in from the file in chunks. I thought so initially, but now I'm not so sure. The thing is, you actually need all the manifest data in memory at once anyway, or so I think. You're essentially doing a "full join" between the contents of the manifest and the contents of the file system, so you've got to scan one (probably the filesystem) and then mark entries in the other (probably the manifest) used as you go. But this might need more thought. The details probably depend on exactly how you design it all. > So, that just leaves ereport() as the largest remaining issue? I'll > look at that today and Tuesday and see what I can work up. PFA my work on that topic. As compared with my previous patch series, the previous 0001 is dropped and what are now 0001 and 0002 are the same as patches from the previous series. 0003 and 0004 are aiming toward getting rid of ereport() and, I believe, show a plausible strategy for so doing. There are, possibly, things not to like here, and it's certainly incomplete, but I think I kinda like this direction. Comments appreciated. 0003 nukes lex_accept(), inlining the logic into callers. I found that the refactoring I wanted to do in 0004 was pretty hard without this, and it turns out to save code, so I think this is a good idea independently of anything else. 0004 adjusts many functions in jsonapi.c to return a new enumerated type, JsonParseErrorType, instead of directly doing ereport(). It adds a new function that takes this value and a lexing context and throws an error. The JSON_ESCAPING_INVALID case is wrong and involves a gross hack, but that's fixable with another field in the lexing context. More work is needed to really bring this up to scratch, but the idea is to make this code have a soft dependency on ereport() rather than a hard one. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Commits
-
Add jsonapi.c to Mkvcbuild.pm's @pgcommonallfiles.
- 006b9dcad419 13.0 landed
-
Move jsonapi.c and jsonapi.h to src/common.
- beb4699091e9 13.0 landed
-
Move some code from jsonapi.c to jsonfuncs.c.
- 73ce2a03f30b 13.0 landed
-
Adjust pg_parse_json() so that it does not directly ereport().
- 1f3a021730be 13.0 landed
-
Remove jsonapi.c's lex_accept().
- 530609aa4263 13.0 landed
-
Split JSON lexer/parser from 'json' data type support.
- 11b5e3e35d39 13.0 landed
-
Rationalize code placement between wchar.c, encnames.c, and mbutils.c.
- 5afaa2e42655 13.0 landed
-
Move wchar.c and encnames.c to src/common/.
- e6afa8918c46 13.0 landed
-
Update header comments for wchar.c and encnames.c.
- 3d4cb5d6c180 13.0 landed
-
Make StringInfo available to frontend code.
- 26aaf97b683d 13.0 cited
-
Use SASLprep to normalize passwords for SCRAM authentication.
- 60f11b87a234 10.0 cited