Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions sqlglot/dialects/e6.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3010,7 +3010,14 @@ def _render_variant_colon(self, root, segments) -> str:
sql += f":[{seg.this}]"
elif isinstance(seg, exp.JSONPathKey):
key = seg.this
if key in self.RESERVED_DATATYPE_KEYWORDS or seg.args.get("escape"):
# E6's colon-path grammar rejects a bare reserved word after ':', so any
# E6 reserved word (not just a datatype keyword, e.g. LIMIT/FROM/ORDER)
# must be double-quoted: col:"limit".
if (
key in self.RESERVED_DATATYPE_KEYWORDS
or (isinstance(key, str) and key.lower() in self.RESERVED_KEYWORDS)
or seg.args.get("escape")
):
sql += f':"{key}"'
else:
sql += f":{key}"
Expand DownExpand Up@@ -3041,12 +3048,19 @@ def json_extract_sql(self, e: exp.JSONExtract | exp.JSONExtractScalar):
and isinstance(path_expressions[1], exp.JSONPathKey)
):
path_key = path_expressions[1].this
if path_key in self.RESERVED_DATATYPE_KEYWORDS:
# E6's colon-path grammar rejects a bare reserved word after ':', so
# any E6 reserved word (not just a datatype keyword, e.g.
# LIMIT/FROM/ORDER) must be double-quoted: col:"limit".
if (
path_key in self.RESERVED_DATATYPE_KEYWORDS
or (
isinstance(path_key, str)
and path_key.lower() in self.RESERVED_KEYWORDS
)
or e.expression.args.get("escape")
):
return f'{self.sql(e.this)}:"{path_key}"'
else:
if e.expression.args.get("escape"):
return f'{self.sql(e.this)}:"{path_key}"'
return f"{self.sql(e.this)}:{path_key}"
return f"{self.sql(e.this)}:{path_key}"
# Fallback if not JSONPath format
elif isinstance(e.expression, exp.Literal):
return f"{self.sql(e.this)}:{e.expression.this}"
Expand Down
15 changes: 15 additions & 0 deletions tests/dialects/test_e6.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,21 @@ def test_E6(self):
},
)

# E6's colon-path grammar rejects a bare reserved word after ':' (e.g. LIMIT / ORDER /
# FROM), so those keys must be double-quoted; non-reserved keys stay bare.
self.validate_all(
'SELECT properties:"limit" FROM source',
read={"databricks": "SELECT properties:limit FROM source"},
)
self.validate_all(
'SELECT properties:"order" FROM source',
read={"databricks": "SELECT properties:order FROM source"},
)
self.validate_all(
"SELECT properties:geojson FROM source",
read={"databricks": "SELECT properties:geojson FROM source"},
)

self.validate_all(
"SELECT FIRST_VALUE(zone) AS zone FROM filtered_zones",
read={"databricks": "SELECT FIRST(zone) AS zone FROM filtered_zones"},
Expand Down
Loading