From 5cd630331959c30fd8ef6ff9cae5d606dfd95587 Mon Sep 17 00:00:00 2001 From: Meredith Heller Date: Mon, 2 Feb 2026 16:49:00 -0800 Subject: [PATCH] fix(admin): add quotes around cluster name in ON CLUSTER clause The ON CLUSTER clause in ClickHouse requires the cluster name to be quoted. Updated the table copy logic to wrap cluster_name in single quotes and updated corresponding tests to match the expected output. Co-Authored-By: Claude Sonnet 4.5 --- snuba/admin/clickhouse/copy_tables.py | 2 +- tests/admin/clickhouse/test_copy_tables.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/snuba/admin/clickhouse/copy_tables.py b/snuba/admin/clickhouse/copy_tables.py index 1e8cca99c4..8e73a38ee5 100644 --- a/snuba/admin/clickhouse/copy_tables.py +++ b/snuba/admin/clickhouse/copy_tables.py @@ -59,7 +59,7 @@ def get_create_table_statements( if cluster_name: table_statement = table_statement.replace( - db_table, f"{db_table} ON CLUSTER {cluster_name}" + db_table, f"{db_table} ON CLUSTER '{cluster_name}'" ) table_statements.append( diff --git a/tests/admin/clickhouse/test_copy_tables.py b/tests/admin/clickhouse/test_copy_tables.py index 47cd6bb795..e8a9f90fbb 100644 --- a/tests/admin/clickhouse/test_copy_tables.py +++ b/tests/admin/clickhouse/test_copy_tables.py @@ -13,7 +13,7 @@ from snuba.migrations.groups import MigrationGroup OUTCOMES_DAILY_TABLE = """ -CREATE TABLE IF NOT EXISTS {db}.outcomes_daily_local_v2 ON CLUSTER test_cluster +CREATE TABLE IF NOT EXISTS {db}.outcomes_daily_local_v2 ON CLUSTER 'test_cluster' ( `org_id` UInt64, `project_id` UInt64, @@ -33,7 +33,7 @@ """ OUTCOMES_DAILY_MV = """ -CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.outcomes_mv_daily_local_v2 ON CLUSTER test_cluster TO {db}.outcomes_daily_local_v2 +CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.outcomes_mv_daily_local_v2 ON CLUSTER 'test_cluster' TO {db}.outcomes_daily_local_v2 ( `org_id` UInt64, `project_id` UInt64,