Skip to content

Commit d1e1baa

Browse files
authored
Generate ON CLUSTER for transpiled CREATE SCHEMA (tobymao#3993)
1 parent 905b722 commit d1e1baa

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

sqlglot/dialects/clickhouse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ class Generator(generator.Generator):
892892
# There's no list in docs, but it can be found in Clickhouse code
893893
# see `ClickHouse/src/Parsers/ParserCreate*.cpp`
894894
ON_CLUSTER_TARGETS = {
895+
"SCHEMA", # Transpiled CREATE SCHEMA may have OnCluster property set
895896
"DATABASE",
896897
"TABLE",
897898
"VIEW",

tests/dialects/test_clickhouse.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,14 @@ def test_ddl(self):
622622
)
623623
self.assertEqual(create_with_cluster.sql("clickhouse"), "CREATE DATABASE foo ON CLUSTER c")
624624

625+
# Transpiled CREATE SCHEMA may have OnCluster property set
626+
create_with_cluster = exp.Create(
627+
this=db_table_expr,
628+
kind="SCHEMA",
629+
properties=exp.Properties(expressions=[exp.OnCluster(this=exp.to_identifier("c"))]),
630+
)
631+
self.assertEqual(create_with_cluster.sql("clickhouse"), "CREATE DATABASE foo ON CLUSTER c")
632+
625633
ctas_with_comment = exp.Create(
626634
this=exp.table_("foo"),
627635
kind="TABLE",

0 commit comments

Comments
 (0)