Skip to content

: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.

chore(clickhouse): declare the events family once via _event_base (#79532)

Paweł Szczur46e0d5d5a202
diff --git a/posthog/clickhouse/hcl/bin/image.txt b/posthog/clickhouse/hcl/bin/image.txt
index a0bf6526dea2..d0468e8ee34d 100644
--- a/posthog/clickhouse/hcl/bin/image.txt
+++ b/posthog/clickhouse/hcl/bin/image.txt
@@ -1 +1 @@
-ghcr.io/posthog/chschema:sha-f72d69a
+ghcr.io/posthog/chschema:sha-49eb278
diff --git a/posthog/clickhouse/hcl/golden/local-multi/data.hcl b/posthog/clickhouse/hcl/golden/local-multi/data.hcl
index af10328dd843..09b2695764ee 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/data.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/data.hcl
@@ -1075,63 +1075,89 @@ database "posthog" {
column "distinct_id" {
type = "String"
}
- column "elements_chain" {
- type = "String"
- }
column "created_at" {
type = "DateTime64(6, 'UTC')"
}
- column "person_id" {
- type = "UUID"
+ column "$group_0" {
+ type = "String"
+ comment = "column_materializer::$group_0"
}
- column "person_created_at" {
- type = "DateTime64(3)"
+ column "$group_1" {
+ type = "String"
+ comment = "column_materializer::$group_1"
}
- column "person_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "$group_2" {
+ type = "String"
+ comment = "column_materializer::$group_2"
}
- column "group0_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "$group_3" {
+ type = "String"
+ comment = "column_materializer::$group_3"
}
- column "group1_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "$group_4" {
+ type = "String"
+ comment = "column_materializer::$group_4"
}
- column "group2_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "$window_id" {
+ type = "String"
+ comment = "column_materializer::$window_id"
}
- column "group3_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "$session_id" {
+ type = "String"
+ comment = "column_materializer::$session_id"
}
- column "group4_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "inserted_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ default = "now64()"
}
- column "group0_created_at" {
- type = "DateTime64(3)"
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
}
- column "group1_created_at" {
- type = "DateTime64(3)"
+ column "elements_chain_href" {
+ type = "String"
+ comment = "column_materializer::elements_chain::href"
}
- column "group2_created_at" {
- type = "DateTime64(3)"
+ column "elements_chain_texts" {
+ type = "Array(String)"
+ comment = "column_materializer::elements_chain::texts"
}
- column "group3_created_at" {
- type = "DateTime64(3)"
+ column "elements_chain_ids" {
+ type = "Array(String)"
+ comment = "column_materializer::elements_chain::ids"
}
- column "group4_created_at" {
- type = "DateTime64(3)"
+ column "elements_chain_elements" {
+ type = "Array(Enum8('a'=1, 'button'=2, 'form'=3, 'input'=4, 'select'=5, 'textarea'=6, 'label'=7))"
+ comment = "column_materializer::elements_chain::elements"
}
- column "person_mode" {
- type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ column "properties_group_custom" {
+ type = "Map(String, String)"
}
- column "historical_migration" {
+ column "properties_group_feature_flags" {
+ type = "Map(String, String)"
+ }
+ column "is_deleted" {
type = "Bool"
}
+ column "person_properties_map_custom" {
+ type = "Map(String, String)"
+ }
+ column "$session_id_uuid" {
+ type = "Nullable(UInt128)"
+ }
+ column "consumer_breadcrumbs" {
+ type = "Array(String)"
+ }
+ column "properties_group_ai" {
+ type = "Map(String, String)"
+ }
+ column "mat_$ai_session_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_session_id"
+ }
+ column "mat_$ai_is_error" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_is_error"
+ }
column "dmat_string_0" {
type = "Nullable(String)"
}
@@ -1162,64 +1188,60 @@ database "posthog" {
column "dmat_string_9" {
type = "Nullable(String)"
}
- column "$group_0" {
- type = "String"
- comment = "column_materializer::$group_0"
+ column "historical_migration" {
+ type = "Bool"
}
- column "$group_1" {
- type = "String"
- comment = "column_materializer::$group_1"
+ column "mat_$ai_prompt_name" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_prompt_name"
}
- column "$group_2" {
- type = "String"
- comment = "column_materializer::$group_2"
+ column "elements_chain" {
+ type = "String"
}
- column "$group_3" {
- type = "String"
- comment = "column_materializer::$group_3"
+ column "person_id" {
+ type = "UUID"
}
- column "$group_4" {
- type = "String"
- comment = "column_materializer::$group_4"
+ column "person_created_at" {
+ type = "DateTime64(3)"
}
- column "$window_id" {
- type = "String"
- comment = "column_materializer::$window_id"
+ column "person_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "$session_id" {
- type = "String"
- comment = "column_materializer::$session_id"
+ column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "$session_id_uuid" {
- type = "Nullable(UInt128)"
+ column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "elements_chain_href" {
- type = "String"
- comment = "column_materializer::elements_chain::href"
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "elements_chain_texts" {
- type = "Array(String)"
- comment = "column_materializer::elements_chain::texts"
+ column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "elements_chain_ids" {
- type = "Array(String)"
- comment = "column_materializer::elements_chain::ids"
+ column "group4_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "elements_chain_elements" {
- type = "Array(Enum8('a'=1, 'button'=2, 'form'=3, 'input'=4, 'select'=5, 'textarea'=6, 'label'=7))"
- comment = "column_materializer::elements_chain::elements"
+ column "group0_created_at" {
+ type = "DateTime64(3)"
}
- column "properties_group_custom" {
- type = "Map(String, String)"
+ column "group1_created_at" {
+ type = "DateTime64(3)"
}
- column "properties_group_ai" {
- type = "Map(String, String)"
+ column "group2_created_at" {
+ type = "DateTime64(3)"
}
- column "properties_group_feature_flags" {
- type = "Map(String, String)"
+ column "group3_created_at" {
+ type = "DateTime64(3)"
}
- column "person_properties_map_custom" {
- type = "Map(String, String)"
+ column "group4_created_at" {
+ type = "DateTime64(3)"
}
column "_timestamp" {
type = "DateTime"
@@ -1227,32 +1249,10 @@ database "posthog" {
column "_offset" {
type = "UInt64"
}
- column "inserted_at" {
- type = "Nullable(DateTime64(6, 'UTC'))"
- default = "now64()"
- }
- column "consumer_breadcrumbs" {
- type = "Array(String)"
- }
- column "is_deleted" {
- type = "Bool"
- }
column "mat_$ai_trace_id" {
type = "Nullable(String)"
comment = "column_materializer::properties::$ai_trace_id"
}
- column "mat_$ai_session_id" {
- type = "Nullable(String)"
- comment = "column_materializer::properties::$ai_session_id"
- }
- column "mat_$ai_is_error" {
- type = "Nullable(String)"
- comment = "column_materializer::properties::$ai_is_error"
- }
- column "mat_$ai_prompt_name" {
- type = "Nullable(String)"
- comment = "column_materializer::properties::$ai_prompt_name"
- }
column "mat_$ai_experiment_id" {
type = "Nullable(String)"
comment = "column_materializer::properties::$ai_experiment_id"
@@ -4977,63 +4977,105 @@ database "posthog" {
column "distinct_id" {
type = "String"
}
- column "elements_chain" {
- type = "String"
- }
column "created_at" {
type = "DateTime64(6, 'UTC')"
}
- column "person_id" {
- type = "UUID"
+ column "$group_0" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_0"
}
- column "person_created_at" {
- type = "DateTime64(3)"
+ column "$group_1" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_1"
}
- column "person_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "$group_2" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_2"
}
- column "group0_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "$group_3" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_3"
}
- column "group1_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "$group_4" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_4"
}
- column "group2_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "$window_id" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$window_id"
}
- column "group3_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "$session_id" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$session_id"
}
- column "group4_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "inserted_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ default = "now64()"
}
- column "group0_created_at" {
- type = "DateTime64(3)"
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
}
- column "group1_created_at" {
- type = "DateTime64(3)"
+ column "elements_chain_href" {
+ type = "String"
+ materialized = "EXTRACT(elements_chain, '(?::|\")href=\"(.*?)\"')"
}
- column "group2_created_at" {
- type = "DateTime64(3)"
+ column "elements_chain_texts" {
+ type = "Array(String)"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")text=\"(.*?)\"'))"
}
- column "group3_created_at" {
- type = "DateTime64(3)"
+ column "elements_chain_ids" {
+ type = "Array(String)"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
}
- column "group4_created_at" {
- type = "DateTime64(3)"
+ column "elements_chain_elements" {
+ type = "Array(Enum8('a'=1, 'button'=2, 'form'=3, 'input'=4, 'select'=5, 'textarea'=6, 'label'=7))"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?:^|;)(a|button|form|input|select|textarea|label)(?:\\\\.|$|:)'))"
}
- column "person_mode" {
- type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ column "properties_group_custom" {
+ type = "Map(String, String)"
+ materialized = "mapSort(mapFilter((key, _) -> ((key NOT LIKE '$%') AND (key NOT IN ('token', 'distinct_id', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'gclid', 'gad_source', 'gclsrc', 'dclid', 'gbraid', 'wbraid', 'fbclid', 'msclkid', 'twclid', 'li_fat_id', 'mc_cid', 'igshid', 'ttclid', 'rdt_cid', 'epik', 'qclid', 'sccid', 'irclid', '_kx'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
+ codec = "ZSTD(1)"
}
- column "historical_migration" {
+ column "properties_group_feature_flags" {
+ type = "Map(String, String)"
+ materialized = "mapSort(mapFilter((key, _) -> (key LIKE '$feature/%'), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
+ codec = "ZSTD(1)"
+ }
+ column "is_deleted" {
type = "Bool"
}
+ column "person_properties_map_custom" {
+ type = "Map(String, String)"
+ materialized = "mapSort(mapFilter((key, _) -> (key NOT LIKE '$%'), CAST(JSONExtractKeysAndValues(person_properties, 'String'), 'Map(String, String)')))"
+ codec = "ZSTD(1)"
+ }
+ column "$session_id_uuid" {
+ type = "Nullable(UInt128)"
+ materialized = "toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)'))"
+ }
+ column "consumer_breadcrumbs" {
+ type = "Array(String)"
+ }
+ column "properties_group_ai" {
+ type = "Map(String, String)"
+ materialized = "mapSort(mapFilter((key, _) -> ((key LIKE '$ai_%') AND (key NOT IN ('$ai_input', '$ai_input_state', '$ai_output', '$ai_output_choices', '$ai_output_state', '$ai_tools'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
+ codec = "ZSTD(1)"
+ }
+ column "mat_$ai_session_id" {
+ type = "Nullable(String)"
+ materialized = "JSONExtract(properties, '$ai_session_id', 'Nullable(String)')"
+ }
+ column "mat_$ai_is_error" {
+ type = "Nullable(String)"
+ materialized = "JSONExtract(properties, '$ai_is_error', 'Nullable(String)')"
+ }
column "dmat_string_0" {
type = "Nullable(String)"
}
@@ -5064,160 +5106,83 @@ database "posthog" {
column "dmat_string_9" {
type = "Nullable(String)"
}
- column "$group_0" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
- comment = "column_materializer::$group_0"
- }
- column "$group_1" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^\"|\"$', '')"
- comment = "column_materializer::$group_1"
- }
- column "$group_2" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^\"|\"$', '')"
- comment = "column_materializer::$group_2"
+ column "historical_migration" {
+ type = "Bool"
}
- column "$group_3" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^\"|\"$', '')"
- comment = "column_materializer::$group_3"
+ column "mat_$ai_prompt_name" {
+ type = "Nullable(String)"
+ materialized = "JSONExtract(properties, '$ai_prompt_name', 'Nullable(String)')"
}
- column "$group_4" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
- comment = "column_materializer::$group_4"
+ column "properties_map_ephemeral" {
+ type = "Map(String, String)"
}
- column "$window_id" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^\"|\"$', '')"
- comment = "column_materializer::$window_id"
+ column "person_properties_map_ephemeral" {
+ type = "Map(String, String)"
}
- column "$session_id" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
- comment = "column_materializer::$session_id"
+ column "mat_$ai_experiment_id" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, '$ai_experiment_id', 'Nullable(String)')"
}
- column "$session_id_uuid" {
- type = "Nullable(UInt128)"
- materialized = "toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)'))"
+ column "elements_chain" {
+ type = "String"
}
- column "elements_chain_href" {
- type = "String"
- materialized = "EXTRACT(elements_chain, '(?::|\")href=\"(.*?)\"')"
+ column "person_id" {
+ type = "UUID"
}
- column "elements_chain_texts" {
- type = "Array(String)"
- materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")text=\"(.*?)\"'))"
+ column "person_created_at" {
+ type = "DateTime64(3)"
}
- column "elements_chain_elements" {
- type = "Array(Enum8('a'=1, 'button'=2, 'form'=3, 'input'=4, 'select'=5, 'textarea'=6, 'label'=7))"
- materialized = "arrayDistinct(extractAll(elements_chain, '(?:^|;)(a|button|form|input|select|textarea|label)(?:\\\\.|$|:)'))"
+ column "person_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "properties_group_custom" {
- type = "Map(String, String)"
- materialized = "mapSort(mapFilter((key, _) -> ((key NOT LIKE '$%') AND (key NOT IN ('token', 'distinct_id', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'gclid', 'gad_source', 'gclsrc', 'dclid', 'gbraid', 'wbraid', 'fbclid', 'msclkid', 'twclid', 'li_fat_id', 'mc_cid', 'igshid', 'ttclid', 'rdt_cid', 'epik', 'qclid', 'sccid', 'irclid', '_kx'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
- codec = "ZSTD(1)"
+ column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "properties_group_ai" {
- type = "Map(String, String)"
- materialized = "mapSort(mapFilter((key, _) -> ((key LIKE '$ai_%') AND (key NOT IN ('$ai_input', '$ai_input_state', '$ai_output', '$ai_output_choices', '$ai_output_state', '$ai_tools'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
- codec = "ZSTD(1)"
+ column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "properties_group_feature_flags" {
- type = "Map(String, String)"
- materialized = "mapSort(mapFilter((key, _) -> (key LIKE '$feature/%'), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
- codec = "ZSTD(1)"
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "person_properties_map_custom" {
- type = "Map(String, String)"
- materialized = "mapSort(mapFilter((key, _) -> (key NOT LIKE '$%'), CAST(JSONExtractKeysAndValues(person_properties, 'String'), 'Map(String, String)')))"
- codec = "ZSTD(1)"
+ column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "_timestamp" {
- type = "DateTime"
+ column "group4_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "_offset" {
- type = "UInt64"
+ column "group0_created_at" {
+ type = "DateTime64(3)"
}
- column "inserted_at" {
- type = "Nullable(DateTime64(6, 'UTC'))"
- default = "now64()"
+ column "group1_created_at" {
+ type = "DateTime64(3)"
}
- column "consumer_breadcrumbs" {
- type = "Array(String)"
+ column "group2_created_at" {
+ type = "DateTime64(3)"
}
- column "elements_chain_ids" {
- type = "Array(String)"
- materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
+ column "group3_created_at" {
+ type = "DateTime64(3)"
}
- column "is_deleted" {
- type = "Bool"
+ column "group4_created_at" {
+ type = "DateTime64(3)"
}
- column "properties_map_ephemeral" {
- type = "Map(String, String)"
+ column "_timestamp" {
+ type = "DateTime"
}
- column "person_properties_map_ephemeral" {
- type = "Map(String, String)"
+ column "_offset" {
+ type = "UInt64"
}
column "mat_$ai_trace_id" {
type = "Nullable(String)"
materialized = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
}
- column "mat_$ai_session_id" {
- type = "Nullable(String)"
- materialized = "JSONExtract(properties, '$ai_session_id', 'Nullable(String)')"
- }
- column "mat_$ai_is_error" {
- type = "Nullable(String)"
- materialized = "JSONExtract(properties, '$ai_is_error', 'Nullable(String)')"
- }
- column "mat_$ai_prompt_name" {
- type = "Nullable(String)"
- materialized = "JSONExtract(properties, '$ai_prompt_name', 'Nullable(String)')"
- }
- column "mat_$ai_experiment_id" {
- type = "Nullable(String)"
- default = "JSONExtract(properties, '$ai_experiment_id', 'Nullable(String)')"
- }
- index "minmax_$group_0" {
- expr = "`$group_0`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$group_1" {
- expr = "`$group_1`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$group_2" {
- expr = "`$group_2`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$group_3" {
- expr = "`$group_3`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$group_4" {
- expr = "`$group_4`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$window_id" {
- expr = "`$window_id`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$session_id" {
- expr = "`$session_id`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$session_id_uuid" {
- expr = "`$session_id_uuid`"
+ index "minmax_inserted_at" {
+ expr = "coalesce(inserted_at, _timestamp)"
type = "minmax"
granularity = 1
}
@@ -5231,16 +5196,6 @@ database "posthog" {
type = "bloom_filter"
granularity = 1
}
- index "properties_group_ai_keys_bf" {
- expr = "mapKeys(properties_group_ai)"
- type = "bloom_filter"
- granularity = 1
- }
- index "properties_group_ai_values_bf" {
- expr = "mapValues(properties_group_ai)"
- type = "bloom_filter"
- granularity = 1
- }
index "properties_group_feature_flags_keys_bf" {
expr = "mapKeys(properties_group_feature_flags)"
type = "bloom_filter"
@@ -5261,19 +5216,14 @@ database "posthog" {
type = "bloom_filter"
granularity = 1
}
- index "kafka_timestamp_minmax_sharded_events" {
- expr = "_timestamp"
- type = "minmax"
- granularity = 3
- }
- index "minmax_inserted_at" {
- expr = "coalesce(inserted_at, _timestamp)"
- type = "minmax"
+ index "properties_group_ai_keys_bf" {
+ expr = "mapKeys(properties_group_ai)"
+ type = "bloom_filter"
granularity = 1
}
- index "is_deleted_idx" {
- expr = "is_deleted"
- type = "minmax"
+ index "properties_group_ai_values_bf" {
+ expr = "mapValues(properties_group_ai)"
+ type = "bloom_filter"
granularity = 1
}
index "bloom_filter_$ai_trace_id" {
@@ -5306,11 +5256,6 @@ database "posthog" {
type = "minmax"
granularity = 1
}
- index "minmax_historical_migration" {
- expr = "historical_migration"
- type = "minmax"
- granularity = 1
- }
index "bloom_filter_$ai_prompt_name" {
expr = "`mat_$ai_prompt_name`"
type = "bloom_filter"
@@ -5331,6 +5276,61 @@ database "posthog" {
type = "minmax"
granularity = 1
}
+ index "minmax_$session_id_uuid" {
+ expr = "`$session_id_uuid`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$group_0" {
+ expr = "`$group_0`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$group_1" {
+ expr = "`$group_1`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$group_2" {
+ expr = "`$group_2`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$group_3" {
+ expr = "`$group_3`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$group_4" {
+ expr = "`$group_4`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$window_id" {
+ expr = "`$window_id`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$session_id" {
+ expr = "`$session_id`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "kafka_timestamp_minmax_sharded_events" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ index "is_deleted_idx" {
+ expr = "is_deleted"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_historical_migration" {
+ expr = "historical_migration"
+ type = "minmax"
+ granularity = 1
+ }
engine "replicated_replacing_merge_tree" {
zoo_path = "/clickhouse/tables/{shard}/posthog.events"
replica_name = "{replica}"
diff --git a/posthog/clickhouse/hcl/manifest.hcl b/posthog/clickhouse/hcl/manifest.hcl
index cea412922818..b5b3789dccbd 100644
--- a/posthog/clickhouse/hcl/manifest.hcl
+++ b/posthog/clickhouse/hcl/manifest.hcl
@@ -102,7 +102,7 @@ role "batch_exports" {
# columns per env that are added out-of-band and churn constantly, so their goldens
# live in PostHog/posthog-cloud-infra (clickhouse/hcl/), not the OSS gate.
role "data" {
- env "local-multi" { layers = ["roles/shared", "roles/coshared/aux_data", "roles/coshared/sessions_data", "roles/coshared/ai_events_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/data/local"] }
+ env "local-multi" { layers = ["roles/shared", "roles/coshared/aux_data", "roles/coshared/sessions_data", "roles/coshared/ai_events_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/data/shared", "roles/data/local"] }
}
# role "endpoints" {
diff --git a/posthog/clickhouse/hcl/migration.md b/posthog/clickhouse/hcl/migration.md
index c9f95244feda..aae8b41d1e7a 100644
--- a/posthog/clickhouse/hcl/migration.md
+++ b/posthog/clickhouse/hcl/migration.md
@@ -95,11 +95,11 @@ Envs:
Each table shall be **defined** once, if there's a difference between envs, it shall be extended (prefered) or overriden, whatever is simple.
-"Defined once" counts _declarations_ — plain ones and same-name redeclarations carrying `extend` alike (an `extend` from an abstract is one definition; a second same-name declaration is a second definition even if it also extends). What does **not** count: `patch_*` blocks, and a redeclaration carrying `override = true` (sanctioned whole-replacement — it still copies content, so it stays the last resort). What the rule forbids is the same table declared in two layers, i.e. copied.
+"Defined once" counts _definition_ sites — plain declarations and `abstract` declarations (a copied abstract schema is still a copy). What does **not** count: declarations carrying `extend` (refinements of a definition that lives elsewhere, chschema #173), `patch_*` blocks, and a redeclaration carrying `override = true` (sanctioned whole-replacement — it still copies content, so it stays the last resort). What the rule forbids is the same schema authored in two places, i.e. copied.
-`hclexp locate -duplicates` draws exactly this line (verified against the pin: table+`patch_table` → 0, table+`override=true` → 0, table+plain redeclaration → 1, plain+`extend` redeclaration → 1, `extend`+`extend` → 1), so it is the enforcement mechanism, not a heuristic. Both repos gate on it against a `duplicates-baseline.txt` that may only shrink.
+`hclexp locate -duplicates` draws exactly this line (verified against the pin: table+`patch_table` → 0, table+`override=true` → 0, `extend` refinements → 0, table+plain redeclaration → 1, abstract+abstract → 1), so it is the enforcement mechanism, not a heuristic. Both repos gate on it against a `duplicates-baseline.txt` that may only shrink.
-The patch vocabulary covers tables and materialized views fully, so "express it as a patch" is always available for a content difference. `patch_table` carries `column` and `index` (both with positional `after`), `modify_column` (full replacement column spec — `type` is required), additive `projection`, `engine`, `order_by`, `partition_by`, `ttl` and `settings`; `patch_view` and `patch_dictionary` do the same for views and dictionaries, and `patch_materialized_view` carries `query` (replace) plus the column operations — an MV whose query differs per env stays declared once with per-env query patches. `settings` merge into the target with the patch winning on collision; everything else replaces. Built on demand in PostHog/chschema — #153 (settings merge), #156 (full vocab + `patch_view`/`patch_dictionary`), #159 (positioned column adds), #161 (positioned index adds), #170 (`patch_materialized_view`, MV `override = true`, projections in `patch_table`).
+The patch vocabulary covers tables and materialized views fully, so "express it as a patch" is always available for a content difference. `patch_table` carries `column` and `index` (both with positional `after`), `modify_column` (full replacement column spec — `type` is required), additive `projection`, `engine`, `order_by`, `partition_by`, `ttl` and `settings`; `patch_view` and `patch_dictionary` do the same for views and dictionaries, and `patch_materialized_view` carries `query` (replace) plus the column operations — an MV whose query differs per env stays declared once with per-env query patches. `settings` merge into the target with the patch winning on collision; everything else replaces. Built on demand in PostHog/chschema — #153 (settings merge), #156 (full vocab + `patch_view`/`patch_dictionary`), #159 (positioned column adds), #161 (positioned index adds), #170 (`patch_materialized_view`, MV `override = true`, projections in `patch_table`), #174/#175 (patches resolve with inheritance: a concrete-target patch applies after `extend`, so it can modify, drop, or position against inherited columns; abstract-target patches propagate to every child).
`patch_column` (#165) is the `extend` side of the same idea: a child using `extend` can specialize a single _inherited_ column — type, nullability, default kind, CODEC, TTL, comment — while keeping every unspecified field and the inherited column order. A plain `column` block on a child still means _add_, and still collides with an inherited name. This is what lets one codec-free abstract back both a storage table and its Distributed proxy, with only the storage child declaring CODECs:
@@ -115,7 +115,7 @@ table "sharded_events" {
Before that, the choice was to hang the CODECs on the abstract — forcing them onto the proxy too — or to stop sharing and repeat the column list.
-In this repo the cross-_role_ duplicates have been factored into `roles/coshared/<member-set>/` layers (one layer per set of stacks that co-host the objects), with env deltas as `patch_*` blocks in the env layers. What keeps the baseline non-empty is only the `mat_`-column-bearing events-family replicas, which resolve when the cloud env overlays move to posthog-cloud-infra rather than by any restructure here.
+In this repo the cross-_role_ duplicates have been factored into `roles/coshared/<member-set>/` layers (one layer per set of stacks that co-host the objects), with env deltas as `patch_*` blocks in the env layers. The events family itself is the `_event_base` pattern live: `roles/data/shared/` declares the abstract core once, `sharded_events` and the `events` proxy extend it there, `roles/data/local` carries the local delta as `patch_table` blocks, and posthog-cloud-infra's `overrides/data/<env>/` carry the cloud deltas the same way. What keeps the baseline non-empty is only the `mat_`-column-bearing events replicas on the sessions roles, which resolve when those roles' cloud env overlays move to posthog-cloud-infra rather than by any restructure here.
The purpose of the extension is to making the schema changes uniform across all envs: think adding a column or table shall be possible in one place and affect all envs.
diff --git a/posthog/clickhouse/hcl/roles/data/local/tables.hcl b/posthog/clickhouse/hcl/roles/data/local/tables.hcl
index 3e269544370b..0291532fb210 100644
--- a/posthog/clickhouse/hcl/roles/data/local/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/data/local/tables.hcl
@@ -816,215 +816,6 @@ database "posthog" {
version_column = "version"
}
}
- table "events" {
- column "uuid" {
- type = "UUID"
- }
- column "event" {
- type = "String"
- }
- column "properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "elements_chain" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- }
- column "person_id" {
- type = "UUID"
- }
- column "person_created_at" {
- type = "DateTime64(3)"
- }
- column "person_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group0_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group1_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group2_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group3_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group4_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group0_created_at" {
- type = "DateTime64(3)"
- }
- column "group1_created_at" {
- type = "DateTime64(3)"
- }
- column "group2_created_at" {
- type = "DateTime64(3)"
- }
- column "group3_created_at" {
- type = "DateTime64(3)"
- }
- column "group4_created_at" {
- type = "DateTime64(3)"
- }
- column "person_mode" {
- type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
- }
- column "historical_migration" {
- type = "Bool"
- }
- column "dmat_string_0" {
- type = "Nullable(String)"
- }
- column "dmat_string_1" {
- type = "Nullable(String)"
- }
- column "dmat_string_2" {
- type = "Nullable(String)"
- }
- column "dmat_string_3" {
- type = "Nullable(String)"
- }
- column "dmat_string_4" {
- type = "Nullable(String)"
- }
- column "dmat_string_5" {
- type = "Nullable(String)"
- }
- column "dmat_string_6" {
- type = "Nullable(String)"
- }
- column "dmat_string_7" {
- type = "Nullable(String)"
- }
- column "dmat_string_8" {
- type = "Nullable(String)"
- }
- column "dmat_string_9" {
- type = "Nullable(String)"
- }
- column "$group_0" {
- type = "String"
- comment = "column_materializer::$group_0"
- }
- column "$group_1" {
- type = "String"
- comment = "column_materializer::$group_1"
- }
- column "$group_2" {
- type = "String"
- comment = "column_materializer::$group_2"
- }
- column "$group_3" {
- type = "String"
- comment = "column_materializer::$group_3"
- }
- column "$group_4" {
- type = "String"
- comment = "column_materializer::$group_4"
- }
- column "$window_id" {
- type = "String"
- comment = "column_materializer::$window_id"
- }
- column "$session_id" {
- type = "String"
- comment = "column_materializer::$session_id"
- }
- column "$session_id_uuid" {
- type = "Nullable(UInt128)"
- }
- column "elements_chain_href" {
- type = "String"
- comment = "column_materializer::elements_chain::href"
- }
- column "elements_chain_texts" {
- type = "Array(String)"
- comment = "column_materializer::elements_chain::texts"
- }
- column "elements_chain_ids" {
- type = "Array(String)"
- comment = "column_materializer::elements_chain::ids"
- }
- column "elements_chain_elements" {
- type = "Array(Enum8('a'=1, 'button'=2, 'form'=3, 'input'=4, 'select'=5, 'textarea'=6, 'label'=7))"
- comment = "column_materializer::elements_chain::elements"
- }
- column "properties_group_custom" {
- type = "Map(String, String)"
- }
- column "properties_group_ai" {
- type = "Map(String, String)"
- }
- column "properties_group_feature_flags" {
- type = "Map(String, String)"
- }
- column "person_properties_map_custom" {
- type = "Map(String, String)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "inserted_at" {
- type = "Nullable(DateTime64(6, 'UTC'))"
- default = "now64()"
- }
- column "consumer_breadcrumbs" {
- type = "Array(String)"
- }
- column "is_deleted" {
- type = "Bool"
- }
- column "mat_$ai_trace_id" {
- type = "Nullable(String)"
- comment = "column_materializer::properties::$ai_trace_id"
- }
- column "mat_$ai_session_id" {
- type = "Nullable(String)"
- comment = "column_materializer::properties::$ai_session_id"
- }
- column "mat_$ai_is_error" {
- type = "Nullable(String)"
- comment = "column_materializer::properties::$ai_is_error"
- }
- column "mat_$ai_prompt_name" {
- type = "Nullable(String)"
- comment = "column_materializer::properties::$ai_prompt_name"
- }
- column "mat_$ai_experiment_id" {
- type = "Nullable(String)"
- comment = "column_materializer::properties::$ai_experiment_id"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_events"
- sharding_key = "sipHash64(distinct_id)"
- }
- }
table "events_json" {
column "uuid" {
type = "UUID"
@@ -3703,424 +3494,38 @@ database "posthog" {
column "_offset" {
type = "UInt64"
}
- column "_partition" {
- type = "UInt64"
- }
- engine "replicated_aggregating_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_app_metrics2"
- replica_name = "{replica}"
- }
- }
- table "sharded_distinct_id_usage" {
- order_by = ["team_id", "minute", "distinct_id"]
- partition_by = "toYYYYMMDD(minute)"
- ttl = "toDate(minute) + toIntervalDay(7)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "minute" {
- type = "DateTime"
- }
- column "event_count" {
- type = "UInt64"
- }
- engine "replicated_summing_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.distinct_id_usage"
- replica_name = "{replica}"
- sum_columns = ["event_count"]
- }
- }
- table "sharded_events" {
- order_by = ["team_id", "toDate(timestamp)", "event", "cityHash64(distinct_id)", "cityHash64(uuid)"]
- partition_by = "toYYYYMM(timestamp)"
- sample_by = "cityHash64(distinct_id)"
- settings = {
- index_granularity = "8192"
- }
- column "uuid" {
- type = "UUID"
- }
- column "event" {
- type = "String"
- }
- column "properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "elements_chain" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- }
- column "person_id" {
- type = "UUID"
- }
- column "person_created_at" {
- type = "DateTime64(3)"
- }
- column "person_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group0_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group1_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group2_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group3_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group4_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group0_created_at" {
- type = "DateTime64(3)"
- }
- column "group1_created_at" {
- type = "DateTime64(3)"
- }
- column "group2_created_at" {
- type = "DateTime64(3)"
- }
- column "group3_created_at" {
- type = "DateTime64(3)"
- }
- column "group4_created_at" {
- type = "DateTime64(3)"
- }
- column "person_mode" {
- type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
- }
- column "historical_migration" {
- type = "Bool"
- }
- column "dmat_string_0" {
- type = "Nullable(String)"
- }
- column "dmat_string_1" {
- type = "Nullable(String)"
- }
- column "dmat_string_2" {
- type = "Nullable(String)"
- }
- column "dmat_string_3" {
- type = "Nullable(String)"
- }
- column "dmat_string_4" {
- type = "Nullable(String)"
- }
- column "dmat_string_5" {
- type = "Nullable(String)"
- }
- column "dmat_string_6" {
- type = "Nullable(String)"
- }
- column "dmat_string_7" {
- type = "Nullable(String)"
- }
- column "dmat_string_8" {
- type = "Nullable(String)"
- }
- column "dmat_string_9" {
- type = "Nullable(String)"
- }
- column "$group_0" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
- comment = "column_materializer::$group_0"
- }
- column "$group_1" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^\"|\"$', '')"
- comment = "column_materializer::$group_1"
- }
- column "$group_2" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^\"|\"$', '')"
- comment = "column_materializer::$group_2"
- }
- column "$group_3" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^\"|\"$', '')"
- comment = "column_materializer::$group_3"
- }
- column "$group_4" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
- comment = "column_materializer::$group_4"
- }
- column "$window_id" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^\"|\"$', '')"
- comment = "column_materializer::$window_id"
- }
- column "$session_id" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
- comment = "column_materializer::$session_id"
- }
- column "$session_id_uuid" {
- type = "Nullable(UInt128)"
- materialized = "toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)'))"
- }
- column "elements_chain_href" {
- type = "String"
- materialized = "EXTRACT(elements_chain, '(?::|\")href=\"(.*?)\"')"
- }
- column "elements_chain_texts" {
- type = "Array(String)"
- materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")text=\"(.*?)\"'))"
- }
- column "elements_chain_elements" {
- type = "Array(Enum8('a'=1, 'button'=2, 'form'=3, 'input'=4, 'select'=5, 'textarea'=6, 'label'=7))"
- materialized = "arrayDistinct(extractAll(elements_chain, '(?:^|;)(a|button|form|input|select|textarea|label)(?:\\\\.|$|:)'))"
- }
- column "properties_group_custom" {
- type = "Map(String, String)"
- materialized = "mapSort(mapFilter((key, _) -> ((key NOT LIKE '$%') AND (key NOT IN ('token', 'distinct_id', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'gclid', 'gad_source', 'gclsrc', 'dclid', 'gbraid', 'wbraid', 'fbclid', 'msclkid', 'twclid', 'li_fat_id', 'mc_cid', 'igshid', 'ttclid', 'rdt_cid', 'epik', 'qclid', 'sccid', 'irclid', '_kx'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
- codec = "ZSTD(1)"
- }
- column "properties_group_ai" {
- type = "Map(String, String)"
- materialized = "mapSort(mapFilter((key, _) -> ((key LIKE '$ai_%') AND (key NOT IN ('$ai_input', '$ai_input_state', '$ai_output', '$ai_output_choices', '$ai_output_state', '$ai_tools'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
- codec = "ZSTD(1)"
- }
- column "properties_group_feature_flags" {
- type = "Map(String, String)"
- materialized = "mapSort(mapFilter((key, _) -> (key LIKE '$feature/%'), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
- codec = "ZSTD(1)"
- }
- column "person_properties_map_custom" {
- type = "Map(String, String)"
- materialized = "mapSort(mapFilter((key, _) -> (key NOT LIKE '$%'), CAST(JSONExtractKeysAndValues(person_properties, 'String'), 'Map(String, String)')))"
- codec = "ZSTD(1)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "inserted_at" {
- type = "Nullable(DateTime64(6, 'UTC'))"
- default = "now64()"
- }
- column "consumer_breadcrumbs" {
- type = "Array(String)"
- }
- column "elements_chain_ids" {
- type = "Array(String)"
- materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
- }
- column "is_deleted" {
- type = "Bool"
- }
- column "properties_map_ephemeral" {
- type = "Map(String, String)"
- }
- column "person_properties_map_ephemeral" {
- type = "Map(String, String)"
- }
- column "mat_$ai_trace_id" {
- type = "Nullable(String)"
- materialized = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
- }
- column "mat_$ai_session_id" {
- type = "Nullable(String)"
- materialized = "JSONExtract(properties, '$ai_session_id', 'Nullable(String)')"
- }
- column "mat_$ai_is_error" {
- type = "Nullable(String)"
- materialized = "JSONExtract(properties, '$ai_is_error', 'Nullable(String)')"
- }
- column "mat_$ai_prompt_name" {
- type = "Nullable(String)"
- materialized = "JSONExtract(properties, '$ai_prompt_name', 'Nullable(String)')"
- }
- column "mat_$ai_experiment_id" {
- type = "Nullable(String)"
- default = "JSONExtract(properties, '$ai_experiment_id', 'Nullable(String)')"
- }
- index "minmax_$group_0" {
- expr = "`$group_0`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$group_1" {
- expr = "`$group_1`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$group_2" {
- expr = "`$group_2`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$group_3" {
- expr = "`$group_3`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$group_4" {
- expr = "`$group_4`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$window_id" {
- expr = "`$window_id`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$session_id" {
- expr = "`$session_id`"
- type = "minmax"
- granularity = 1
- }
- index "minmax_$session_id_uuid" {
- expr = "`$session_id_uuid`"
- type = "minmax"
- granularity = 1
- }
- index "properties_group_custom_keys_bf" {
- expr = "mapKeys(properties_group_custom)"
- type = "bloom_filter"
- granularity = 1
- }
- index "properties_group_custom_values_bf" {
- expr = "mapValues(properties_group_custom)"
- type = "bloom_filter"
- granularity = 1
- }
- index "properties_group_ai_keys_bf" {
- expr = "mapKeys(properties_group_ai)"
- type = "bloom_filter"
- granularity = 1
- }
- index "properties_group_ai_values_bf" {
- expr = "mapValues(properties_group_ai)"
- type = "bloom_filter"
- granularity = 1
- }
- index "properties_group_feature_flags_keys_bf" {
- expr = "mapKeys(properties_group_feature_flags)"
- type = "bloom_filter"
- granularity = 1
- }
- index "properties_group_feature_flags_values_bf" {
- expr = "mapValues(properties_group_feature_flags)"
- type = "bloom_filter"
- granularity = 1
- }
- index "person_properties_map_custom_keys_bf" {
- expr = "mapKeys(person_properties_map_custom)"
- type = "bloom_filter"
- granularity = 1
- }
- index "person_properties_map_custom_values_bf" {
- expr = "mapValues(person_properties_map_custom)"
- type = "bloom_filter"
- granularity = 1
- }
- index "kafka_timestamp_minmax_sharded_events" {
- expr = "_timestamp"
- type = "minmax"
- granularity = 3
- }
- index "minmax_inserted_at" {
- expr = "coalesce(inserted_at, _timestamp)"
- type = "minmax"
- granularity = 1
- }
- index "is_deleted_idx" {
- expr = "(is_deleted)"
- type = "minmax"
- granularity = 1
- }
- index "bloom_filter_$ai_trace_id" {
- expr = "`mat_$ai_trace_id`"
- type = "bloom_filter(0.001)"
- granularity = 2
- }
- index "bloom_filter_$ai_session_id" {
- expr = "`mat_$ai_session_id`"
- type = "bloom_filter"
- granularity = 1
- }
- index "minmax_$ai_session_id" {
- expr = "`mat_$ai_session_id`"
- type = "minmax"
- granularity = 1
- }
- index "set_$ai_is_error" {
- expr = "`mat_$ai_is_error`"
- type = "set(7)"
- granularity = 1
- }
- index "bloom_filter_distinct_id" {
- expr = "distinct_id"
- type = "bloom_filter"
- granularity = 1
+ column "_partition" {
+ type = "UInt64"
}
- index "minmax_sharded_events_timestamp" {
- expr = "timestamp"
- type = "minmax"
- granularity = 1
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_app_metrics2"
+ replica_name = "{replica}"
}
- index "minmax_historical_migration" {
- expr = "(historical_migration)"
- type = "minmax"
- granularity = 1
+ }
+ table "sharded_distinct_id_usage" {
+ order_by = ["team_id", "minute", "distinct_id"]
+ partition_by = "toYYYYMMDD(minute)"
+ ttl = "toDate(minute) + toIntervalDay(7)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
}
- index "bloom_filter_$ai_prompt_name" {
- expr = "`mat_$ai_prompt_name`"
- type = "bloom_filter"
- granularity = 1
+ column "team_id" {
+ type = "Int64"
}
- index "minmax_$ai_prompt_name" {
- expr = "`mat_$ai_prompt_name`"
- type = "minmax"
- granularity = 1
+ column "distinct_id" {
+ type = "String"
}
- index "bloom_filter_$ai_experiment_id" {
- expr = "`mat_$ai_experiment_id`"
- type = "bloom_filter"
- granularity = 1
+ column "minute" {
+ type = "DateTime"
}
- index "minmax_$ai_experiment_id" {
- expr = "`mat_$ai_experiment_id`"
- type = "minmax"
- granularity = 1
+ column "event_count" {
+ type = "UInt64"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.events"
- replica_name = "{replica}"
- version_column = "_timestamp"
+ engine "replicated_summing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.distinct_id_usage"
+ replica_name = "{replica}"
+ sum_columns = ["event_count"]
}
}
table "sharded_experiment_exposures_preaggregated" {
@@ -8450,4 +7855,226 @@ SQL
preallocate = 1
}
}
+ patch_table "sharded_events" {
+ modify_column "$group_0" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_0"
+ }
+ modify_column "$group_1" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_1"
+ }
+ modify_column "$group_2" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_2"
+ }
+ modify_column "$group_3" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_3"
+ }
+ modify_column "$group_4" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_4"
+ }
+ modify_column "$window_id" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$window_id"
+ }
+ modify_column "$session_id" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$session_id"
+ }
+ modify_column "properties_group_custom" {
+ type = "Map(String, String)"
+ materialized = "mapSort(mapFilter((key, _) -> ((key NOT LIKE '$%') AND (key NOT IN ('token', 'distinct_id', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'gclid', 'gad_source', 'gclsrc', 'dclid', 'gbraid', 'wbraid', 'fbclid', 'msclkid', 'twclid', 'li_fat_id', 'mc_cid', 'igshid', 'ttclid', 'rdt_cid', 'epik', 'qclid', 'sccid', 'irclid', '_kx'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
+ codec = "ZSTD(1)"
+ }
+ drop_columns = ["mat_historical_migration"]
+ column "elements_chain" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group4_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ materialized = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
+ }
+ drop_indexes = ["minmax_mat_historical_migration", "is_deleted_idx", "minmax_historical_migration"]
+ index "minmax_$group_0" {
+ expr = "`$group_0`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$group_1" {
+ expr = "`$group_1`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$group_2" {
+ expr = "`$group_2`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$group_3" {
+ expr = "`$group_3`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$group_4" {
+ expr = "`$group_4`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$window_id" {
+ expr = "`$window_id`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$session_id" {
+ expr = "`$session_id`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "kafka_timestamp_minmax_sharded_events" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ index "is_deleted_idx" {
+ expr = "(is_deleted)"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_historical_migration" {
+ expr = "(historical_migration)"
+ type = "minmax"
+ granularity = 1
+ }
+ }
+
+ patch_table "events" {
+ modify_column "properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ drop_columns = ["mat_historical_migration"]
+ column "elements_chain" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group4_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_trace_id"
+ }
+ column "mat_$ai_experiment_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_experiment_id"
+ }
+ }
}
diff --git a/posthog/clickhouse/hcl/roles/data/shared/tables.hcl b/posthog/clickhouse/hcl/roles/data/shared/tables.hcl
new file mode 100644
index 000000000000..3e084138f40f
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/data/shared/tables.hcl
@@ -0,0 +1,404 @@
+# The events family: one abstract core backing both the storage table and its
+# Distributed proxy (defined once, per migration.md). Env deltas are patch_table
+# blocks: roles/data/local here, overrides/data/<env> in posthog-cloud-infra.
+database "posthog" {
+ table "_event_base" {
+ abstract = true
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "$group_0" {
+ type = "String"
+ }
+ column "$group_1" {
+ type = "String"
+ }
+ column "$group_2" {
+ type = "String"
+ }
+ column "$group_3" {
+ type = "String"
+ }
+ column "$group_4" {
+ type = "String"
+ }
+ column "$window_id" {
+ type = "String"
+ }
+ column "$session_id" {
+ type = "String"
+ }
+ column "inserted_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ default = "now64()"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ column "elements_chain_href" {
+ type = "String"
+ }
+ column "elements_chain_texts" {
+ type = "Array(String)"
+ }
+ column "elements_chain_ids" {
+ type = "Array(String)"
+ }
+ column "elements_chain_elements" {
+ type = "Array(Enum8('a'=1, 'button'=2, 'form'=3, 'input'=4, 'select'=5, 'textarea'=6, 'label'=7))"
+ }
+ column "properties_group_custom" {
+ type = "Map(String, String)"
+ }
+ column "properties_group_feature_flags" {
+ type = "Map(String, String)"
+ }
+ column "is_deleted" {
+ type = "Bool"
+ }
+ column "person_properties_map_custom" {
+ type = "Map(String, String)"
+ }
+ column "$session_id_uuid" {
+ type = "Nullable(UInt128)"
+ }
+ column "consumer_breadcrumbs" {
+ type = "Array(String)"
+ }
+ column "properties_group_ai" {
+ type = "Map(String, String)"
+ }
+ column "mat_historical_migration" {
+ type = "Nullable(String)"
+ }
+ column "mat_$ai_session_id" {
+ type = "Nullable(String)"
+ }
+ column "mat_$ai_is_error" {
+ type = "Nullable(String)"
+ }
+ column "dmat_string_0" {
+ type = "Nullable(String)"
+ }
+ column "dmat_string_1" {
+ type = "Nullable(String)"
+ }
+ column "dmat_string_2" {
+ type = "Nullable(String)"
+ }
+ column "dmat_string_3" {
+ type = "Nullable(String)"
+ }
+ column "dmat_string_4" {
+ type = "Nullable(String)"
+ }
+ column "dmat_string_5" {
+ type = "Nullable(String)"
+ }
+ column "dmat_string_6" {
+ type = "Nullable(String)"
+ }
+ column "dmat_string_7" {
+ type = "Nullable(String)"
+ }
+ column "dmat_string_8" {
+ type = "Nullable(String)"
+ }
+ column "dmat_string_9" {
+ type = "Nullable(String)"
+ }
+ column "historical_migration" {
+ type = "Bool"
+ }
+ column "mat_$ai_prompt_name" {
+ type = "Nullable(String)"
+ }
+ }
+
+ table "sharded_events" {
+ extend = "_event_base"
+ patch_column "properties" {
+ codec = "ZSTD(3)"
+ }
+ patch_column "$group_0" {
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_0"
+ }
+ patch_column "$group_1" {
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_1"
+ }
+ patch_column "$group_2" {
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_2"
+ }
+ patch_column "$group_3" {
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_3"
+ }
+ patch_column "$group_4" {
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_4"
+ }
+ patch_column "$window_id" {
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$window_id"
+ }
+ patch_column "$session_id" {
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$session_id"
+ }
+ patch_column "elements_chain_href" {
+ materialized = "EXTRACT(elements_chain, '(?::|\")href=\"(.*?)\"')"
+ }
+ patch_column "elements_chain_texts" {
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")text=\"(.*?)\"'))"
+ }
+ patch_column "elements_chain_ids" {
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
+ }
+ patch_column "elements_chain_elements" {
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?:^|;)(a|button|form|input|select|textarea|label)(?:\\\\.|$|:)'))"
+ }
+ patch_column "properties_group_custom" {
+ materialized = "mapSort(mapFilter((key, _) -> ((key NOT LIKE '$%') AND (key NOT IN ('token', 'distinct_id', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'gclid', 'gad_source', 'gclsrc', 'dclid', 'gbraid', 'wbraid', 'fbclid', 'msclkid', 'twclid', 'li_fat_id', 'mc_cid', 'igshid', 'ttclid', 'rdt_cid'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
+ codec = "ZSTD(1)"
+ }
+ patch_column "properties_group_feature_flags" {
+ materialized = "mapSort(mapFilter((key, _) -> (key LIKE '$feature/%'), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
+ codec = "ZSTD(1)"
+ }
+ patch_column "person_properties_map_custom" {
+ materialized = "mapSort(mapFilter((key, _) -> (key NOT LIKE '$%'), CAST(JSONExtractKeysAndValues(person_properties, 'String'), 'Map(String, String)')))"
+ codec = "ZSTD(1)"
+ }
+ patch_column "$session_id_uuid" {
+ materialized = "toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)'))"
+ }
+ patch_column "properties_group_ai" {
+ materialized = "mapSort(mapFilter((key, _) -> ((key LIKE '$ai_%') AND (key NOT IN ('$ai_input', '$ai_input_state', '$ai_output', '$ai_output_choices', '$ai_output_state', '$ai_tools'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
+ codec = "ZSTD(1)"
+ }
+ patch_column "mat_historical_migration" {
+ default = "JSONExtract(properties, 'historical_migration', 'Nullable(String)')"
+ }
+ patch_column "mat_$ai_session_id" {
+ materialized = "JSONExtract(properties, '$ai_session_id', 'Nullable(String)')"
+ }
+ patch_column "mat_$ai_is_error" {
+ materialized = "JSONExtract(properties, '$ai_is_error', 'Nullable(String)')"
+ }
+ patch_column "mat_$ai_prompt_name" {
+ materialized = "JSONExtract(properties, '$ai_prompt_name', 'Nullable(String)')"
+ }
+ column "properties_map_ephemeral" {
+ type = "Map(String, String)"
+ }
+ column "person_properties_map_ephemeral" {
+ type = "Map(String, String)"
+ }
+ column "mat_$ai_experiment_id" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, '$ai_experiment_id', 'Nullable(String)')"
+ }
+ order_by = ["team_id", "toDate(timestamp)", "event", "cityHash64(distinct_id)", "cityHash64(uuid)"]
+ partition_by = "toYYYYMM(timestamp)"
+ sample_by = "cityHash64(distinct_id)"
+ settings = {
+ index_granularity = "8192"
+ }
+ index "minmax_inserted_at" {
+ expr = "coalesce(inserted_at, _timestamp)"
+ type = "minmax"
+ granularity = 1
+ }
+ index "properties_group_custom_keys_bf" {
+ expr = "mapKeys(properties_group_custom)"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "properties_group_custom_values_bf" {
+ expr = "mapValues(properties_group_custom)"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "properties_group_feature_flags_keys_bf" {
+ expr = "mapKeys(properties_group_feature_flags)"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "properties_group_feature_flags_values_bf" {
+ expr = "mapValues(properties_group_feature_flags)"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "is_deleted_idx" {
+ expr = "is_deleted"
+ type = "minmax"
+ granularity = 1
+ }
+ index "person_properties_map_custom_keys_bf" {
+ expr = "mapKeys(person_properties_map_custom)"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "person_properties_map_custom_values_bf" {
+ expr = "mapValues(person_properties_map_custom)"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "properties_group_ai_keys_bf" {
+ expr = "mapKeys(properties_group_ai)"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "properties_group_ai_values_bf" {
+ expr = "mapValues(properties_group_ai)"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "bloom_filter_$ai_trace_id" {
+ expr = "`mat_$ai_trace_id`"
+ type = "bloom_filter(0.001)"
+ granularity = 2
+ }
+ index "minmax_mat_historical_migration" {
+ expr = "mat_historical_migration"
+ type = "minmax"
+ granularity = 1
+ }
+ index "bloom_filter_$ai_session_id" {
+ expr = "`mat_$ai_session_id`"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "minmax_$ai_session_id" {
+ expr = "`mat_$ai_session_id`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "set_$ai_is_error" {
+ expr = "`mat_$ai_is_error`"
+ type = "set(7)"
+ granularity = 1
+ }
+ index "bloom_filter_distinct_id" {
+ expr = "distinct_id"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "minmax_sharded_events_timestamp" {
+ expr = "timestamp"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_historical_migration" {
+ expr = "historical_migration"
+ type = "minmax"
+ granularity = 1
+ }
+ index "bloom_filter_$ai_prompt_name" {
+ expr = "`mat_$ai_prompt_name`"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "minmax_$ai_prompt_name" {
+ expr = "`mat_$ai_prompt_name`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "bloom_filter_$ai_experiment_id" {
+ expr = "`mat_$ai_experiment_id`"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "minmax_$ai_experiment_id" {
+ expr = "`mat_$ai_experiment_id`"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_$session_id_uuid" {
+ expr = "`$session_id_uuid`"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.events"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "events" {
+ extend = "_event_base"
+ patch_column "$group_0" {
+ comment = "column_materializer::$group_0"
+ }
+ patch_column "$group_1" {
+ comment = "column_materializer::$group_1"
+ }
+ patch_column "$group_2" {
+ comment = "column_materializer::$group_2"
+ }
+ patch_column "$group_3" {
+ comment = "column_materializer::$group_3"
+ }
+ patch_column "$group_4" {
+ comment = "column_materializer::$group_4"
+ }
+ patch_column "$window_id" {
+ comment = "column_materializer::$window_id"
+ }
+ patch_column "$session_id" {
+ comment = "column_materializer::$session_id"
+ }
+ patch_column "elements_chain_href" {
+ comment = "column_materializer::elements_chain::href"
+ }
+ patch_column "elements_chain_texts" {
+ comment = "column_materializer::elements_chain::texts"
+ }
+ patch_column "elements_chain_ids" {
+ comment = "column_materializer::elements_chain::ids"
+ }
+ patch_column "elements_chain_elements" {
+ comment = "column_materializer::elements_chain::elements"
+ }
+ patch_column "mat_historical_migration" {
+ comment = "column_materializer::properties::historical_migration"
+ }
+ patch_column "mat_$ai_session_id" {
+ comment = "column_materializer::properties::$ai_session_id"
+ }
+ patch_column "mat_$ai_is_error" {
+ comment = "column_materializer::properties::$ai_is_error"
+ }
+ patch_column "mat_$ai_prompt_name" {
+ comment = "column_materializer::properties::$ai_prompt_name"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/sql/local-multi/data.sql b/posthog/clickhouse/hcl/sql/local-multi/data.sql
index 6a5ae2b8c176..461b3940b6a2 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/data.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/data.sql
@@ -908,33 +908,7 @@ CREATE TABLE posthog.sharded_events (
timestamp DateTime64(6, 'UTC'),
team_id Int64,
distinct_id String,
- elements_chain String,
created_at DateTime64(6, 'UTC'),
- person_id UUID,
- person_created_at DateTime64(3),
- person_properties String CODEC(ZSTD(3)),
- group0_properties String CODEC(ZSTD(3)),
- group1_properties String CODEC(ZSTD(3)),
- group2_properties String CODEC(ZSTD(3)),
- group3_properties String CODEC(ZSTD(3)),
- group4_properties String CODEC(ZSTD(3)),
- group0_created_at DateTime64(3),
- group1_created_at DateTime64(3),
- group2_created_at DateTime64(3),
- group3_created_at DateTime64(3),
- group4_created_at DateTime64(3),
- person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),
- historical_migration Bool,
- dmat_string_0 Nullable(String),
- dmat_string_1 Nullable(String),
- dmat_string_2 Nullable(String),
- dmat_string_3 Nullable(String),
- dmat_string_4 Nullable(String),
- dmat_string_5 Nullable(String),
- dmat_string_6 Nullable(String),
- dmat_string_7 Nullable(String),
- dmat_string_8 Nullable(String),
- dmat_string_9 Nullable(String),
$group_0 String MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0',
$group_1 String MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1',
$group_2 String MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^"|"$', '') COMMENT 'column_materializer::$group_2',
@@ -942,57 +916,83 @@ CREATE TABLE posthog.sharded_events (
$group_4 String MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^"|"$', '') COMMENT 'column_materializer::$group_4',
$window_id String MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^"|"$', '') COMMENT 'column_materializer::$window_id',
$session_id String MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^"|"$', '') COMMENT 'column_materializer::$session_id',
- $session_id_uuid Nullable(UInt128) MATERIALIZED toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)')),
+ inserted_at Nullable(DateTime64(6, 'UTC')) DEFAULT now64(),
+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),
elements_chain_href String MATERIALIZED EXTRACT(elements_chain, '(?::|")href="(.*?)"'),
elements_chain_texts Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")text="(.*?)"')),
+ elements_chain_ids Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")attr_id="(.*?)"')),
elements_chain_elements Array(Enum8('a'=1, 'button'=2, 'form'=3, 'input'=4, 'select'=5, 'textarea'=6, 'label'=7)) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?:^|;)(a|button|form|input|select|textarea|label)(?:\\.|$|:)')),
properties_group_custom Map(String, String) MATERIALIZED mapSort(mapFilter((key, _) -> ((key NOT LIKE '$%') AND (key NOT IN ('token', 'distinct_id', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'gclid', 'gad_source', 'gclsrc', 'dclid', 'gbraid', 'wbraid', 'fbclid', 'msclkid', 'twclid', 'li_fat_id', 'mc_cid', 'igshid', 'ttclid', 'rdt_cid', 'epik', 'qclid', 'sccid', 'irclid', '_kx'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)'))) CODEC(ZSTD(1)),
- properties_group_ai Map(String, String) MATERIALIZED mapSort(mapFilter((key, _) -> ((key LIKE '$ai_%') AND (key NOT IN ('$ai_input', '$ai_input_state', '$ai_output', '$ai_output_choices', '$ai_output_state', '$ai_tools'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)'))) CODEC(ZSTD(1)),
properties_group_feature_flags Map(String, String) MATERIALIZED mapSort(mapFilter((key, _) -> (key LIKE '$feature/%'), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)'))) CODEC(ZSTD(1)),
+ is_deleted Bool,
person_properties_map_custom Map(String, String) MATERIALIZED mapSort(mapFilter((key, _) -> (key NOT LIKE '$%'), CAST(JSONExtractKeysAndValues(person_properties, 'String'), 'Map(String, String)'))) CODEC(ZSTD(1)),
- _timestamp DateTime,
- _offset UInt64,
- inserted_at Nullable(DateTime64(6, 'UTC')) DEFAULT now64(),
+ $session_id_uuid Nullable(UInt128) MATERIALIZED toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)')),
consumer_breadcrumbs Array(String),
- elements_chain_ids Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")attr_id="(.*?)"')),
- is_deleted Bool,
- properties_map_ephemeral Map(String, String),
- person_properties_map_ephemeral Map(String, String),
- mat_$ai_trace_id Nullable(String) MATERIALIZED JSONExtract(properties, '$ai_trace_id', 'Nullable(String)'),
+ properties_group_ai Map(String, String) MATERIALIZED mapSort(mapFilter((key, _) -> ((key LIKE '$ai_%') AND (key NOT IN ('$ai_input', '$ai_input_state', '$ai_output', '$ai_output_choices', '$ai_output_state', '$ai_tools'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)'))) CODEC(ZSTD(1)),
mat_$ai_session_id Nullable(String) MATERIALIZED JSONExtract(properties, '$ai_session_id', 'Nullable(String)'),
mat_$ai_is_error Nullable(String) MATERIALIZED JSONExtract(properties, '$ai_is_error', 'Nullable(String)'),
+ dmat_string_0 Nullable(String),
+ dmat_string_1 Nullable(String),
+ dmat_string_2 Nullable(String),
+ dmat_string_3 Nullable(String),
+ dmat_string_4 Nullable(String),
+ dmat_string_5 Nullable(String),
+ dmat_string_6 Nullable(String),
+ dmat_string_7 Nullable(String),
+ dmat_string_8 Nullable(String),
+ dmat_string_9 Nullable(String),
+ historical_migration Bool,
mat_$ai_prompt_name Nullable(String) MATERIALIZED JSONExtract(properties, '$ai_prompt_name', 'Nullable(String)'),
+ properties_map_ephemeral Map(String, String),
+ person_properties_map_ephemeral Map(String, String),
mat_$ai_experiment_id Nullable(String) DEFAULT JSONExtract(properties, '$ai_experiment_id', 'Nullable(String)'),
- INDEX minmax_$group_0 `$group_0` TYPE minmax GRANULARITY 1,
- INDEX minmax_$group_1 `$group_1` TYPE minmax GRANULARITY 1,
- INDEX minmax_$group_2 `$group_2` TYPE minmax GRANULARITY 1,
- INDEX minmax_$group_3 `$group_3` TYPE minmax GRANULARITY 1,
- INDEX minmax_$group_4 `$group_4` TYPE minmax GRANULARITY 1,
- INDEX minmax_$window_id `$window_id` TYPE minmax GRANULARITY 1,
- INDEX minmax_$session_id `$session_id` TYPE minmax GRANULARITY 1,
- INDEX minmax_$session_id_uuid `$session_id_uuid` TYPE minmax GRANULARITY 1,
+ elements_chain String,
+ person_id UUID,
+ person_created_at DateTime64(3),
+ person_properties String CODEC(ZSTD(3)),
+ group0_properties String CODEC(ZSTD(3)),
+ group1_properties String CODEC(ZSTD(3)),
+ group2_properties String CODEC(ZSTD(3)),
+ group3_properties String CODEC(ZSTD(3)),
+ group4_properties String CODEC(ZSTD(3)),
+ group0_created_at DateTime64(3),
+ group1_created_at DateTime64(3),
+ group2_created_at DateTime64(3),
+ group3_created_at DateTime64(3),
+ group4_created_at DateTime64(3),
+ _timestamp DateTime,
+ _offset UInt64,
+ mat_$ai_trace_id Nullable(String) MATERIALIZED JSONExtract(properties, '$ai_trace_id', 'Nullable(String)'),
+ INDEX minmax_inserted_at coalesce(inserted_at, _timestamp) TYPE minmax GRANULARITY 1,
INDEX properties_group_custom_keys_bf mapKeys(properties_group_custom) TYPE bloom_filter GRANULARITY 1,
INDEX properties_group_custom_values_bf mapValues(properties_group_custom) TYPE bloom_filter GRANULARITY 1,
- INDEX properties_group_ai_keys_bf mapKeys(properties_group_ai) TYPE bloom_filter GRANULARITY 1,
- INDEX properties_group_ai_values_bf mapValues(properties_group_ai) TYPE bloom_filter GRANULARITY 1,
INDEX properties_group_feature_flags_keys_bf mapKeys(properties_group_feature_flags) TYPE bloom_filter GRANULARITY 1,
INDEX properties_group_feature_flags_values_bf mapValues(properties_group_feature_flags) TYPE bloom_filter GRANULARITY 1,
INDEX person_properties_map_custom_keys_bf mapKeys(person_properties_map_custom) TYPE bloom_filter GRANULARITY 1,
INDEX person_properties_map_custom_values_bf mapValues(person_properties_map_custom) TYPE bloom_filter GRANULARITY 1,
- INDEX kafka_timestamp_minmax_sharded_events _timestamp TYPE minmax GRANULARITY 3,
- INDEX minmax_inserted_at coalesce(inserted_at, _timestamp) TYPE minmax GRANULARITY 1,
- INDEX is_deleted_idx is_deleted TYPE minmax GRANULARITY 1,
+ INDEX properties_group_ai_keys_bf mapKeys(properties_group_ai) TYPE bloom_filter GRANULARITY 1,
+ INDEX properties_group_ai_values_bf mapValues(properties_group_ai) TYPE bloom_filter GRANULARITY 1,
INDEX bloom_filter_$ai_trace_id `mat_$ai_trace_id` TYPE bloom_filter(0.001) GRANULARITY 2,
INDEX bloom_filter_$ai_session_id `mat_$ai_session_id` TYPE bloom_filter GRANULARITY 1,
INDEX minmax_$ai_session_id `mat_$ai_session_id` TYPE minmax GRANULARITY 1,
INDEX set_$ai_is_error `mat_$ai_is_error` TYPE set(7) GRANULARITY 1,
INDEX bloom_filter_distinct_id distinct_id TYPE bloom_filter GRANULARITY 1,
INDEX minmax_sharded_events_timestamp timestamp TYPE minmax GRANULARITY 1,
- INDEX minmax_historical_migration historical_migration TYPE minmax GRANULARITY 1,
INDEX bloom_filter_$ai_prompt_name `mat_$ai_prompt_name` TYPE bloom_filter GRANULARITY 1,
INDEX minmax_$ai_prompt_name `mat_$ai_prompt_name` TYPE minmax GRANULARITY 1,
INDEX bloom_filter_$ai_experiment_id `mat_$ai_experiment_id` TYPE bloom_filter GRANULARITY 1,
- INDEX minmax_$ai_experiment_id `mat_$ai_experiment_id` TYPE minmax GRANULARITY 1
+ INDEX minmax_$ai_experiment_id `mat_$ai_experiment_id` TYPE minmax GRANULARITY 1,
+ INDEX minmax_$session_id_uuid `$session_id_uuid` TYPE minmax GRANULARITY 1,
+ INDEX minmax_$group_0 `$group_0` TYPE minmax GRANULARITY 1,
+ INDEX minmax_$group_1 `$group_1` TYPE minmax GRANULARITY 1,
+ INDEX minmax_$group_2 `$group_2` TYPE minmax GRANULARITY 1,
+ INDEX minmax_$group_3 `$group_3` TYPE minmax GRANULARITY 1,
+ INDEX minmax_$group_4 `$group_4` TYPE minmax GRANULARITY 1,
+ INDEX minmax_$window_id `$window_id` TYPE minmax GRANULARITY 1,
+ INDEX minmax_$session_id `$session_id` TYPE minmax GRANULARITY 1,
+ INDEX kafka_timestamp_minmax_sharded_events _timestamp TYPE minmax GRANULARITY 3,
+ INDEX is_deleted_idx is_deleted TYPE minmax GRANULARITY 1,
+ INDEX minmax_historical_migration historical_migration TYPE minmax GRANULARITY 1
) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.events', '{replica}', _timestamp) ORDER BY (team_id, toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) PARTITION BY toYYYYMM(timestamp) SAMPLE BY cityHash64(distinct_id) SETTINGS index_granularity = 8192;
CREATE TABLE posthog.sharded_events_json (
uuid UUID,
@@ -2981,33 +2981,7 @@ CREATE TABLE posthog.events (
timestamp DateTime64(6, 'UTC'),
team_id Int64,
distinct_id String,
- elements_chain String,
created_at DateTime64(6, 'UTC'),
- person_id UUID,
- person_created_at DateTime64(3),
- person_properties String CODEC(ZSTD(3)),
- group0_properties String CODEC(ZSTD(3)),
- group1_properties String CODEC(ZSTD(3)),
- group2_properties String CODEC(ZSTD(3)),
- group3_properties String CODEC(ZSTD(3)),
- group4_properties String CODEC(ZSTD(3)),
- group0_created_at DateTime64(3),
- group1_created_at DateTime64(3),
- group2_created_at DateTime64(3),
- group3_created_at DateTime64(3),
- group4_created_at DateTime64(3),
- person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),
- historical_migration Bool,
- dmat_string_0 Nullable(String),
- dmat_string_1 Nullable(String),
- dmat_string_2 Nullable(String),
- dmat_string_3 Nullable(String),
- dmat_string_4 Nullable(String),
- dmat_string_5 Nullable(String),
- dmat_string_6 Nullable(String),
- dmat_string_7 Nullable(String),
- dmat_string_8 Nullable(String),
- dmat_string_9 Nullable(String),
$group_0 String COMMENT 'column_materializer::$group_0',
$group_1 String COMMENT 'column_materializer::$group_1',
$group_2 String COMMENT 'column_materializer::$group_2',
@@ -3015,24 +2989,50 @@ CREATE TABLE posthog.events (
$group_4 String COMMENT 'column_materializer::$group_4',
$window_id String COMMENT 'column_materializer::$window_id',
$session_id String COMMENT 'column_materializer::$session_id',
- $session_id_uuid Nullable(UInt128),
+ inserted_at Nullable(DateTime64(6, 'UTC')) DEFAULT now64(),
+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),
elements_chain_href String COMMENT 'column_materializer::elements_chain::href',
elements_chain_texts Array(String) COMMENT 'column_materializer::elements_chain::texts',
elements_chain_ids Array(String) COMMENT 'column_materializer::elements_chain::ids',
elements_chain_elements Array(Enum8('a'=1, 'button'=2, 'form'=3, 'input'=4, 'select'=5, 'textarea'=6, 'label'=7)) COMMENT 'column_materializer::elements_chain::elements',
properties_group_custom Map(String, String),
- properties_group_ai Map(String, String),
properties_group_feature_flags Map(String, String),
+ is_deleted Bool,
person_properties_map_custom Map(String, String),
- _timestamp DateTime,
- _offset UInt64,
- inserted_at Nullable(DateTime64(6, 'UTC')) DEFAULT now64(),
+ $session_id_uuid Nullable(UInt128),
consumer_breadcrumbs Array(String),
- is_deleted Bool,
- mat_$ai_trace_id Nullable(String) COMMENT 'column_materializer::properties::$ai_trace_id',
+ properties_group_ai Map(String, String),
mat_$ai_session_id Nullable(String) COMMENT 'column_materializer::properties::$ai_session_id',
mat_$ai_is_error Nullable(String) COMMENT 'column_materializer::properties::$ai_is_error',
+ dmat_string_0 Nullable(String),
+ dmat_string_1 Nullable(String),
+ dmat_string_2 Nullable(String),
+ dmat_string_3 Nullable(String),
+ dmat_string_4 Nullable(String),
+ dmat_string_5 Nullable(String),
+ dmat_string_6 Nullable(String),
+ dmat_string_7 Nullable(String),
+ dmat_string_8 Nullable(String),
+ dmat_string_9 Nullable(String),
+ historical_migration Bool,
mat_$ai_prompt_name Nullable(String) COMMENT 'column_materializer::properties::$ai_prompt_name',
+ elements_chain String,
+ person_id UUID,
+ person_created_at DateTime64(3),
+ person_properties String CODEC(ZSTD(3)),
+ group0_properties String CODEC(ZSTD(3)),
+ group1_properties String CODEC(ZSTD(3)),
+ group2_properties String CODEC(ZSTD(3)),
+ group3_properties String CODEC(ZSTD(3)),
+ group4_properties String CODEC(ZSTD(3)),
+ group0_created_at DateTime64(3),
+ group1_created_at DateTime64(3),
+ group2_created_at DateTime64(3),
+ group3_created_at DateTime64(3),
+ group4_created_at DateTime64(3),
+ _timestamp DateTime,
+ _offset UInt64,
+ mat_$ai_trace_id Nullable(String) COMMENT 'column_materializer::properties::$ai_trace_id',
mat_$ai_experiment_id Nullable(String) COMMENT 'column_materializer::properties::$ai_experiment_id'
) ENGINE = Distributed('posthog', 'posthog', 'sharded_events', sipHash64(distinct_id));
CREATE TABLE posthog.events_json (