fix(snowflake): map JSON type to VARIANT in Snowflake generator [CLAUDE]#7496
Merged
georgesittas merged 1 commit intotobymao:mainfrom Apr 14, 2026
Conversation
Snowflake has no native JSON data type — VARIANT is the equivalent. When transpiling CAST(x AS JSON) from DuckDB (or other dialects) to Snowflake, the JSON type was passed through unchanged, producing invalid SQL. Add exp.DType.JSON: "VARIANT" to the Snowflake generator's TYPE_MAPPING, following the same pattern as Fabric's JSON→VARCHAR mapping. Ref: https://docs.snowflake.com/en/sql-reference/data-types-semistructured "Snowflake can convert data from JSON format to an internal hierarchy of ARRAY, OBJECT, and VARIANT data and store that hierarchical data directly in a VARIANT value."
georgesittas
approved these changes
Apr 14, 2026
maxa-jonathan-hallee
added a commit
to maxa-jonathan-hallee/sqlglot
that referenced
this pull request
Apr 16, 2026
…ON_ARRAY [CLAUDE] DuckDB JSON_ARRAY returns type JSON, which we map to Snowflake VARIANT (see tobymao#7496). TO_JSON returns VARCHAR, breaking downstream JSON access operators like JSON_EXTRACT_PATH_TEXT. TO_VARIANT preserves the semi-structured semantics.
georgesittas
pushed a commit
that referenced
this pull request
Apr 17, 2026
…E] (#7497) * fix(snowflake): transpile DuckDB JSON_ARRAY to ARRAY_CONSTRUCT [CLAUDE] DuckDB's JSON_ARRAY function has no Snowflake equivalent — Snowflake uses ARRAY_CONSTRUCT instead (JSON_ARRAY is not a recognized function). - Add JSON_ARRAY → exp.JSONArray mapping in DuckDB parser FUNCTIONS - Add exp.JSONArray → ARRAY_CONSTRUCT transform in Snowflake generator Ref: https://docs.snowflake.com/en/sql-reference/functions/array_construct * fix(snowflake): wrap JSON_ARRAY transpilation with TO_JSON for correct return type [CLAUDE] DuckDB JSON_ARRAY returns a JSON string, not a native array. ARRAY_CONSTRUCT alone returns a native array which breaks downstream JSON access operators. * fix(snowflake): use TO_VARIANT instead of TO_JSON when transpiling JSON_ARRAY [CLAUDE] DuckDB JSON_ARRAY returns type JSON, which we map to Snowflake VARIANT (see #7496). TO_JSON returns VARCHAR, breaking downstream JSON access operators like JSON_EXTRACT_PATH_TEXT. TO_VARIANT preserves the semi-structured semantics.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Snowflake has no native JSON data type —
VARIANTis the equivalent. When transpilingCAST(x AS JSON)from DuckDB (or other dialects) to Snowflake, the JSON type was passed through unchanged, producing invalid SQL.exp.DType.JSON: "VARIANT"to the Snowflake generator'sTYPE_MAPPINGtest_duckdb.pyverifyingCAST(x AS JSON)→CAST(x AS VARIANT)for SnowflakeFollows the same pattern as Fabric's
JSON → VARCHARmapping ingenerators/fabric.py.References