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

Refactor: move JSON path generation logic in Generator #2920

Merged
merged 6 commits into from
Feb 6, 2024

Conversation

georgesittas
Copy link
Collaborator

@georgesittas georgesittas commented Feb 6, 2024

Addresses items (1) and (2) mentioned in the "to do" section of #2914.

Transpiling * is a little more nuanced and requires more investigation, because despite some dialects not supporting this syntax, I think it may still be possible to simulate it by simply omitting it. For example, in DuckDB you can do:

D SELECT '["a", "b", "c"]' -> '$[*]';
┌───────────────────────────────┐
│ ('["a", "b", "c"]' -> '$[*]') │
│            json[]             │
├───────────────────────────────┤
│ ["a", "b", "c"]               │
└───────────────────────────────┘

But in BigQuery this syntax is not supported, since they don't recognize the * inside the brackets ("Unsupported operator in JSONPath: *"). However, if we completely omit the brackets, it seems like the result matches:

> SELECT JSON_EXTRACT('["a", "b", "c"]', '$');
f0_
["a","b","c"]

The exact same thing holds e.g. for Trino. Not sure if we wanna solve this now, though.

sqlglot/generator.py Outdated Show resolved Hide resolved
sqlglot/jsonpath.py Outdated Show resolved Hide resolved
@georgesittas georgesittas merged commit 15582f4 into main Feb 6, 2024
5 checks passed
@georgesittas georgesittas deleted the jo/refactor_jsonpath branch February 6, 2024 18:23
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

Successfully merging this pull request may close these issues.

None yet

2 participants