Skip to content

Commit

Permalink
these low cardinality bits are everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
fuziontech committed Dec 20, 2023
1 parent e1bd7c1 commit 3db7134
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions posthog/session_recordings/sql/session_replay_event_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'),
Expand All @@ -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
Expand Down

0 comments on commit 3db7134

Please sign in to comment.