-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
sql: support JSONPath #22513
Comments
54565: parser: parse REINDEX SCHEMA r=arulajmani a=otan Refs: #51424 Release note: None 54568: sql: add unimplemented errors for jsonpath types and builtins r=arulajmani a=otan Refs #22513 , #51424 Release note: None 54573: builtins: add unimplemented errors for full text search builtins r=arulajmani a=otan Refs: #7821, #51424 Release note: None 54575: parser: add unimplemented errors for CREATE/DROP ACCESS METHOD r=arulajmani a=otan No issue number for this one (same as aggregate) as there's no way I think we can realistically support this. Telemetry still there though. Refs: #51424 Release note: None Co-authored-by: Oliver Tan <[email protected]>
This is a feature we use in PostgreSQL, that we will need to migrate to CockroachDB. |
Support for JSON path is essential for wildcard searches. Here's an example using movies.json, converted to hold one object per line via this command: perl -i -pe 's/\]\},/]}\n/g' movies.json Load it up into Postgres: CREATE TABLE MOVIES (id SERIAL PRIMARY KEY, movie JSONB NOT NULL);
\copy movies(movie) from PROGRAM 'sed "s|\\\\|\\\\\\\\|g" movies.json';
CREATE INDEX ON movies USING GIN (movie jsonb_path_ops); If I want a list of all movies where Carrie Fisher is a cast member:
This is because the The closest equivalent I can get in Cockroach is: CREATE TABLE MOVIES (id SERIAL PRIMARY KEY, movie JSONB NOT NULL);
\copy movies(movie) from 'movies.json';
CREATE INDEX ON movies USING GIN (movie); A couple of differences here from the Postgres example:
No big deal, but as there are no wildcards, we can search only one at a time:
Now we can work around this by putting the array in an
However it cannot use the GIN index:
Contrast that table scan with this plan from Postgres using jsonpath:
|
Aaaaaand I just figured out that
So much for the array wildcard argument! |
As part of work to implement jsonpath queries, this PR implements the `jsonpath` type within CockroachDB. There is no parsing or evaluation added, and the `jsonpath` will currently accept any non-empty string. Table creation with jsonpath columns are not supported as of now until an encoding and decoding schema is determined. Indexes are not supported for `jsonpath` columns when they will be introduced. Part of: cockroachdb#22513 Release note (sql change): Adding jsonpath type, without parsing, evaluation, or table creation. Currently accepts any non-empty string.
140204: sql: add jsonpath type r=normanchenn a=normanchenn As part of work to implement jsonpath queries, this PR implements the`jsonpath` type within CockroachDB. There is no parsing or evaluation added, and the `jsonpath` will currently accept any non-empty string. Indexes are not currently supported for `jsonpath` columns. Part of: #22513 Release note (sql change): Adding jsonpath type, without parsing or evaluation. Currently accepts any non-empty string. Co-authored-by: Norman Chen <[email protected]>
This is a prototype for a minimal jsonpath parser. It currently supports a small set of features: setting jsonpath mode (strict/lax), root ($), key accessors (.key_name), and array wildcards ([*]). This is standalone and doesn't integrate with the database. Part of: cockroachdb#22513 Release note: None
140204: sql: add jsonpath type r=normanchenn a=normanchenn As part of work to implement jsonpath queries, this PR implements the`jsonpath` type within CockroachDB. There is no parsing or evaluation added, and the `jsonpath` will currently accept any non-empty string. Indexes are not currently supported for `jsonpath` columns. Part of: cockroachdb#22513 Release note (sql change): Adding jsonpath type, without parsing or evaluation. Currently accepts any non-empty string. Co-authored-by: Norman Chen <[email protected]>
This is a prototype for a minimal jsonpath parser. It currently supports a small set of features: setting jsonpath mode (strict/lax), root ($), key accessors (.key_name), and array wildcards ([*]). This is standalone and doesn't integrate with the database. Part of: cockroachdb#22513 Release note: None
141661: sql: add jsonpath parser r=normanchenn a=normanchenn This is a prototype for a minimal jsonpath parser. It currently supports a small set of features: setting jsonpath mode (strict/lax), root ($), key accessors (.key_name), and array wildcards ([*]). This is standalone and doesn't integrate with the database. Part of: #22513 Release note: None 142037: kvserver: cache the storeClockTimestamp every tick r=iskettaneh a=iskettaneh Instead of calculating the time now() multiple times during the tick. This commit caches timestamp during the tick(), and then it gets reused instead of redoing the work again. Preliminary testing showed that this reduces the clock mutex contention by 50%. Fixes: #142049 Release note: None 142043: roachtest: Update pgx block list r=spilchen a=spilchen The pgx test v5.TestBeginReadOnly previously expected an error when executing: ``` BEGIN READ ONLY CREATE TABLE foo(id serial primary key) ``` Due to the recent autocommit_before_ddl change in #141145, the transaction is auto-committed before the CREATE TABLE, allowing the command to succeed. This update adjusts the block list so that we ignore this failed test. I will backport this in: #141987 #141851. Epic: none Release note: none Closes #141903 Co-authored-by: Norman Chen <[email protected]> Co-authored-by: Ibrahim Kettaneh <[email protected]> Co-authored-by: Matt Spilchen <[email protected]>
142336: builtins: add jsonb_path_query r=normanchenn a=normanchenn Previously, the `jsonpath` data type and parser were created and integrated with each other. This PR adds the `jsonb_path_query` function and a new `pkg/util/jsonpath/eval` package, adding an evaluation engine for jsonpath queries. Informs: #22513. Epic: None Release note (sql change): Add the `jsonb_path_query` function, which takes in a JSON object and a Jsonpath query, and returns the resulting JSON object. Co-authored-by: Norman Chen <[email protected]>
Spec is available here. There's a good blog post covering the feature in Postgres here. I have an incomplete and non-Cockroach-compatible implementation here which includes a goyacc parser, which might be helpful.
Postgres documentation: https://www.postgresql.org/docs/current/functions-json.html#FUNCTIONS-SQLJSON-PATH
I think this could potentially make a decent intern project, in terms of size and scope. It is not a feature of Postgres 10 but will be a feature of Postgres 11.
Implementation
jsonb_path_query()
builtins: add jsonb_path_query #142336jsonb_path_exists()
builtins: add jsonb_path_exists #143028Supported Features
strict/lax
mode$
).key
)[*]
)[0]
)[0 to 5]
)[0, 1 to 5]
)$variable
)like_regex
jsonpath: addlike_regex
support #143243, jsonpath: addlike_regex
, string and null scalars #143240Jira issue: CRDB-5852
Epic: CRDB-12464
gz#18507
The text was updated successfully, but these errors were encountered: