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

Feat(clickhouse): add support for JSONExtractString, clean up some helpers #2925

Merged
merged 3 commits into from
Feb 7, 2024

Conversation

georgesittas
Copy link
Collaborator

@georgesittas georgesittas commented Feb 7, 2024

Several changes here, not necessarily related to each other:

  • Improve parsing / transpilation of clickhouse's JSONExtractString, fixes Support for Clickhouse JSON Extract* Functions #2051. Note that clickhouse uses 1-based indexing, so I had to slightly change the logic in some parts to take this into account. Perhaps and interesting observation here is that the dialect offset is not necessarily tied to the JSON path offset.
  • Refactored some helpers that concern JSON path parsing and generation and are used by clickhouse, postgres, redshift.
  • Fixed some issues related to columns being used in json paths (supported by clickhouse, duckdb, postgres). This involved a change that may need some attention in the parser (I split _parse_column into two methods, can elaborate if needed).
  • Finally, fixed an issue with multi-arg JSON_EXTRACT calls. It turns out that I had a bug in my implementation and so previously we'd support up to 3 arguments because of the null_if_invalid flag, but 4 would fail. I extended both JSONExtract and JSONExtractScalar to accept arbitrarily many args to amend this.

References:

sqlglot/dialects/dialect.py Outdated Show resolved Hide resolved
@georgesittas georgesittas merged commit 3a20eac into main Feb 7, 2024
5 checks passed
@georgesittas georgesittas deleted the jo/json_path_vars_fix branch February 7, 2024 18:35
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.

Support for Clickhouse JSON Extract* Functions
2 participants