Skip to content

Commit

Permalink
format replicated
Browse files Browse the repository at this point in the history
  • Loading branch information
raubitsj committed Dec 11, 2024
1 parent a66146d commit 647e1e0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion weave/trace_server/clickhouse_trace_server_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
from typing import Optional
import re

from clickhouse_connect.driver.client import Client as CHClient

Expand Down Expand Up @@ -40,7 +41,24 @@ def __init__(
self._initialize_migration_db()

def _format_replicated_sql(self, sql_query: str) -> str:
return sql_query
"""Format SQL query to use replicated engines if replicated mode is enabled.
Converts MergeTree engine variants to their Replicated counterparts:
- MergeTree -> ReplicatedMergeTree
- SummingMergeTree -> ReplicatedSummingMergeTree
- etc.
"""
if not self.replicated:
return sql_query

# Match "ENGINE = <optional words>MergeTree" followed by word boundary
pattern = r'ENGINE\s*=\s*(\w+)?MergeTree\b'

def replace_engine(match):
engine_prefix = match.group(1) or ""
return f'ENGINE = Replicated{engine_prefix}MergeTree'

return re.sub(pattern, replace_engine, sql_query, flags=re.IGNORECASE)

def _create_db_sql(self, db_name: str) -> str:
replicated_engine = ""
Expand Down

0 comments on commit 647e1e0

Please sign in to comment.