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
2 changes: 1 addition & 1 deletion sqlmesh/core/engine_adapter/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ def _build_table_properties_exp(
primary_key_vals = []
if isinstance(primary_key, (exp.Tuple, exp.Array)):
primary_key_vals = primary_key.expressions
if isinstance(ordered_by_raw, exp.Paren):
if isinstance(primary_key, exp.Paren):
primary_key_vals = [primary_key.this]

if not primary_key_vals:
Expand Down
14 changes: 14 additions & 0 deletions tests/core/engine_adapter/test_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,20 @@ def build_properties_sql(storage_format="", order_by="", primary_key="", propert
== "ENGINE=MergeTree ORDER BY (a) PRIMARY KEY (a)"
)

# A parenthesized single-column PRIMARY_KEY must be unwrapped regardless of the
# ORDER_BY shape. Previously the PRIMARY_KEY branch checked ORDER_BY's expression,
# so pairing PRIMARY_KEY = (a) with a non-parenthesized ORDER_BY emitted the
# malformed "PRIMARY KEY ((a))".
assert (
build_properties_sql(order_by="ORDER_BY = a,", primary_key="PRIMARY_KEY = (a)")
== "ENGINE=MergeTree ORDER BY (a) PRIMARY KEY (a)"
)

assert (
build_properties_sql(order_by="ORDER_BY = (a, b),", primary_key="PRIMARY_KEY = (a)")
== "ENGINE=MergeTree ORDER BY (a, b) PRIMARY KEY (a)"
)

assert build_properties_sql(order_by="ORDER_BY = a + 1,") == "ENGINE=MergeTree ORDER BY (a + 1)"

assert (
Expand Down