: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
feat(sessions): flatten sessions v3 flag values into a k=v array (#102710)
Andy Zhao2aa2fd01799e
diff --git a/posthog/clickhouse/hcl/golden/dev/data.hcl b/posthog/clickhouse/hcl/golden/dev/data.hclindex 0b32f78ba54c..850131e0f0ad 100644--- a/posthog/clickhouse/hcl/golden/dev/data.hcl+++ b/posthog/clickhouse/hcl/golden/dev/data.hcl@@ -3853,6 +3853,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -3862,6 +3865,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}@@ -6336,6 +6345,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -6345,6 +6357,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}@@ -6358,6 +6376,21 @@ database "posthog" {type = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }+ index "hosts_bloom_filter" {+ expr = "hosts"+ type = "bloom_filter()"+ granularity = 1+ }+ index "emails_bloom_filter" {+ expr = "emails"+ type = "bloom_filter()"+ granularity = 1+ }engine "replicated_aggregating_merge_tree" {zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions_v3"replica_name = "{replica}"@@ -8335,6 +8368,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -8344,6 +8380,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}@@ -9492,12 +9534,11 @@ SELECTsession_timestamp,team_id,argMaxMerge(distinct_id) AS distinct_id,- argMaxMerge(person_id) AS person_id,groupUniqArrayMerge(distinct_ids) AS distinct_ids,min(min_timestamp) AS min_timestamp,max(max_timestamp) AS max_timestamp,max(max_inserted_at) AS max_inserted_at,- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,+ groupUniqArrayArray(2000)(urls) AS urls,argMinMerge(entry_url) AS entry_url,argMaxMerge(end_url) AS end_url,argMaxMerge(last_external_click_url) AS last_external_click_url,@@ -9530,8 +9571,14 @@ SELECTuniqExactMerge(pageview_uniq) AS pageview_uniq,uniqExactMerge(autocapture_uniq) AS autocapture_uniq,uniqExactMerge(screen_uniq) AS screen_uniq,- uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,- groupUniqArrayMapMerge(flag_values) AS flag_values+ uniqUpToMerge(1)(page_screen_uniq_up_to) AS page_screen_uniq_up_to,+ max(has_autocapture) AS has_autocapture,+ groupUniqArrayArray(10000)(flag_key_values) AS flag_key_values,+ groupUniqArrayArray(flag_keys) AS flag_keys,+ groupUniqArrayArray(2000)(event_names) AS event_names,+ groupUniqArrayArray(100)(hosts) AS hosts,+ groupUniqArrayArray(10)(emails) AS emails,+ max(has_replay_events) AS has_replay_eventsFROM posthog.raw_sessions_v3GROUP BYsession_id_v7, session_timestamp, team_iddiff --git a/posthog/clickhouse/hcl/golden/dev/sessions.hcl b/posthog/clickhouse/hcl/golden/dev/sessions.hclindex af32c5fcfe00..9087beb485a6 100644--- a/posthog/clickhouse/hcl/golden/dev/sessions.hcl+++ b/posthog/clickhouse/hcl/golden/dev/sessions.hcl@@ -994,6 +994,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -1022,6 +1025,11 @@ database "posthog" {type = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }engine "replicated_aggregating_merge_tree" {zoo_path = "/clickhouse/tables/sessions/noshard/posthog.raw_sessions_v3"replica_name = "{shard}-{replica}"diff --git a/posthog/clickhouse/hcl/golden/local-multi/data.hcl b/posthog/clickhouse/hcl/golden/local-multi/data.hclindex e0da94dd2c98..66e006e13f0c 100644--- a/posthog/clickhouse/hcl/golden/local-multi/data.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/data.hcl@@ -4516,8 +4516,8 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}- column "flag_values" {- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"}column "flag_keys" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"@@ -7629,8 +7629,8 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}- column "flag_values" {- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"}column "flag_keys" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"@@ -7652,6 +7652,11 @@ database "posthog" {type = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }index "flag_keys_bloom_filter" {expr = "flag_keys"type = "bloom_filter()"@@ -9837,8 +9842,8 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}- column "flag_values" {- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"}column "flag_keys" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"@@ -11943,7 +11948,7 @@ SELECTuniqExactMerge(screen_uniq) AS screen_uniq,uniqUpToMerge(1)(page_screen_uniq_up_to) AS page_screen_uniq_up_to,max(has_autocapture) AS has_autocapture,- groupUniqArrayMapMerge(flag_values) AS flag_values,+ groupUniqArrayArray(10000)(flag_key_values) AS flag_key_values,groupUniqArrayArray(flag_keys) AS flag_keys,groupUniqArrayArray(2000)(event_names) AS event_names,groupUniqArrayArray(100)(hosts) AS hosts,diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hclindex bea9cff497a6..b20e4fb708d4 100644--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl@@ -9436,8 +9436,8 @@ SQLcolumn "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}- column "flag_values" {- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"}column "flag_keys" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"@@ -13529,8 +13529,8 @@ SQLcolumn "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}- column "flag_values" {- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"}column "flag_keys" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"@@ -13552,6 +13552,11 @@ SQLtype = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }index "flag_keys_bloom_filter" {expr = "flag_keys"type = "bloom_filter()"@@ -18130,8 +18135,8 @@ SQLcolumn "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}- column "flag_values" {- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"}column "flag_keys" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"@@ -24758,7 +24763,7 @@ SELECTuniqExactMerge(screen_uniq) AS screen_uniq,uniqUpToMerge(1)(page_screen_uniq_up_to) AS page_screen_uniq_up_to,max(has_autocapture) AS has_autocapture,- groupUniqArrayMapMerge(flag_values) AS flag_values,+ groupUniqArrayArray(10000)(flag_key_values) AS flag_key_values,groupUniqArrayArray(flag_keys) AS flag_keys,groupUniqArrayArray(2000)(event_names) AS event_names,groupUniqArrayArray(100)(hosts) AS hosts,diff --git a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl b/posthog/clickhouse/hcl/golden/prod-eu/data.hclindex e07cfe65e43f..853458680d9e 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl@@ -4498,6 +4498,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -4507,6 +4510,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}@@ -6334,6 +6343,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -6343,6 +6355,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}@@ -6356,6 +6374,21 @@ database "posthog" {type = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }+ index "hosts_bloom_filter" {+ expr = "hosts"+ type = "bloom_filter()"+ granularity = 1+ }+ index "emails_bloom_filter" {+ expr = "emails"+ type = "bloom_filter()"+ granularity = 1+ }engine "replicated_aggregating_merge_tree" {zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions_v3"replica_name = "{replica}"@@ -8582,6 +8615,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -9924,12 +9960,11 @@ SELECTsession_timestamp,team_id,argMaxMerge(distinct_id) AS distinct_id,- argMaxMerge(person_id) AS person_id,groupUniqArrayMerge(distinct_ids) AS distinct_ids,min(min_timestamp) AS min_timestamp,max(max_timestamp) AS max_timestamp,max(max_inserted_at) AS max_inserted_at,- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,+ groupUniqArrayArray(2000)(urls) AS urls,argMinMerge(entry_url) AS entry_url,argMaxMerge(end_url) AS end_url,argMaxMerge(last_external_click_url) AS last_external_click_url,@@ -9962,8 +9997,14 @@ SELECTuniqExactMerge(pageview_uniq) AS pageview_uniq,uniqExactMerge(autocapture_uniq) AS autocapture_uniq,uniqExactMerge(screen_uniq) AS screen_uniq,- uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,- groupUniqArrayMapMerge(flag_values) AS flag_values+ uniqUpToMerge(1)(page_screen_uniq_up_to) AS page_screen_uniq_up_to,+ max(has_autocapture) AS has_autocapture,+ groupUniqArrayArray(10000)(flag_key_values) AS flag_key_values,+ groupUniqArrayArray(flag_keys) AS flag_keys,+ groupUniqArrayArray(2000)(event_names) AS event_names,+ groupUniqArrayArray(100)(hosts) AS hosts,+ groupUniqArrayArray(10)(emails) AS emails,+ max(has_replay_events) AS has_replay_eventsFROM posthog.raw_sessions_v3GROUP BYsession_id_v7, session_timestamp, team_iddiff --git a/posthog/clickhouse/hcl/golden/prod-eu/sessions.hcl b/posthog/clickhouse/hcl/golden/prod-eu/sessions.hclindex 51bb00c74530..e2acb0aab18f 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/sessions.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/sessions.hcl@@ -990,6 +990,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -1018,6 +1021,11 @@ database "posthog" {type = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }engine "replicated_aggregating_merge_tree" {zoo_path = "/clickhouse/tables/sessions/noshard/posthog.raw_sessions_v3"replica_name = "{shard}-{replica}"diff --git a/posthog/clickhouse/hcl/golden/prod-us/data.hcl b/posthog/clickhouse/hcl/golden/prod-us/data.hclindex 1954d4436992..d2900001eb26 100644--- a/posthog/clickhouse/hcl/golden/prod-us/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/data.hcl@@ -4293,6 +4293,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -4302,6 +4305,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}@@ -6174,6 +6183,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -6183,6 +6195,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}@@ -6196,6 +6214,21 @@ database "posthog" {type = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }+ index "hosts_bloom_filter" {+ expr = "hosts"+ type = "bloom_filter()"+ granularity = 1+ }+ index "emails_bloom_filter" {+ expr = "emails"+ type = "bloom_filter()"+ granularity = 1+ }engine "replicated_aggregating_merge_tree" {zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.raw_sessions_v3"replica_name = "{replica}"@@ -8404,6 +8437,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -9709,12 +9745,11 @@ SELECTsession_timestamp,team_id,argMaxMerge(distinct_id) AS distinct_id,- argMaxMerge(person_id) AS person_id,groupUniqArrayMerge(distinct_ids) AS distinct_ids,min(min_timestamp) AS min_timestamp,max(max_timestamp) AS max_timestamp,max(max_inserted_at) AS max_inserted_at,- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,+ groupUniqArrayArray(2000)(urls) AS urls,argMinMerge(entry_url) AS entry_url,argMaxMerge(end_url) AS end_url,argMaxMerge(last_external_click_url) AS last_external_click_url,@@ -9747,8 +9782,14 @@ SELECTuniqExactMerge(pageview_uniq) AS pageview_uniq,uniqExactMerge(autocapture_uniq) AS autocapture_uniq,uniqExactMerge(screen_uniq) AS screen_uniq,- uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,- groupUniqArrayMapMerge(flag_values) AS flag_values+ uniqUpToMerge(1)(page_screen_uniq_up_to) AS page_screen_uniq_up_to,+ max(has_autocapture) AS has_autocapture,+ groupUniqArrayArray(10000)(flag_key_values) AS flag_key_values,+ groupUniqArrayArray(flag_keys) AS flag_keys,+ groupUniqArrayArray(2000)(event_names) AS event_names,+ groupUniqArrayArray(100)(hosts) AS hosts,+ groupUniqArrayArray(10)(emails) AS emails,+ max(has_replay_events) AS has_replay_eventsFROM posthog.raw_sessions_v3GROUP BYsession_id_v7, session_timestamp, team_iddiff --git a/posthog/clickhouse/hcl/golden/prod-us/sessions.hcl b/posthog/clickhouse/hcl/golden/prod-us/sessions.hclindex 27ec5381379e..0b19439c0b0c 100644--- a/posthog/clickhouse/hcl/golden/prod-us/sessions.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/sessions.hcl@@ -1001,6 +1001,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -1029,6 +1032,11 @@ database "posthog" {type = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }engine "replicated_aggregating_merge_tree" {zoo_path = "/clickhouse/tables/sessions/noshard/posthog.raw_sessions_v3"replica_name = "{shard}-{replica}"diff --git a/posthog/clickhouse/hcl/roles/data/cloud/tables.hcl b/posthog/clickhouse/hcl/roles/data/cloud/tables.hclindex 65ed2da2b680..daa3ab21931e 100644--- a/posthog/clickhouse/hcl/roles/data/cloud/tables.hcl+++ b/posthog/clickhouse/hcl/roles/data/cloud/tables.hcl@@ -441,6 +441,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -450,6 +453,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}@@ -1075,6 +1084,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -1084,6 +1096,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}diff --git a/posthog/clickhouse/hcl/roles/data/common/shared_declarations.hcl b/posthog/clickhouse/hcl/roles/data/common/shared_declarations.hclindex e84a48d7df05..df8fe4134109 100644--- a/posthog/clickhouse/hcl/roles/data/common/shared_declarations.hcl+++ b/posthog/clickhouse/hcl/roles/data/common/shared_declarations.hcl@@ -994,8 +994,8 @@ SQLcolumn "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}- column "flag_values" {- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"}column "flag_keys" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"@@ -1066,7 +1066,7 @@ SELECTuniqExactMerge(screen_uniq) AS screen_uniq,uniqUpToMerge(1)(page_screen_uniq_up_to) AS page_screen_uniq_up_to,max(has_autocapture) AS has_autocapture,- groupUniqArrayMapMerge(flag_values) AS flag_values,+ groupUniqArrayArray(10000)(flag_key_values) AS flag_key_values,groupUniqArrayArray(flag_keys) AS flag_keys,groupUniqArrayArray(2000)(event_names) AS event_names,groupUniqArrayArray(100)(hosts) AS hosts,@@ -1362,8 +1362,8 @@ SQLcolumn "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}- column "flag_values" {- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"}column "flag_keys" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"@@ -1385,6 +1385,11 @@ SQLtype = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }index "flag_keys_bloom_filter" {expr = "flag_keys"type = "bloom_filter()"@@ -2057,8 +2062,8 @@ SQLcolumn "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}- column "flag_values" {- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"}column "flag_keys" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"diff --git a/posthog/clickhouse/hcl/roles/data/dev/tables.hcl b/posthog/clickhouse/hcl/roles/data/dev/tables.hclindex 6e5bc9b63dda..e91470263ce3 100644--- a/posthog/clickhouse/hcl/roles/data/dev/tables.hcl+++ b/posthog/clickhouse/hcl/roles/data/dev/tables.hcl@@ -1205,6 +1205,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -1214,6 +1217,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}@@ -1227,6 +1236,21 @@ database "posthog" {type = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }+ index "hosts_bloom_filter" {+ expr = "hosts"+ type = "bloom_filter()"+ granularity = 1+ }+ index "emails_bloom_filter" {+ expr = "emails"+ type = "bloom_filter()"+ granularity = 1+ }engine "replicated_aggregating_merge_tree" {zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions_v3"replica_name = "{replica}"@@ -2079,60 +2103,6 @@ SQL}}- view "raw_sessions_v3_v" {- override = true- query = <<SQL-SELECT- session_id_v7,- session_timestamp,- team_id,- argMaxMerge(distinct_id) AS distinct_id,- argMaxMerge(person_id) AS person_id,- groupUniqArrayMerge(distinct_ids) AS distinct_ids,- min(min_timestamp) AS min_timestamp,- max(max_timestamp) AS max_timestamp,- max(max_inserted_at) AS max_inserted_at,- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,- argMinMerge(entry_url) AS entry_url,- argMaxMerge(end_url) AS end_url,- argMaxMerge(last_external_click_url) AS last_external_click_url,- argMinMerge(browser) AS browser,- argMinMerge(browser_version) AS browser_version,- argMinMerge(os) AS os,- argMinMerge(os_version) AS os_version,- argMinMerge(device_type) AS device_type,- argMinMerge(viewport_width) AS viewport_width,- argMinMerge(viewport_height) AS viewport_height,- argMinMerge(geoip_country_code) AS geoip_country_code,- argMinMerge(geoip_subdivision_1_code) AS geoip_subdivision_1_code,- argMinMerge(geoip_subdivision_1_name) AS geoip_subdivision_1_name,- argMinMerge(geoip_subdivision_city_name) AS geoip_subdivision_city_name,- argMinMerge(geoip_time_zone) AS geoip_time_zone,- argMinMerge(entry_utm_source) AS entry_utm_source,- argMinMerge(entry_utm_campaign) AS entry_utm_campaign,- argMinMerge(entry_utm_medium) AS entry_utm_medium,- argMinMerge(entry_utm_term) AS entry_utm_term,- argMinMerge(entry_utm_content) AS entry_utm_content,- argMinMerge(entry_referring_domain) AS entry_referring_domain,- argMinMerge(entry_gclid) AS entry_gclid,- argMinMerge(entry_gad_source) AS entry_gad_source,- argMinMerge(entry_fbclid) AS entry_fbclid,- argMinMerge(entry_has_gclid) AS entry_has_gclid,- argMinMerge(entry_has_fbclid) AS entry_has_fbclid,- argMinMerge(entry_ad_ids_map) AS entry_ad_ids_map,- argMinMerge(entry_ad_ids_set) AS entry_ad_ids_set,- argMinMerge(entry_channel_type_properties) AS entry_channel_type_properties,- uniqExactMerge(pageview_uniq) AS pageview_uniq,- uniqExactMerge(autocapture_uniq) AS autocapture_uniq,- uniqExactMerge(screen_uniq) AS screen_uniq,- uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,- groupUniqArrayMapMerge(flag_values) AS flag_values-FROM posthog.raw_sessions_v3-GROUP BY- session_id_v7, session_timestamp, team_id-SQL-- }view "sessions_v" {override = truediff --git a/posthog/clickhouse/hcl/roles/data/prod-eu/tables.hcl b/posthog/clickhouse/hcl/roles/data/prod-eu/tables.hclindex 702fe37c8a6d..306c500007f7 100644--- a/posthog/clickhouse/hcl/roles/data/prod-eu/tables.hcl+++ b/posthog/clickhouse/hcl/roles/data/prod-eu/tables.hcl@@ -749,6 +749,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -758,6 +761,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}@@ -771,6 +780,21 @@ database "posthog" {type = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }+ index "hosts_bloom_filter" {+ expr = "hosts"+ type = "bloom_filter()"+ granularity = 1+ }+ index "emails_bloom_filter" {+ expr = "emails"+ type = "bloom_filter()"+ granularity = 1+ }engine "replicated_aggregating_merge_tree" {zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions_v3"replica_name = "{replica}"@@ -1945,14 +1969,6 @@ SQL}patch_table "writable_raw_sessions_v3" {- column "hosts" {- type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"- after = "event_names"- }- column "emails" {- type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"- after = "hosts"- }engine "distributed" {cluster_name = "sessions"remote_database = "posthog"@@ -2338,60 +2354,6 @@ SQL}}- view "raw_sessions_v3_v" {- override = true- query = <<SQL-SELECT- session_id_v7,- session_timestamp,- team_id,- argMaxMerge(distinct_id) AS distinct_id,- argMaxMerge(person_id) AS person_id,- groupUniqArrayMerge(distinct_ids) AS distinct_ids,- min(min_timestamp) AS min_timestamp,- max(max_timestamp) AS max_timestamp,- max(max_inserted_at) AS max_inserted_at,- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,- argMinMerge(entry_url) AS entry_url,- argMaxMerge(end_url) AS end_url,- argMaxMerge(last_external_click_url) AS last_external_click_url,- argMinMerge(browser) AS browser,- argMinMerge(browser_version) AS browser_version,- argMinMerge(os) AS os,- argMinMerge(os_version) AS os_version,- argMinMerge(device_type) AS device_type,- argMinMerge(viewport_width) AS viewport_width,- argMinMerge(viewport_height) AS viewport_height,- argMinMerge(geoip_country_code) AS geoip_country_code,- argMinMerge(geoip_subdivision_1_code) AS geoip_subdivision_1_code,- argMinMerge(geoip_subdivision_1_name) AS geoip_subdivision_1_name,- argMinMerge(geoip_subdivision_city_name) AS geoip_subdivision_city_name,- argMinMerge(geoip_time_zone) AS geoip_time_zone,- argMinMerge(entry_utm_source) AS entry_utm_source,- argMinMerge(entry_utm_campaign) AS entry_utm_campaign,- argMinMerge(entry_utm_medium) AS entry_utm_medium,- argMinMerge(entry_utm_term) AS entry_utm_term,- argMinMerge(entry_utm_content) AS entry_utm_content,- argMinMerge(entry_referring_domain) AS entry_referring_domain,- argMinMerge(entry_gclid) AS entry_gclid,- argMinMerge(entry_gad_source) AS entry_gad_source,- argMinMerge(entry_fbclid) AS entry_fbclid,- argMinMerge(entry_has_gclid) AS entry_has_gclid,- argMinMerge(entry_has_fbclid) AS entry_has_fbclid,- argMinMerge(entry_ad_ids_map) AS entry_ad_ids_map,- argMinMerge(entry_ad_ids_set) AS entry_ad_ids_set,- argMinMerge(entry_channel_type_properties) AS entry_channel_type_properties,- uniqExactMerge(pageview_uniq) AS pageview_uniq,- uniqExactMerge(autocapture_uniq) AS autocapture_uniq,- uniqExactMerge(screen_uniq) AS screen_uniq,- uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,- groupUniqArrayMapMerge(flag_values) AS flag_values-FROM posthog.raw_sessions_v3-GROUP BY- session_id_v7, session_timestamp, team_id-SQL-- }view "sessions_v" {override = truediff --git a/posthog/clickhouse/hcl/roles/data/prod-us/tables.hcl b/posthog/clickhouse/hcl/roles/data/prod-us/tables.hclindex cb6161a09f54..e5b310f1c25b 100644--- a/posthog/clickhouse/hcl/roles/data/prod-us/tables.hcl+++ b/posthog/clickhouse/hcl/roles/data/prod-us/tables.hcl@@ -814,6 +814,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -823,6 +826,12 @@ database "posthog" {column "event_names" {type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"}+ column "hosts" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"+ }+ column "emails" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"+ }column "has_replay_events" {type = "SimpleAggregateFunction(max, Bool)"}@@ -836,6 +845,21 @@ database "posthog" {type = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }+ index "hosts_bloom_filter" {+ expr = "hosts"+ type = "bloom_filter()"+ granularity = 1+ }+ index "emails_bloom_filter" {+ expr = "emails"+ type = "bloom_filter()"+ granularity = 1+ }engine "replicated_aggregating_merge_tree" {zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.raw_sessions_v3"replica_name = "{replica}"@@ -1645,14 +1669,6 @@ SQL}patch_table "writable_raw_sessions_v3" {- column "hosts" {- type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"- after = "event_names"- }- column "emails" {- type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"- after = "hosts"- }engine "distributed" {cluster_name = "sessions"remote_database = "posthog"@@ -2044,60 +2060,6 @@ SQL}}- view "raw_sessions_v3_v" {- override = true- query = <<SQL-SELECT- session_id_v7,- session_timestamp,- team_id,- argMaxMerge(distinct_id) AS distinct_id,- argMaxMerge(person_id) AS person_id,- groupUniqArrayMerge(distinct_ids) AS distinct_ids,- min(min_timestamp) AS min_timestamp,- max(max_timestamp) AS max_timestamp,- max(max_inserted_at) AS max_inserted_at,- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,- argMinMerge(entry_url) AS entry_url,- argMaxMerge(end_url) AS end_url,- argMaxMerge(last_external_click_url) AS last_external_click_url,- argMinMerge(browser) AS browser,- argMinMerge(browser_version) AS browser_version,- argMinMerge(os) AS os,- argMinMerge(os_version) AS os_version,- argMinMerge(device_type) AS device_type,- argMinMerge(viewport_width) AS viewport_width,- argMinMerge(viewport_height) AS viewport_height,- argMinMerge(geoip_country_code) AS geoip_country_code,- argMinMerge(geoip_subdivision_1_code) AS geoip_subdivision_1_code,- argMinMerge(geoip_subdivision_1_name) AS geoip_subdivision_1_name,- argMinMerge(geoip_subdivision_city_name) AS geoip_subdivision_city_name,- argMinMerge(geoip_time_zone) AS geoip_time_zone,- argMinMerge(entry_utm_source) AS entry_utm_source,- argMinMerge(entry_utm_campaign) AS entry_utm_campaign,- argMinMerge(entry_utm_medium) AS entry_utm_medium,- argMinMerge(entry_utm_term) AS entry_utm_term,- argMinMerge(entry_utm_content) AS entry_utm_content,- argMinMerge(entry_referring_domain) AS entry_referring_domain,- argMinMerge(entry_gclid) AS entry_gclid,- argMinMerge(entry_gad_source) AS entry_gad_source,- argMinMerge(entry_fbclid) AS entry_fbclid,- argMinMerge(entry_has_gclid) AS entry_has_gclid,- argMinMerge(entry_has_fbclid) AS entry_has_fbclid,- argMinMerge(entry_ad_ids_map) AS entry_ad_ids_map,- argMinMerge(entry_ad_ids_set) AS entry_ad_ids_set,- argMinMerge(entry_channel_type_properties) AS entry_channel_type_properties,- uniqExactMerge(pageview_uniq) AS pageview_uniq,- uniqExactMerge(autocapture_uniq) AS autocapture_uniq,- uniqExactMerge(screen_uniq) AS screen_uniq,- uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,- groupUniqArrayMapMerge(flag_values) AS flag_values-FROM posthog.raw_sessions_v3-GROUP BY- session_id_v7, session_timestamp, team_id-SQL-- }view "sessions_v" {override = truediff --git a/posthog/clickhouse/hcl/roles/sessions/shared/tables.hcl b/posthog/clickhouse/hcl/roles/sessions/shared/tables.hclindex c75cba8f6963..06d7130ad4f3 100644--- a/posthog/clickhouse/hcl/roles/sessions/shared/tables.hcl+++ b/posthog/clickhouse/hcl/roles/sessions/shared/tables.hcl@@ -412,6 +412,9 @@ database "posthog" {column "has_autocapture" {type = "SimpleAggregateFunction(max, Bool)"}+ column "flag_key_values" {+ type = "SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String))"+ }column "flag_values" {type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"}@@ -440,6 +443,11 @@ database "posthog" {type = "bloom_filter()"granularity = 1}+ index "flag_key_values_bloom_filter" {+ expr = "flag_key_values"+ type = "bloom_filter()"+ granularity = 1+ }engine "replicated_aggregating_merge_tree" {zoo_path = "/clickhouse/tables/sessions/noshard/posthog.raw_sessions_v3"replica_name = "{shard}-{replica}"diff --git a/posthog/clickhouse/hcl/sql/dev/data.sql b/posthog/clickhouse/hcl/sql/dev/data.sqlindex b8991ccd3e60..d52cb47cc124 100644--- a/posthog/clickhouse/hcl/sql/dev/data.sql+++ b/posthog/clickhouse/hcl/sql/dev/data.sql@@ -1348,12 +1348,18 @@ CREATE TABLE posthog.sharded_raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),+ hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),+ emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool),INDEX event_names_bloom_filter event_names TYPE bloom_filter() GRANULARITY 1,- INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1+ INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1,+ INDEX flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1,+ INDEX hosts_bloom_filter hosts TYPE bloom_filter() GRANULARITY 1,+ INDEX emails_bloom_filter emails TYPE bloom_filter() GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.raw_sessions_v3', '{replica}') ORDER BY (team_id, session_timestamp, session_id_v7) PARTITION BY toYYYYMM(session_timestamp) SETTINGS index_granularity = 8192;CREATE TABLE posthog.sharded_session_recording_events (uuid UUID,@@ -1963,9 +1969,12 @@ CREATE TABLE posthog.writable_raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),+ hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),+ emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool)) ENGINE = Distributed('posthog', 'posthog', 'sharded_raw_sessions_v3', cityHash64(session_id_v7));CREATE TABLE posthog.writable_session_recording_events (@@ -2711,9 +2720,12 @@ CREATE TABLE posthog.raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),+ hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),+ emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool)) ENGINE = Distributed('posthog', 'posthog', 'sharded_raw_sessions_v3', cityHash64(session_id_v7));CREATE TABLE posthog.session_recording_events (@@ -3031,12 +3043,11 @@ CREATE VIEW posthog.raw_sessions_v3_v AS SELECTsession_timestamp,team_id,argMaxMerge(distinct_id) AS distinct_id,- argMaxMerge(person_id) AS person_id,groupUniqArrayMerge(distinct_ids) AS distinct_ids,min(min_timestamp) AS min_timestamp,max(max_timestamp) AS max_timestamp,max(max_inserted_at) AS max_inserted_at,- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,+ groupUniqArrayArray(2000)(urls) AS urls,argMinMerge(entry_url) AS entry_url,argMaxMerge(end_url) AS end_url,argMaxMerge(last_external_click_url) AS last_external_click_url,@@ -3069,8 +3080,14 @@ CREATE VIEW posthog.raw_sessions_v3_v AS SELECTuniqExactMerge(pageview_uniq) AS pageview_uniq,uniqExactMerge(autocapture_uniq) AS autocapture_uniq,uniqExactMerge(screen_uniq) AS screen_uniq,- uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,- groupUniqArrayMapMerge(flag_values) AS flag_values+ uniqUpToMerge(1)(page_screen_uniq_up_to) AS page_screen_uniq_up_to,+ max(has_autocapture) AS has_autocapture,+ groupUniqArrayArray(10000)(flag_key_values) AS flag_key_values,+ groupUniqArrayArray(flag_keys) AS flag_keys,+ groupUniqArrayArray(2000)(event_names) AS event_names,+ groupUniqArrayArray(100)(hosts) AS hosts,+ groupUniqArrayArray(10)(emails) AS emails,+ max(has_replay_events) AS has_replay_eventsFROM posthog.raw_sessions_v3GROUP BYsession_id_v7, session_timestamp, team_id;diff --git a/posthog/clickhouse/hcl/sql/dev/sessions.sql b/posthog/clickhouse/hcl/sql/dev/sessions.sqlindex 2dc01b4d82fd..2bf1337b7a09 100644--- a/posthog/clickhouse/hcl/sql/dev/sessions.sql+++ b/posthog/clickhouse/hcl/sql/dev/sessions.sql@@ -294,6 +294,7 @@ CREATE TABLE posthog.raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),@@ -301,7 +302,8 @@ CREATE TABLE posthog.raw_sessions_v3 (emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool),INDEX event_names_bloom_filter event_names TYPE bloom_filter() GRANULARITY 1,- INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1+ INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1,+ INDEX flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/sessions/noshard/posthog.raw_sessions_v3', '{shard}-{replica}') ORDER BY (team_id, session_timestamp, session_id_v7) PARTITION BY toYYYYMM(session_timestamp) SETTINGS index_granularity = 8192, storage_policy = 's3_tiered';CREATE TABLE posthog.sessions (session_id String,diff --git a/posthog/clickhouse/hcl/sql/local-multi/data.sql b/posthog/clickhouse/hcl/sql/local-multi/data.sqlindex 870b5490994c..88676e44fa26 100644--- a/posthog/clickhouse/hcl/sql/local-multi/data.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/data.sql@@ -1618,13 +1618,14 @@ CREATE TABLE posthog.sharded_raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),- flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool),INDEX event_names_bloom_filter event_names TYPE bloom_filter() GRANULARITY 1,+ INDEX flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1,INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1,INDEX hosts_bloom_filter hosts TYPE bloom_filter() GRANULARITY 1,INDEX emails_bloom_filter emails TYPE bloom_filter() GRANULARITY 1@@ -2294,7 +2295,7 @@ CREATE TABLE posthog.writable_raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),- flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),@@ -3405,7 +3406,7 @@ CREATE TABLE posthog.raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),- flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),@@ -3735,7 +3736,7 @@ CREATE VIEW posthog.raw_sessions_v3_v AS SELECTuniqExactMerge(screen_uniq) AS screen_uniq,uniqUpToMerge(1)(page_screen_uniq_up_to) AS page_screen_uniq_up_to,max(has_autocapture) AS has_autocapture,- groupUniqArrayMapMerge(flag_values) AS flag_values,+ groupUniqArrayArray(10000)(flag_key_values) AS flag_key_values,groupUniqArrayArray(flag_keys) AS flag_keys,groupUniqArrayArray(2000)(event_names) AS event_names,groupUniqArrayArray(100)(hosts) AS hosts,diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sqlindex 91673c24c31d..2329570bde57 100644--- a/posthog/clickhouse/hcl/sql/local-single/all.sql+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql@@ -2761,13 +2761,14 @@ CREATE TABLE posthog.sharded_raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),- flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool),INDEX event_names_bloom_filter event_names TYPE bloom_filter() GRANULARITY 1,+ INDEX flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1,INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1,INDEX hosts_bloom_filter hosts TYPE bloom_filter() GRANULARITY 1,INDEX emails_bloom_filter emails TYPE bloom_filter() GRANULARITY 1@@ -4110,7 +4111,7 @@ CREATE TABLE posthog.writable_raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),- flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),@@ -6924,7 +6925,7 @@ CREATE TABLE posthog.raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),- flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),@@ -7559,7 +7560,7 @@ CREATE VIEW posthog.raw_sessions_v3_v AS SELECTuniqExactMerge(screen_uniq) AS screen_uniq,uniqUpToMerge(1)(page_screen_uniq_up_to) AS page_screen_uniq_up_to,max(has_autocapture) AS has_autocapture,- groupUniqArrayMapMerge(flag_values) AS flag_values,+ groupUniqArrayArray(10000)(flag_key_values) AS flag_key_values,groupUniqArrayArray(flag_keys) AS flag_keys,groupUniqArrayArray(2000)(event_names) AS event_names,groupUniqArrayArray(100)(hosts) AS hosts,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/data.sql b/posthog/clickhouse/hcl/sql/prod-eu/data.sqlindex 9826f278e032..39110f726096 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/data.sql@@ -1111,9 +1111,12 @@ CREATE TABLE posthog.raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),+ hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),+ emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool)) ENGINE = Distributed('sessions', 'posthog', 'raw_sessions_v3', cityHash64(session_id_v7));CREATE TABLE posthog.session_replay_features (@@ -1567,12 +1570,18 @@ CREATE TABLE posthog.sharded_raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),+ hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),+ emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool),INDEX event_names_bloom_filter event_names TYPE bloom_filter() GRANULARITY 1,- INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1+ INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1,+ INDEX flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1,+ INDEX hosts_bloom_filter hosts TYPE bloom_filter() GRANULARITY 1,+ INDEX emails_bloom_filter emails TYPE bloom_filter() GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.raw_sessions_v3', '{replica}') ORDER BY (team_id, session_timestamp, session_id_v7) PARTITION BY toYYYYMM(session_timestamp) SETTINGS index_granularity = 8192;CREATE TABLE posthog.sharded_session_recording_events (uuid UUID,@@ -2256,6 +2265,7 @@ CREATE TABLE posthog.writable_raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),@@ -2726,12 +2736,11 @@ CREATE VIEW posthog.raw_sessions_v3_v AS SELECTsession_timestamp,team_id,argMaxMerge(distinct_id) AS distinct_id,- argMaxMerge(person_id) AS person_id,groupUniqArrayMerge(distinct_ids) AS distinct_ids,min(min_timestamp) AS min_timestamp,max(max_timestamp) AS max_timestamp,max(max_inserted_at) AS max_inserted_at,- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,+ groupUniqArrayArray(2000)(urls) AS urls,argMinMerge(entry_url) AS entry_url,argMaxMerge(end_url) AS end_url,argMaxMerge(last_external_click_url) AS last_external_click_url,@@ -2764,8 +2773,14 @@ CREATE VIEW posthog.raw_sessions_v3_v AS SELECTuniqExactMerge(pageview_uniq) AS pageview_uniq,uniqExactMerge(autocapture_uniq) AS autocapture_uniq,uniqExactMerge(screen_uniq) AS screen_uniq,- uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,- groupUniqArrayMapMerge(flag_values) AS flag_values+ uniqUpToMerge(1)(page_screen_uniq_up_to) AS page_screen_uniq_up_to,+ max(has_autocapture) AS has_autocapture,+ groupUniqArrayArray(10000)(flag_key_values) AS flag_key_values,+ groupUniqArrayArray(flag_keys) AS flag_keys,+ groupUniqArrayArray(2000)(event_names) AS event_names,+ groupUniqArrayArray(100)(hosts) AS hosts,+ groupUniqArrayArray(10)(emails) AS emails,+ max(has_replay_events) AS has_replay_eventsFROM posthog.raw_sessions_v3GROUP BYsession_id_v7, session_timestamp, team_id;diff --git a/posthog/clickhouse/hcl/sql/prod-eu/sessions.sql b/posthog/clickhouse/hcl/sql/prod-eu/sessions.sqlindex da2471276e7a..1eaab798fb50 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/sessions.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/sessions.sql@@ -294,6 +294,7 @@ CREATE TABLE posthog.raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),@@ -301,7 +302,8 @@ CREATE TABLE posthog.raw_sessions_v3 (emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool),INDEX event_names_bloom_filter event_names TYPE bloom_filter() GRANULARITY 1,- INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1+ INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1,+ INDEX flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/sessions/noshard/posthog.raw_sessions_v3', '{shard}-{replica}') ORDER BY (team_id, session_timestamp, session_id_v7) PARTITION BY toYYYYMM(session_timestamp) SETTINGS index_granularity = 8192, storage_policy = 's3_tiered';CREATE TABLE posthog.sessions (session_id String,diff --git a/posthog/clickhouse/hcl/sql/prod-us/data.sql b/posthog/clickhouse/hcl/sql/prod-us/data.sqlindex ea8452a7737b..74574517cf27 100644--- a/posthog/clickhouse/hcl/sql/prod-us/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/data.sql@@ -1419,12 +1419,18 @@ CREATE TABLE posthog.sharded_raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),+ hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),+ emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool),INDEX event_names_bloom_filter event_names TYPE bloom_filter() GRANULARITY 1,- INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1+ INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1,+ INDEX flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1,+ INDEX hosts_bloom_filter hosts TYPE bloom_filter() GRANULARITY 1,+ INDEX emails_bloom_filter emails TYPE bloom_filter() GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.raw_sessions_v3', '{replica}') ORDER BY (team_id, session_timestamp, session_id_v7) PARTITION BY toYYYYMM(session_timestamp) SETTINGS index_granularity = 8192;CREATE TABLE posthog.sharded_session_replay_embeddings (session_id String,@@ -2895,9 +2901,12 @@ CREATE TABLE posthog.raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),+ hosts SimpleAggregateFunction(groupUniqArrayArray(100), Array(String)),+ emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool)) ENGINE = Distributed('posthog', 'posthog', 'sharded_raw_sessions_v3', cityHash64(session_id_v7));CREATE TABLE posthog.session_replay_embeddings (@@ -2984,6 +2993,7 @@ CREATE TABLE posthog.writable_raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),@@ -3171,12 +3181,11 @@ CREATE VIEW posthog.raw_sessions_v3_v AS SELECTsession_timestamp,team_id,argMaxMerge(distinct_id) AS distinct_id,- argMaxMerge(person_id) AS person_id,groupUniqArrayMerge(distinct_ids) AS distinct_ids,min(min_timestamp) AS min_timestamp,max(max_timestamp) AS max_timestamp,max(max_inserted_at) AS max_inserted_at,- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,+ groupUniqArrayArray(2000)(urls) AS urls,argMinMerge(entry_url) AS entry_url,argMaxMerge(end_url) AS end_url,argMaxMerge(last_external_click_url) AS last_external_click_url,@@ -3209,8 +3218,14 @@ CREATE VIEW posthog.raw_sessions_v3_v AS SELECTuniqExactMerge(pageview_uniq) AS pageview_uniq,uniqExactMerge(autocapture_uniq) AS autocapture_uniq,uniqExactMerge(screen_uniq) AS screen_uniq,- uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,- groupUniqArrayMapMerge(flag_values) AS flag_values+ uniqUpToMerge(1)(page_screen_uniq_up_to) AS page_screen_uniq_up_to,+ max(has_autocapture) AS has_autocapture,+ groupUniqArrayArray(10000)(flag_key_values) AS flag_key_values,+ groupUniqArrayArray(flag_keys) AS flag_keys,+ groupUniqArrayArray(2000)(event_names) AS event_names,+ groupUniqArrayArray(100)(hosts) AS hosts,+ groupUniqArrayArray(10)(emails) AS emails,+ max(has_replay_events) AS has_replay_eventsFROM posthog.raw_sessions_v3GROUP BYsession_id_v7, session_timestamp, team_id;diff --git a/posthog/clickhouse/hcl/sql/prod-us/sessions.sql b/posthog/clickhouse/hcl/sql/prod-us/sessions.sqlindex 3438ce792caa..188bf65d6ebf 100644--- a/posthog/clickhouse/hcl/sql/prod-us/sessions.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/sessions.sql@@ -294,6 +294,7 @@ CREATE TABLE posthog.raw_sessions_v3 (screen_uniq AggregateFunction(uniqExact, Nullable(UUID)),page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Bool),+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),event_names SimpleAggregateFunction(groupUniqArrayArray, Array(String)),@@ -301,7 +302,8 @@ CREATE TABLE posthog.raw_sessions_v3 (emails SimpleAggregateFunction(groupUniqArrayArray(10), Array(String)),has_replay_events SimpleAggregateFunction(max, Bool),INDEX event_names_bloom_filter event_names TYPE bloom_filter() GRANULARITY 1,- INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1+ INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1,+ INDEX flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/sessions/noshard/posthog.raw_sessions_v3', '{shard}-{replica}') ORDER BY (team_id, session_timestamp, session_id_v7) PARTITION BY toYYYYMM(session_timestamp) SETTINGS index_granularity = 8192, max_replicated_merges_in_queue = 5, parts_to_delay_insert = 1500, parts_to_throw_insert = 2000, prefer_fetch_merged_part_size_threshold = 1, prefer_fetch_merged_part_time_threshold = 0, replicated_deduplication_window = 0, replicated_deduplication_window_for_async_inserts = 0, storage_policy = 's3_tiered';CREATE TABLE posthog.sessions (session_id String,diff --git a/posthog/clickhouse/migrations/0325_sessions_v3_flag_key_values.py b/posthog/clickhouse/migrations/0325_sessions_v3_flag_key_values.pynew file mode 100644index 000000000000..3a1244654224--- /dev/null+++ b/posthog/clickhouse/migrations/0325_sessions_v3_flag_key_values.py@@ -0,0 +1,117 @@+from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions+from posthog.models.raw_sessions.migrations_v3 import (+ ADD_EMAILS,+ ADD_EMAILS_BLOOM_FILTER,+ ADD_FLAG_KEY_VALUES,+ ADD_FLAG_KEY_VALUES_BLOOM_FILTER,+ ADD_HOSTS,+ ADD_HOSTS_BLOOM_FILTER,+)+from posthog.models.raw_sessions.sessions_v3 import (+ DISTRIBUTED_RAW_SESSIONS_TABLE_V3,+ RAW_SESSIONS_CREATE_OR_REPLACE_VIEW_SQL_V3,+ SHARDED_RAW_SESSIONS_TABLE_V3,+ TABLE_BASE_NAME_V3,+ WRITABLE_RAW_SESSIONS_TABLE_V3,+)+from posthog.run_mode import run_mode++operations = [+ run_sql_with_exceptions(+ ADD_FLAG_KEY_VALUES.format(table_name=SHARDED_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=True,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ ADD_FLAG_KEY_VALUES.format(table_name=WRITABLE_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ ADD_FLAG_KEY_VALUES.format(table_name=DISTRIBUTED_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ ADD_FLAG_KEY_VALUES_BLOOM_FILTER.format(table_name=SHARDED_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=True,+ is_alter_on_replicated_table=True,+ ),+ # hosts and emails were only ever added by hand, so the main-cluster copies never got+ # them; the recreated view below selects both, so the columns must exist first.+ run_sql_with_exceptions(+ ADD_HOSTS.format(table_name=SHARDED_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=True,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ ADD_HOSTS.format(table_name=WRITABLE_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ ADD_HOSTS.format(table_name=DISTRIBUTED_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ ADD_EMAILS.format(table_name=SHARDED_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=True,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ ADD_EMAILS.format(table_name=WRITABLE_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ ADD_EMAILS.format(table_name=DISTRIBUTED_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ ADD_HOSTS_BLOOM_FILTER.format(table_name=SHARDED_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=True,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ ADD_EMAILS_BLOOM_FILTER.format(table_name=SHARDED_RAW_SESSIONS_TABLE_V3()),+ node_roles=[NodeRole.DATA],+ sharded=True,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ RAW_SESSIONS_CREATE_OR_REPLACE_VIEW_SQL_V3(),+ node_roles=[NodeRole.DATA],+ ),+]++# In cloud envs the live copy is the single-shard raw_sessions_v3 MergeTree on the sessions+# satellite cluster (roles/sessions/shared in the HCL); local sessions nodes don't carry it.+if run_mode().is_deployed_cloud:+ operations += [+ run_sql_with_exceptions(+ ADD_FLAG_KEY_VALUES.format(table_name=TABLE_BASE_NAME_V3),+ node_roles=[NodeRole.SESSIONS],+ sharded=False,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ ADD_FLAG_KEY_VALUES_BLOOM_FILTER.format(table_name=TABLE_BASE_NAME_V3),+ node_roles=[NodeRole.SESSIONS],+ sharded=False,+ is_alter_on_replicated_table=True,+ ),+ ]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex fb6a87824408..59fd5e7d4eaa 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0324_metrics2_timestamp_index+0325_sessions_v3_flag_key_valuesdiff --git a/posthog/clickhouse/test/__snapshots__/test_raw_sessions_v3_model.ambr b/posthog/clickhouse/test/__snapshots__/test_raw_sessions_v3_model.ambrindex 4633f79fc864..18be1c646860 100644--- a/posthog/clickhouse/test/__snapshots__/test_raw_sessions_v3_model.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_raw_sessions_v3_model.ambr@@ -167,9 +167,9 @@'''select session_id_v7,- has(flag_values['$feature/flag_string'], 'f1_a') as has_f1_a,- has(flag_values['$feature/flag_string'], 'f1_b') as has_f1_b,- has(flag_values['$feature/flag_string'], 'f1_c') as has_f1_c+ has(flag_key_values, '$feature/flag_string=f1_a') as has_f1_a,+ has(flag_key_values, '$feature/flag_string=f1_b') as has_f1_b,+ has(flag_key_values, '$feature/flag_string=f1_c') as has_f1_cfrom raw_sessions_v3_vwhere team_id = 99999ORDER BY session_id_v7diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex c5d071beba12..8b382423edf2 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -6203,8 +6203,9 @@page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Boolean),- -- Flags - store every seen value for each flag- flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),+ -- Flags - store every seen 'key=value' pair per flag. A flat array instead of a+ -- groupUniqArrayMap state because per-key sub-aggregators made merges ~8-37x more expensive.+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),-- Event names - store unique event names seen in this session@@ -6416,7 +6417,7 @@event = '$autocapture' as has_autocapture,-- flags- initializeAggregation('groupUniqArrayMapState', properties_group_feature_flags) as flag_values,+ arrayMap((k, v) -> concat(k, '=', v), mapKeys(properties_group_feature_flags), mapValues(properties_group_feature_flags)) as flag_key_values,mapKeys(properties_group_feature_flags) as flag_keys,-- event names@@ -6515,7 +6516,7 @@false as has_autocapture,-- flags- initializeAggregation('groupUniqArrayMapState', CAST(map(), 'Map(String, String)')) as flag_values,+ CAST([], 'Array(String)') as flag_key_values,CAST([], 'Array(String)') as flag_keys,-- event names@@ -8347,8 +8348,9 @@page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Boolean),- -- Flags - store every seen value for each flag- flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),+ -- Flags - store every seen 'key=value' pair per flag. A flat array instead of a+ -- groupUniqArrayMap state because per-key sub-aggregators made merges ~8-37x more expensive.+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),-- Event names - store unique event names seen in this session@@ -8366,6 +8368,7 @@-- IndexesINDEX event_names_bloom_filter event_names TYPE bloom_filter() GRANULARITY 1,+ INDEX flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1,INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1,INDEX hosts_bloom_filter hosts TYPE bloom_filter() GRANULARITY 1,INDEX emails_bloom_filter emails TYPE bloom_filter() GRANULARITY 1@@ -10465,8 +10468,9 @@page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Boolean),- -- Flags - store every seen value for each flag- flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),+ -- Flags - store every seen 'key=value' pair per flag. A flat array instead of a+ -- groupUniqArrayMap state because per-key sub-aggregators made merges ~8-37x more expensive.+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),-- Event names - store unique event names seen in this session@@ -13661,8 +13665,9 @@page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Boolean),- -- Flags - store every seen value for each flag- flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),+ -- Flags - store every seen 'key=value' pair per flag. A flat array instead of a+ -- groupUniqArrayMap state because per-key sub-aggregators made merges ~8-37x more expensive.+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),-- Event names - store unique event names seen in this session@@ -13680,6 +13685,7 @@-- IndexesINDEX event_names_bloom_filter event_names TYPE bloom_filter() GRANULARITY 1,+ INDEX flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1,INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1,INDEX hosts_bloom_filter hosts TYPE bloom_filter() GRANULARITY 1,INDEX emails_bloom_filter emails TYPE bloom_filter() GRANULARITY 1diff --git a/posthog/clickhouse/test/test_raw_sessions_v3_model.py b/posthog/clickhouse/test/test_raw_sessions_v3_model.pyindex 087cba542cc5..160d0f6d2898 100644--- a/posthog/clickhouse/test/test_raw_sessions_v3_model.py+++ b/posthog/clickhouse/test/test_raw_sessions_v3_model.py@@ -520,14 +520,15 @@ class TestRawSessionsModel(ClickhouseTestMixin, BaseTest):result = self.select_by_session_id(session_id)+ flag_key_values = result[0]["flag_key_values"]# contains all values- assert set(result[0]["flag_values"]["$feature/flag_string"]) == {"f1_a", "f1_b"}+ assert {"$feature/flag_string=f1_a", "$feature/flag_string=f1_b"} <= set(flag_key_values)# converts to string- assert set(result[0]["flag_values"]["$feature/flag_int"]) == {"1", "2"}+ assert {"$feature/flag_int=1", "$feature/flag_int=2"} <= set(flag_key_values)# converts to json string- assert set(result[0]["flag_values"]["$feature/flag_complex"]) == {'["hello",123]', '{"key":"value"}'}+ assert {'$feature/flag_complex=["hello",123]', '$feature/flag_complex={"key":"value"}'} <= set(flag_key_values)# deduplicates- assert result[0]["flag_values"]["$feature/flag_duplicates"] == ["a"]+ assert flag_key_values.count("$feature/flag_duplicates=a") == 1def test_lookup_feature_flag(self):distinct_id_1 = create_distinct_id()@@ -570,9 +571,9 @@ class TestRawSessionsModel(ClickhouseTestMixin, BaseTest):"""selectsession_id_v7,- has(flag_values['$feature/flag_string'], 'f1_a') as has_f1_a,- has(flag_values['$feature/flag_string'], 'f1_b') as has_f1_b,- has(flag_values['$feature/flag_string'], 'f1_c') as has_f1_c+ has(flag_key_values, '$feature/flag_string=f1_a') as has_f1_a,+ has(flag_key_values, '$feature/flag_string=f1_b') as has_f1_b,+ has(flag_key_values, '$feature/flag_string=f1_c') as has_f1_cfrom raw_sessions_v3_vwhereteam_id = %(team_id)sdiff --git a/posthog/models/raw_sessions/migrations_v3.py b/posthog/models/raw_sessions/migrations_v3.pyindex 32859721b979..b105e0c19be5 100644--- a/posthog/models/raw_sessions/migrations_v3.py+++ b/posthog/models/raw_sessions/migrations_v3.py@@ -79,3 +79,15 @@ ADD_URLS = """ALTER TABLE {table_name}ADD COLUMN IF NOT EXISTS urls SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)) AFTER max_inserted_at"""+++ADD_FLAG_KEY_VALUES = """+ALTER TABLE {table_name}+ADD COLUMN IF NOT EXISTS flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)) AFTER has_autocapture+"""+++ADD_FLAG_KEY_VALUES_BLOOM_FILTER = """+ALTER TABLE {table_name}+ADD INDEX IF NOT EXISTS flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1+"""diff --git a/posthog/models/raw_sessions/sessions_v3.py b/posthog/models/raw_sessions/sessions_v3.pyindex 036efd0d5f2f..7fddd6eeaf89 100644--- a/posthog/models/raw_sessions/sessions_v3.py+++ b/posthog/models/raw_sessions/sessions_v3.py@@ -161,8 +161,9 @@ CREATE TABLE IF NOT EXISTS {table_name}page_screen_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),has_autocapture SimpleAggregateFunction(max, Boolean),- -- Flags - store every seen value for each flag- flag_values AggregateFunction(groupUniqArrayMap, Map(String, String)),+ -- Flags - store every seen 'key=value' pair per flag. A flat array instead of a+ -- groupUniqArrayMap state because per-key sub-aggregators made merges ~8-37x more expensive.+ flag_key_values SimpleAggregateFunction(groupUniqArrayArray(10000), Array(String)),flag_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),-- Event names - store unique event names seen in this session@@ -198,6 +199,7 @@ def SHARDED_RAW_SESSIONS_TABLE_SQL_V3():-- IndexesINDEX event_names_bloom_filter event_names TYPE bloom_filter() GRANULARITY 1,+ INDEX flag_key_values_bloom_filter flag_key_values TYPE bloom_filter() GRANULARITY 1,INDEX flag_keys_bloom_filter flag_keys TYPE bloom_filter() GRANULARITY 1,INDEX hosts_bloom_filter hosts TYPE bloom_filter() GRANULARITY 1,INDEX emails_bloom_filter emails TYPE bloom_filter() GRANULARITY 1@@ -379,7 +381,7 @@ SELECTevent = '$autocapture' as has_autocapture,-- flags- initializeAggregation('groupUniqArrayMapState', properties_group_feature_flags) as flag_values,+ arrayMap((k, v) -> concat(k, '=', v), mapKeys(properties_group_feature_flags), mapValues(properties_group_feature_flags)) as flag_key_values,mapKeys(properties_group_feature_flags) as flag_keys,-- event names@@ -510,7 +512,7 @@ SELECTfalse as has_autocapture,-- flags- initializeAggregation('groupUniqArrayMapState', CAST(map(), 'Map(String, String)')) as flag_values,+ CAST([], 'Array(String)') as flag_key_values,CAST([], 'Array(String)') as flag_keys,-- event names@@ -735,7 +737,7 @@ SELECTmax(has_autocapture) as has_autocapture,-- flags- groupUniqArrayMapMerge(flag_values) as flag_values,+ groupUniqArrayArray(10000)(flag_key_values) as flag_key_values,groupUniqArrayArray(flag_keys) as flag_keys,-- event names