diff --git a/posthog/session_recordings/sql/session_replay_event_sql.py b/posthog/session_recordings/sql/session_replay_event_sql.py index 76b00794329d7..b67e5106b42fc 100644 --- a/posthog/session_recordings/sql/session_replay_event_sql.py +++ b/posthog/session_recordings/sql/session_replay_event_sql.py @@ -109,7 +109,8 @@ engine=kafka_engine(topic=KAFKA_CLICKHOUSE_SESSION_REPLAY_EVENTS), ) -SESSION_REPLAY_EVENTS_TABLE_MV_SQL = lambda: """ +SESSION_REPLAY_EVENTS_TABLE_MV_SQL = ( + lambda: """ CREATE MATERIALIZED VIEW IF NOT EXISTS session_replay_events_mv ON CLUSTER '{cluster}' TO {database}.{target_table} {explictly_specify_columns} AS SELECT @@ -144,13 +145,13 @@ FROM {database}.kafka_session_replay_events group by session_id, team_id """.format( - target_table="writable_session_replay_events", - cluster=settings.CLICKHOUSE_CLUSTER, - database=settings.CLICKHOUSE_DATABASE, - # ClickHouse is incorrectly expanding the type of the snapshot source column - # Despite it being a LowCardinality(Nullable(String)) in writable_session_replay_events - # The column expansion picks only Nullable(String) and so we can't select it - explictly_specify_columns="""( + target_table="writable_session_replay_events", + cluster=settings.CLICKHOUSE_CLUSTER, + database=settings.CLICKHOUSE_DATABASE, + # ClickHouse is incorrectly expanding the type of the snapshot source column + # Despite it being a LowCardinality(Nullable(String)) in writable_session_replay_events + # The column expansion picks only Nullable(String) and so we can't select it + explictly_specify_columns="""( `session_id` String, `team_id` Int64, `distinct_id` String, `min_first_timestamp` DateTime64(6, 'UTC'), `max_last_timestamp` DateTime64(6, 'UTC'), @@ -160,9 +161,10 @@ `console_log_count` Int64, `console_warn_count` Int64, `console_error_count` Int64, `size` Int64, `message_count` Int64, `event_count` Int64, -`snapshot_source` AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')), +`snapshot_source` AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')), `_timestamp` Nullable(DateTime) )""", + ) ) # Distributed engine tables are only created if CLICKHOUSE_REPLICATED