:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix: mergetree settings on query_log_archive (#63245)
Paweł Szczurf37c7d2d1a4e
diff --git a/posthog/clickhouse/query_log_archive.py b/posthog/clickhouse/query_log_archive.pyindex 74283994a1e5..e73376a363f9 100644--- a/posthog/clickhouse/query_log_archive.py+++ b/posthog/clickhouse/query_log_archive.py@@ -692,7 +692,9 @@ ORDER BY (team_id, event_date, event_time, query_id)PRIMARY KEY (team_id, event_date, event_time, query_id)"""-def QUERY_LOG_ARCHIVE_OPS_TABLE_SQL(table_name, engine, include_aliases=True, include_table_clauses=True):+def QUERY_LOG_ARCHIVE_OPS_TABLE_SQL(+ table_name, engine, include_aliases=True, include_table_clauses=True, settings=None+):"""JSON-backed query_log_archive table.include_aliases=True for the data table and read tables (exposes lc_* / ProfileEvents_*).@@ -701,11 +703,12 @@ def QUERY_LOG_ARCHIVE_OPS_TABLE_SQL(table_name, engine, include_aliases=True, incolumns = _QUERY_LOG_ARCHIVE_PHYSICAL_COLUMNSif include_aliases:columns = f"{columns},\n{_QUERY_LOG_ARCHIVE_ALIAS_COLUMNS}"- return "CREATE TABLE IF NOT EXISTS {table_name} (\n{columns}\n) ENGINE = {engine}{table_clauses}".format(+ return "CREATE TABLE IF NOT EXISTS {table_name} (\n{columns}\n) ENGINE = {engine}{table_clauses} {settings}".format(table_name=table_name,columns=columns,engine=engine,table_clauses=_QUERY_LOG_ARCHIVE_OPS_TABLE_CLAUSES if include_table_clauses else "",+ settings=settings if settings else "",)@@ -718,6 +721,7 @@ def SHARDED_QUERY_LOG_ARCHIVE_OPS_TABLE_SQL():return QUERY_LOG_ARCHIVE_OPS_TABLE_SQL(table_name=SHARDED_QUERY_LOG_ARCHIVE_TABLE,engine=SHARDED_QUERY_LOG_ARCHIVE_OPS_ENGINE(),+ settings="SETTINGS object_shared_data_serialization_version='map_with_buckets',object_serialization_version='v3'",)diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex 3ad2966ff349..9a6d2a3d747d 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -3994,7 +3994,7 @@lc_dagster__owner String ALIAS log_comment.`dagster.tags.owner`::String,lc_modifiers String ALIAS if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')- ) ENGINE = Distributed('ops', 'posthog_test', 'sharded_query_log_archive')+ ) ENGINE = Distributed('ops', 'posthog_test', 'sharded_query_log_archive')'''# ---# name: test_create_table_query[raw_error_tracking_fingerprint_issue_state]@@ -5935,7 +5935,7 @@) ENGINE = ReplicatedMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.sharded_query_log_archive', '{replica}-{shard}')PARTITION BY toYYYYMM(event_date)ORDER BY (team_id, event_date, event_time, query_id)- PRIMARY KEY (team_id, event_date, event_time, query_id)+ PRIMARY KEY (team_id, event_date, event_time, query_id) SETTINGS object_shared_data_serialization_version='map_with_buckets',object_serialization_version='v3''''# ---# name: test_create_table_query[sharded_raw_sessions]@@ -7758,7 +7758,7 @@SKIP cache_key),ProfileEvents Map(String, UInt64)- ) ENGINE = Distributed('ops', 'posthog_test', 'sharded_query_log_archive')+ ) ENGINE = Distributed('ops', 'posthog_test', 'sharded_query_log_archive')'''# ---# name: test_create_table_query[writable_raw_sessions]@@ -9937,7 +9937,7 @@) ENGINE = ReplicatedMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.sharded_query_log_archive', '{replica}-{shard}')PARTITION BY toYYYYMM(event_date)ORDER BY (team_id, event_date, event_time, query_id)- PRIMARY KEY (team_id, event_date, event_time, query_id)+ PRIMARY KEY (team_id, event_date, event_time, query_id) SETTINGS object_shared_data_serialization_version='map_with_buckets',object_serialization_version='v3''''# ---# name: test_create_table_query_replicated_and_storage[sharded_raw_sessions]