Skip to content

fix(druid): add JSON_VALUE RETURNING support#7771

Merged
georgesittas merged 1 commit into
tobymao:mainfrom
sitelight:fix/druid-json-value-returning
Jun 20, 2026
Merged

fix(druid): add JSON_VALUE RETURNING support#7771
georgesittas merged 1 commit into
tobymao:mainfrom
sitelight:fix/druid-json-value-returning

Conversation

@sitelight

Copy link
Copy Markdown
Contributor

Description

Adds JSON_VALUE to Druid's FUNCTION_PARSERS so the RETURNING <type> clause is parsed instead of falling through to the generic function-call parser, which can't handle it.

The base Parser._parse_json_value already handles RETURNING (and ON EMPTY / ON ERROR) correctly — it just wasn't routed for the Druid dialect. MySQL, Trino, and Exasol register JSON_VALUE the same way.

Before

>>> import sqlglot
>>> sqlglot.parse_one("SELECT JSON_VALUE(x, '$.a' RETURNING BIGINT) FROM t", dialect="druid")
sqlglot.errors.ParseError: Expecting ). Line 1, Col: 36.

After

>>> sqlglot.parse_one("SELECT JSON_VALUE(x, '$.a' RETURNING BIGINT) FROM t", dialect="druid").sql(dialect="druid")
"SELECT JSON_VALUE(x, '$.a' RETURNING BIGINT) FROM t"

Related

Surfaced via apache/superset#36954 — Superset users on Druid datasets currently can't run any query using json_value(..., '$.x' RETURNING <type>) because the SQL fails sanitize/format before being sent to the engine.

Tests

Added test_json_value to tests/dialects/test_druid.py covering plain JSON_VALUE, RETURNING DOUBLE, and the exact failure case from the linked issue. Full suite (python -m unittest) green locally.

@georgesittas georgesittas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@georgesittas georgesittas merged commit 31cee10 into tobymao:main Jun 20, 2026
8 checks passed
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.

2 participants