Skip to content
Open
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
3 changes: 2 additions & 1 deletion sqlmesh/core/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,8 @@ def format_model_expressions(
if rewrite_casts:

def cast_to_colon(node: exp.Expr) -> exp.Expr:
if isinstance(node, exp.Cast) and not any(
# Directly check type instead of isinstance to avoid rewriting subclasses of CAST, e.g. JSONCast
if type(node) is exp.Cast and not any(
# Only convert CAST into :: if it doesn't have additional args set, otherwise this
# conversion could alter the semantics (eg. changing SAFE_CAST in BigQuery to CAST)
arg
Expand Down
23 changes: 23 additions & 0 deletions tests/core/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,29 @@ def test_format_model_expressions():
SAFE_CAST('bla' AS INT64) AS FOO"""
)

x = format_model_expressions(
parse(
"""
MODEL(name a.b, kind FULL, dialect clickhouse);
SELECT data.:String AS foo, CAST(1 AS INT) AS bar
"""
),
dialect="clickhouse",
)
# JSONCast (e.g. `.:` syntax in ClickHouse) must not be written to `::`
assert (
x
== """MODEL (
name a.b,
kind FULL,
dialect clickhouse
);

SELECT
data.:String AS foo,
1::Int32 AS bar"""
)

x = format_model_expressions(
parse(
"""
Expand Down