fix(bigquery)!: Do not normalize JSON fields in dot notation#6320
Merged
fix(bigquery)!: Do not normalize JSON fields in dot notation#6320
Conversation
8c22aeb to
2cb0475
Compare
2cb0475 to
5c9c45d
Compare
tobymao
reviewed
Nov 13, 2025
tobymao
reviewed
Nov 13, 2025
Collaborator
Author
|
Here's my research thus far: Case sensitivity
Repros: snowflake> WITH t AS (SELECT PARSE_JSON('{"a": {"A": 1}, "A": {"a": 2}}') AS col) SELECT col:a.A, col:A.a from t;
COL:A.A | COL:A.A
-- | --
1 | 2
databricks> WITH t AS (SELECT PARSE_JSON('{"a": {"A": 1}, "A": {"a": 2}}') AS col) SELECT col:a.A, col:A.a from t;
A a
1 2
duckdb> WITH t AS (SELECT JSON '{"a": {"A": 1}, "A": {"a": 2}}' AS col) SELECT col.a.A, col.A.a from t;
┌──────┬──────┐
│ A │ a │
│ json │ json │
├──────┼──────┤
│ 1 │ 2 │
└──────┴──────┘
clickhouse (online playground)> WITH t AS (SELECT '{"a": {"A": 1}, "A": {"a": 2}}'::JSON AS col) SELECT col.a.A, col.A.a from t;
col.a.A | col.A.a
1 2
Other dialects
postgres> WITH t AS (SELECT '{"a": {"A": 1}, "A": {"a": 2}}'::JSON AS col) SELECT col.a.A, col.A.a from t;
ERROR: missing FROM-clause entry for table "a"
postgres> WITH t AS (SELECT '{"a": {"A": 1}, "A": {"a": 2}}'::JSON AS col) SELECT col->a->A, col->A->a from t;
ERROR: column "a" does not exist
^
postgres> WITH t AS (SELECT '{"a": {"A": 1}, "A": {"a": 2}}'::JSON AS col) SELECT col->'a'->'A', col->'A'->'a' from t;
?column? | ?column?
----------+----------
1 | 2
(1 row)
trino> WITH t AS (SELECT CAST('{"a": {"A": 1}, "A": {"a": 2}}' AS JSON) AS col) SELECT col.a.A, col.A.a from t;
Query 20251114_094456_00003_maqp5 failed: line 1:81: Expression col is not of type ROW |
Collaborator
|
Nice work @VaggelisD, seems like Toby's hunch was right. Let's get rid of the flag and just assume that JSON values will always have case-sensitive keys. |
Co-authored-by: Jo <46752250+georgesittas@users.noreply.github.com>
georgesittas
approved these changes
Nov 14, 2025
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.
In BigQuery,
JSONfield lookups in dot notation are case sensitive, e.g:However, up until this point SQLGlot normalized all BigQuery identifiers as case insensitive which is valid for
STRUCTlookups or other identifiers but may alter the semantics of these JSON accesses.This PR fixes this behavior through the following steps:
normalize_identifiers: Preserve the original column+dot parts in the column'smetaqualify_columns: Distinguish the column from the dot parts i.e keeping only the latter in themetaannotate_types: Once all of the types are fully known, traverseJSONcolumns upwards to revert/repair the dot parts