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.

feat(clickhouse): declare the cloud data clusters (#95026)

Paweł Szczur4416938d8637
diff --git a/posthog/clickhouse/hcl/bin/image.txt b/posthog/clickhouse/hcl/bin/image.txt
index a4575c1a6633..4e2c24ffe124 100644
--- a/posthog/clickhouse/hcl/bin/image.txt
+++ b/posthog/clickhouse/hcl/bin/image.txt
@@ -1 +1 @@
-ghcr.io/posthog/chschema:sha-89109e5
+ghcr.io/posthog/chschema:sha-46db733
diff --git a/posthog/clickhouse/hcl/check.sh b/posthog/clickhouse/hcl/check.sh
index 89547b09b49a..b436bf7f1902 100755
--- a/posthog/clickhouse/hcl/check.sh
+++ b/posthog/clickhouse/hcl/check.sh
@@ -28,6 +28,23 @@ known_drift_skip() {
# migration 0155 dropped on DATA; the ingestion-side objects survived because
# 0155 targeted the wrong role, and 0253's cleanup is cloud-only.
local-multi|local-single) echo "writable_error_tracking_issue_fingerprint_embeddings" ;;
+
+ # Cross-cluster validation only started resolving for the cloud envs when the data
+ # role gained env blocks: before that the `posthog` cluster was @absent there and
+ # every remote was skipped. What it found is live state, not a modelling mistake,
+ # so each name below is drift to carry rather than a declaration to change.
+ #
+ # events, events_main, writable_*, distributed_* -- proxies whose remote lives on
+ # a cluster the env does not compose (batch_exports, ai_events, aux), or whose
+ # column set genuinely disagrees with the remote today. The sessions events
+ # proxy is the clearest: it declares elements_hash and properties_group_ai_large,
+ # which sharded_events does not have on any data cluster.
+ # web_*_distributed, session_replay_events, log_entries_distributed,
+ # persons_*_up_to_date_view -- same shape, different remote.
+ #
+ # Remove a name once its two sides agree. Do not add one without a drift-catalog row.
+ dev|prod-us|prod-eu) echo "ai_events,billing_usage_records,distributed_events_recent,distributed_posthog_document_embeddings,events,events_main,log_entries_distributed,new_raw_sessions,new_sessions,new_writable_raw_sessions,new_writable_sessions,persons_properties_up_to_date_view,persons_up_to_date_view,session_recording_events,session_replay_events,session_replay_features_mv,web_bounces_daily_distributed,web_bounces_hourly_distributed,web_stats_daily_distributed,web_stats_hourly_distributed,writable_events_recent,writable_ingestion_warnings,writable_posthog_document_embeddings,writable_raw_sessions_primary,writable_raw_sessions_v3,writable_session_recording_events,writable_session_replay_events,writable_sessions,writable_sessions_background" ;;
+
*) echo "" ;;
esac
}
diff --git a/posthog/clickhouse/hcl/exclude.hcl b/posthog/clickhouse/hcl/exclude.hcl
index cb633d414173..43992d3c8d76 100644
--- a/posthog/clickhouse/hcl/exclude.hcl
+++ b/posthog/clickhouse/hcl/exclude.hcl
@@ -43,6 +43,28 @@ exclude {
"events_main",
"events_recent",
+ # --- per-customer and adhoc tables on the cloud data clusters ---
+ # A team-numbered table belongs to one customer and is not part of the cluster's
+ # schema. The bare [0-9]* glob catches the numeric-prefixed scratch tables that
+ # appear beside them. Both mirror posthog-cloud-infra's exclude.hcl.
+ "team_[0-9]*",
+ "[0-9]*",
+ ".inner_id.*",
+
+ # --- job artifacts, created and dropped out of band ---
+ # Each is named after the run that made it, so the name never repeats and no
+ # golden can track it. The undated siblings (pending_person_deletes_reporting,
+ # the clickhouse_cleanup_* tables themselves) are real schema and stay declared,
+ # which is why these globs require a digit or the _dictionary suffix.
+ "pending_deletes_*",
+ "pending_person_deletes_[0-9]*",
+ "pending_event_deletes_[0-9]*",
+ "person_distinct_id_overrides_snapshot_*",
+ "clickhouse_cleanup_*_dictionary",
+ # The part-breaker job's working tables (posthog/dags/part_breaker.py).
+ "sharded_events_part_breaker",
+ "sharded_events_part_breaker_*",
+
# --- infra-created, never by a migration ---
# Iceberg readers over the logs archive bucket. The bucket is per environment
# and named in the DDL, so declaring these would put one environment's storage
diff --git a/posthog/clickhouse/hcl/golden/dev/data.hcl b/posthog/clickhouse/hcl/golden/dev/data.hcl
new file mode 100644
index 000000000000..53c111b8a906
--- /dev/null
+++ b/posthog/clickhouse/hcl/golden/dev/data.hcl
@@ -0,0 +1,9851 @@
+database "posthog" {
+ table "adhoc_events_deletion" {
+ order_by = ["team_id", "uuid"]
+ ttl = "deleted_at + toIntervalMonth(3) WHERE is_deleted = 1"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ column "deleted_at" {
+ type = "DateTime"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ default = "0"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.adhoc_events_deletion"
+ replica_name = "{replica}-{shard}"
+ version_column = "deleted_at"
+ is_deleted_column = "is_deleted"
+ }
+ }
+
+ table "ai_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "LowCardinality(String)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "retention_days" {
+ type = "Int16"
+ default = "30"
+ }
+ column "drop_date" {
+ type = "Date"
+ materialized = "toDate(timestamp) + toIntervalDay(retention_days)"
+ }
+ column "trace_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "Nullable(String)"
+ }
+ column "parent_id" {
+ type = "Nullable(String)"
+ }
+ column "span_id" {
+ type = "Nullable(String)"
+ }
+ column "span_type" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "generation_id" {
+ type = "Nullable(String)"
+ }
+ column "experiment_id" {
+ type = "Nullable(String)"
+ }
+ column "span_name" {
+ type = "Nullable(String)"
+ }
+ column "trace_name" {
+ type = "Nullable(String)"
+ }
+ column "prompt_name" {
+ type = "Nullable(String)"
+ }
+ column "model" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "provider" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "framework" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "total_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "text_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "text_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "image_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "image_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "audio_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "audio_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "video_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "video_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "reasoning_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "cache_read_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "cache_creation_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "web_search_count" {
+ type = "Nullable(Int64)"
+ }
+ column "input_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "output_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "total_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "request_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "web_search_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "audio_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "image_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "video_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "latency" {
+ type = "Nullable(Float64)"
+ }
+ column "time_to_first_token" {
+ type = "Nullable(Float64)"
+ }
+ column "is_error" {
+ type = "UInt8"
+ }
+ column "error" {
+ type = "Nullable(String)"
+ }
+ column "error_type" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "error_normalized" {
+ type = "Nullable(String)"
+ }
+ column "input" {
+ type = "Nullable(String)"
+ }
+ column "output" {
+ type = "Nullable(String)"
+ }
+ column "output_choices" {
+ type = "Nullable(String)"
+ }
+ column "input_state" {
+ type = "Nullable(String)"
+ }
+ column "output_state" {
+ type = "Nullable(String)"
+ }
+ column "tools" {
+ type = "Nullable(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "ai_events"
+ remote_database = "posthog"
+ remote_table = "sharded_ai_events"
+ sharding_key = "cityHash64(concat(toString(team_id), '-', trace_id, '-', toString(toDate(timestamp))))"
+ }
+ }
+
+ table "app_metrics" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "plugin_config_id" {
+ type = "Int64"
+ }
+ column "category" {
+ type = "LowCardinality(String)"
+ }
+ column "job_id" {
+ type = "String"
+ }
+ column "successes" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "successes_on_retry" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "failures" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "error_uuid" {
+ type = "UUID"
+ }
+ column "error_type" {
+ type = "String"
+ }
+ column "error_details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_app_metrics"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "app_metrics2" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "app_source" {
+ type = "LowCardinality(String)"
+ }
+ column "app_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "metric_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_app_metrics2"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "async_deletion_run" {
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "deletion_type", "key"]
+ }
+ }
+
+ table "billing_usage_records" {
+ column "schema_version" {
+ type = "UInt8"
+ }
+ column "record_id" {
+ type = "String"
+ }
+ column "producer_id" {
+ type = "LowCardinality(String)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "organization_id" {
+ type = "UUID"
+ }
+ column "usage_key" {
+ type = "LowCardinality(String)"
+ }
+ column "unit" {
+ type = "LowCardinality(String)"
+ }
+ column "quantity" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_billing_usage_records"
+ sharding_key = "cityHash64(team_id)"
+ }
+ }
+
+ table "channel_definition" {
+ order_by = ["domain", "kind"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "domain" {
+ type = "String"
+ }
+ column "kind" {
+ type = "String"
+ }
+ column "domain_type" {
+ type = "Nullable(String)"
+ }
+ column "type_if_paid" {
+ type = "Nullable(String)"
+ }
+ column "type_if_organic" {
+ type = "Nullable(String)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.channel_definition"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "clickhouse_cleanup_deleted_persons" {
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "max_version" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_orphaned_distinct_ids" {
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "own_tombstone" {
+ type = "UInt8"
+ }
+ column "max_version" {
+ type = "Int64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_distinct_ids" {
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_persons" {
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "cohort_membership" {
+ order_by = ["team_id", "cohort_id", "person_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "status" {
+ type = "Enum8('entered'=1, 'left'=2)"
+ }
+ column "last_updated" {
+ type = "DateTime64(6)"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.cohort_membership"
+ replica_name = "{replica}-{shard}"
+ version_column = "last_updated"
+ }
+ }
+
+ table "cohortpeople" {
+ order_by = ["team_id", "cohort_id", "person_id", "version"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "sign" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.cohortpeople"
+ replica_name = "{replica}-{shard}"
+ sign_column = "sign"
+ }
+ }
+
+ table "conversion_goal_attributed_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "conversion_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "conversion_value" {
+ type = "Float64"
+ }
+ column "touchpoint_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "touchpoint_weight" {
+ type = "Float64"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "medium_name" {
+ type = "String"
+ }
+ column "content_name" {
+ type = "String"
+ }
+ column "term_name" {
+ type = "String"
+ }
+ column "referring_domain_name" {
+ type = "String"
+ }
+ column "gclid_name" {
+ type = "String"
+ }
+ column "fbclid_name" {
+ type = "String"
+ }
+ column "gad_source_name" {
+ type = "String"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_conversion_goal_attributed_preaggregated"
+ sharding_key = "cityHash64(person_id)"
+ }
+ }
+
+ table "distinct_id_usage" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "minute" {
+ type = "DateTime"
+ }
+ column "event_count" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_distinct_id_usage"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_events_recent" {
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ column "_timestamp_ms" {
+ type = "DateTime64(3)"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings_text_embedding_3_large_3072" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings_text_embedding_3_small_1536" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_system_processes" {
+ settings = {
+ skip_unavailable_shards = "1"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "user" {
+ type = "String"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "address" {
+ type = "IPv6"
+ }
+ column "port" {
+ type = "UInt16"
+ }
+ column "initial_user" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "initial_address" {
+ type = "IPv6"
+ }
+ column "initial_port" {
+ type = "UInt16"
+ }
+ column "interface" {
+ type = "UInt8"
+ }
+ column "os_user" {
+ type = "String"
+ }
+ column "client_hostname" {
+ type = "String"
+ }
+ column "client_name" {
+ type = "String"
+ }
+ column "client_revision" {
+ type = "UInt64"
+ }
+ column "client_version_major" {
+ type = "UInt64"
+ }
+ column "client_version_minor" {
+ type = "UInt64"
+ }
+ column "client_version_patch" {
+ type = "UInt64"
+ }
+ column "http_method" {
+ type = "UInt8"
+ }
+ column "http_user_agent" {
+ type = "String"
+ }
+ column "http_referer" {
+ type = "String"
+ }
+ column "forwarded_for" {
+ type = "String"
+ }
+ column "quota_key" {
+ type = "String"
+ }
+ column "distributed_depth" {
+ type = "UInt64"
+ }
+ column "elapsed" {
+ type = "Float64"
+ }
+ column "is_cancelled" {
+ type = "UInt8"
+ }
+ column "is_all_data_sent" {
+ type = "UInt8"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "total_rows_approx" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "Int64"
+ }
+ column "peak_memory_usage" {
+ type = "Int64"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "query_kind" {
+ type = "String"
+ }
+ column "thread_ids" {
+ type = "Array(UInt64)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "Settings" {
+ type = "Map(String, String)"
+ }
+ column "current_database" {
+ type = "String"
+ }
+ column "ProfileEvents.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(ProfileEvents)"
+ }
+ column "ProfileEvents.Values" {
+ type = "Array(UInt64)"
+ alias = "mapValues(ProfileEvents)"
+ }
+ column "Settings.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(Settings)"
+ }
+ column "Settings.Values" {
+ type = "Array(String)"
+ alias = "mapValues(Settings)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "system"
+ remote_table = "processes"
+ }
+ }
+
+ table "dmat_slot_assignments" {
+ order_by = ["team_id", "column_index"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "column_index" {
+ type = "UInt8"
+ }
+ column "property_name" {
+ type = "String"
+ }
+ column "version" {
+ type = "UInt32"
+ default = "toUnixTimestamp(now())"
+ }
+ engine "replacing_merge_tree" {
+ version_column = "version"
+ }
+ }
+
+ table "dummy" {
+ order_by = ["id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "String"
+ }
+ engine "merge_tree" {
+ }
+ }
+
+ table "dummy_privileges" {
+ order_by = ["id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "String"
+ }
+ engine "merge_tree" {
+ }
+ }
+
+ table "duplicate_events" {
+ order_by = ["team_id", "distinct_id", "event", "inserted_at"]
+ partition_by = "toYYYYMMDD(inserted_at)"
+ ttl = "inserted_at + toIntervalDay(7)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "source_uuid" {
+ type = "UUID"
+ }
+ column "duplicate_uuid" {
+ type = "UUID"
+ }
+ column "similarity_score" {
+ type = "Float64"
+ }
+ column "dedup_type" {
+ type = "LowCardinality(String)"
+ }
+ column "is_confirmed" {
+ type = "UInt8"
+ }
+ column "reason" {
+ type = "Nullable(String)"
+ }
+ column "version" {
+ type = "String"
+ }
+ column "different_property_count" {
+ type = "UInt32"
+ }
+ column "properties_similarity" {
+ type = "Float64"
+ }
+ column "source_message" {
+ type = "String"
+ }
+ column "duplicate_message" {
+ type = "String"
+ }
+ column "distinct_fields" {
+ type = "Array(Tuple(field_name String, original_value String, new_value String))"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_duplicate_events" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.duplicate_events"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "eni_inventory" {
+ order_by = ["eni_id", "ip_address"]
+ partition_by = "toYYYYMMDD(collected_at)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "collected_at" {
+ type = "DateTime"
+ }
+ column "eni_id" {
+ type = "String"
+ }
+ column "ip_address" {
+ type = "String"
+ }
+ column "owner_account" {
+ type = "String"
+ }
+ column "subnet_id" {
+ type = "String"
+ }
+ column "security_groups" {
+ type = "Array(JSON)"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "node_name" {
+ type = "String"
+ }
+ column "karpenter_nodeclaim" {
+ type = "String"
+ }
+ column "karpenter_ec2nodeclass" {
+ type = "String"
+ }
+ engine "replacing_merge_tree" {
+ version_column = "collected_at"
+ }
+ }
+
+ table "error_tracking_fingerprint_issue_state" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "fingerprint" {
+ type = "String"
+ }
+ column "issue_id" {
+ type = "UUID"
+ }
+ column "issue_name" {
+ type = "Nullable(String)"
+ }
+ column "issue_description" {
+ type = "Nullable(String)"
+ }
+ column "issue_status" {
+ type = "String"
+ }
+ column "issue_severity" {
+ type = "Nullable(String)"
+ }
+ column "assigned_user_id" {
+ type = "Nullable(Int64)"
+ }
+ column "assigned_role_id" {
+ type = "Nullable(UUID)"
+ }
+ column "first_seen" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "raw_error_tracking_fingerprint_issue_state"
+ }
+ }
+
+ table "error_tracking_issue_fingerprint_overrides" {
+ order_by = ["team_id", "fingerprint"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "fingerprint" {
+ type = "String"
+ }
+ column "issue_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_error_tracking_issue_fingerprint_overrides" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.error_tracking_issue_fingerprint_overrides"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "events" {
+ 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 "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "person_created_at" {
+ type = "DateTime64(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 "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"
+ 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_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_trace_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_trace_id"
+ }
+ column "mat_historical_migration" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::historical_migration"
+ }
+ 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)"
+ }
+ 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)"
+ comment = "column_materializer::properties::$ai_prompt_name"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "events_dead_letter_queue" {
+ order_by = ["id", "event_uuid", "distinct_id", "team_id"]
+ ttl = "toDate(_timestamp) + toIntervalWeek(4)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "ip" {
+ type = "String"
+ }
+ column "site_url" {
+ type = "String"
+ }
+ column "now" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "raw_payload" {
+ type = "String"
+ }
+ column "error_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "error_location" {
+ type = "String"
+ }
+ column "error" {
+ type = "String"
+ }
+ column "tags" {
+ type = "Array(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.events_dead_letter_queue"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "events_recent" {
+ 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 "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"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "exchange_rate" {
+ order_by = ["date", "currency"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "currency" {
+ type = "String"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "rate" {
+ type = "Decimal(18, 10)"
+ }
+ column "version" {
+ type = "UInt32"
+ default = "toUnixTimestamp(now())"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.exchange_rate"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "experiment_exposures_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "entity_id" {
+ type = "String"
+ }
+ column "variant" {
+ type = "String"
+ }
+ column "first_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "last_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "exposure_event_uuid" {
+ type = "UUID"
+ }
+ column "exposure_session_id" {
+ type = "String"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_experiment_exposures_preaggregated"
+ sharding_key = "cityHash64(entity_id)"
+ }
+ }
+
+ table "experiment_metric_events_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "entity_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "numeric_value" {
+ type = "Float64"
+ default = "0"
+ }
+ column "steps" {
+ type = "Array(UInt8)"
+ default = "[]"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_experiment_metric_events_preaggregated"
+ sharding_key = "cityHash64(entity_id)"
+ }
+ }
+
+ table "flag_evaluations" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "LowCardinality(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 "person_id" {
+ type = "UUID"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "timestamp"
+ }
+ 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 "flag_key" {
+ type = "String"
+ comment = "column_materializer::properties::$feature_flag"
+ }
+ column "response" {
+ type = "LowCardinality(String)"
+ comment = "column_materializer::properties::$feature_flag_response"
+ }
+ column "session_id" {
+ type = "String"
+ comment = "column_materializer::properties::$session_id"
+ }
+ column "request_id" {
+ type = "String"
+ comment = "column_materializer::properties::$feature_flag_request_id"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_flag_evaluations"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "flow_logs_local" {
+ order_by = ["ts_start", "dstport", "dstaddr", "interface_id"]
+ partition_by = "toYYYYMMDD(ts_start)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "interface_id" {
+ type = "String"
+ }
+ column "srcaddr" {
+ type = "String"
+ }
+ column "dstaddr" {
+ type = "String"
+ }
+ column "srcport" {
+ type = "UInt16"
+ }
+ column "dstport" {
+ type = "UInt16"
+ }
+ column "protocol" {
+ type = "UInt8"
+ }
+ column "packets" {
+ type = "UInt32"
+ }
+ column "bytes" {
+ type = "UInt64"
+ }
+ column "ts_start" {
+ type = "DateTime"
+ }
+ column "ts_end" {
+ type = "DateTime"
+ }
+ column "action" {
+ type = "LowCardinality(String)"
+ }
+ column "log_status" {
+ type = "LowCardinality(String)"
+ }
+ engine "merge_tree" {
+ }
+ }
+
+ table "groups" {
+ order_by = ["team_id", "group_type_index", "group_key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "group_type_index" {
+ type = "UInt8"
+ }
+ column "group_key" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "group_properties" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "Bool"
+ }
+ index "is_deleted_idx" {
+ expr = "is_deleted"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.groups"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "groups2" {
+ order_by = ["group_key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "group_key" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.groups2"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "heatmaps" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "x" {
+ type = "Int16"
+ }
+ column "y" {
+ type = "Int16"
+ }
+ column "scale_factor" {
+ type = "Int16"
+ }
+ column "viewport_width" {
+ type = "Int16"
+ }
+ column "viewport_height" {
+ type = "Int16"
+ }
+ column "pointer_target_fixed" {
+ type = "Bool"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_heatmaps"
+ sharding_key = "cityHash64(concat(toString(team_id), '-', session_id, '-', toString(toDate(timestamp))))"
+ }
+ }
+
+ table "hog_invocation_results" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "function_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "function_id" {
+ type = "String"
+ }
+ column "invocation_id" {
+ type = "String"
+ }
+ column "parent_run_id" {
+ type = "String"
+ }
+ column "status" {
+ type = "LowCardinality(String)"
+ }
+ column "attempts" {
+ type = "UInt8"
+ }
+ column "is_retry" {
+ type = "UInt8"
+ }
+ column "scheduled_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "first_scheduled_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "started_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ }
+ column "finished_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ }
+ column "duration_ms" {
+ type = "Nullable(UInt32)"
+ }
+ column "error_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "error_message" {
+ type = "String"
+ }
+ column "event_uuid" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "String"
+ }
+ column "invocation_globals" {
+ type = "String"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "hog_invocation_results_data"
+ }
+ }
+
+ table "ingestion_warnings" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "details" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_ingestion_warnings"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "ingestion_warnings_v2_distributed" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "details" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "category" {
+ type = "LowCardinality(String)"
+ default = "coalesce(nullIf(JSONExtractString(details, 'category'), ''), 'unknown')"
+ }
+ column "severity" {
+ type = "LowCardinality(String)"
+ default = "coalesce(nullIf(JSONExtractString(details, 'severity'), ''), 'warning')"
+ }
+ column "pipeline_step" {
+ type = "LowCardinality(String)"
+ default = "coalesce(nullIf(JSONExtractString(details, 'pipelineStep'), ''), 'unknown')"
+ }
+ column "event_uuid" {
+ type = "Nullable(UUID)"
+ default = "toUUIDOrNull(JSONExtractString(details, 'eventUuid'))"
+ }
+ column "distinct_id" {
+ type = "Nullable(String)"
+ default = "nullIf(JSONExtractString(details, 'distinctId'), '')"
+ }
+ column "group_key" {
+ type = "Nullable(String)"
+ default = "nullIf(JSONExtractString(details, 'groupKey'), '')"
+ }
+ column "person_id" {
+ type = "Nullable(UUID)"
+ default = "toUUIDOrNull(JSONExtractString(details, 'personId'))"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "ingestion_warnings_v2"
+ }
+ }
+
+ table "k8s_node_inventory" {
+ order_by = ["nodepool", "instance_id"]
+ partition_by = "toYYYYMMDD(collected_at)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "collected_at" {
+ type = "DateTime"
+ }
+ column "node_name" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "region" {
+ type = "String"
+ }
+ column "nodeclaim" {
+ type = "String"
+ }
+ column "nodepool" {
+ type = "String"
+ }
+ column "ec2nodeclass" {
+ type = "String"
+ }
+ column "labels" {
+ type = "JSON"
+ }
+ column "enis" {
+ type = "Array(JSON)"
+ }
+ engine "replacing_merge_tree" {
+ version_column = "collected_at"
+ }
+ }
+
+ table "kafka_error_tracking_issue_fingerprint_overrides_ws" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "fingerprint" {
+ type = "String"
+ }
+ column "issue_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ engine "kafka" {
+ collection = "warpstream_shared"
+ topic_list = "clickhouse_error_tracking_issue_fingerprint"
+ group_name = "clickhouse_error_tracking_issue_fingerprint_overrides_ws"
+ format = "JSONEachRow"
+ }
+ }
+
+ table "llma_metrics_daily" {
+ order_by = ["team_id", "date", "metric_name"]
+ partition_by = "toYYYYMM(date)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "String"
+ }
+ column "metric_value" {
+ type = "Float64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.llma_metrics_daily"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "log_entries" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_log_entries"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "marketing_conversions_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "conversion_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "conversion_math_value" {
+ type = "Float64"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "medium_name" {
+ type = "String"
+ }
+ column "content_name" {
+ type = "String"
+ }
+ column "term_name" {
+ type = "String"
+ }
+ column "referring_domain_name" {
+ type = "String"
+ }
+ column "gclid_name" {
+ type = "String"
+ }
+ column "fbclid_name" {
+ type = "String"
+ }
+ column "gad_source_name" {
+ type = "String"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_marketing_conversions_preaggregated"
+ sharding_key = "cityHash64(person_id)"
+ }
+ }
+
+ table "marketing_costs_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "source_id" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "grain" {
+ type = "LowCardinality(String)"
+ }
+ column "match_key" {
+ type = "String"
+ }
+ column "campaign_id" {
+ type = "String"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "ad_group_id" {
+ type = "String"
+ }
+ column "ad_group_name" {
+ type = "String"
+ }
+ column "ad_id" {
+ type = "String"
+ }
+ column "ad_name" {
+ type = "String"
+ }
+ column "cost_date" {
+ type = "Date"
+ }
+ column "cost" {
+ type = "Float64"
+ }
+ column "clicks" {
+ type = "Float64"
+ }
+ column "impressions" {
+ type = "Float64"
+ }
+ column "reported_conversions" {
+ type = "Float64"
+ }
+ column "reported_conversion_value" {
+ type = "Float64"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_marketing_costs_preaggregated"
+ sharding_key = "cityHash64(source_name, campaign_id)"
+ }
+ }
+
+ table "marketing_touchpoints_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "touchpoint_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "medium_name" {
+ type = "String"
+ }
+ column "content_name" {
+ type = "String"
+ }
+ column "term_name" {
+ type = "String"
+ }
+ column "referring_domain_name" {
+ type = "String"
+ }
+ column "gclid_name" {
+ type = "String"
+ }
+ column "fbclid_name" {
+ type = "String"
+ }
+ column "gad_source_name" {
+ type = "String"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_marketing_touchpoints_preaggregated"
+ sharding_key = "cityHash64(person_id)"
+ }
+ }
+
+ table "materialized_test" {
+ order_by = ["id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UInt32"
+ }
+ column "properties" {
+ type = "String"
+ }
+ engine "merge_tree" {
+ }
+ }
+
+ table "message_assets" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "function_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "function_id" {
+ type = "String"
+ }
+ column "parent_run_id" {
+ type = "String"
+ }
+ column "invocation_id" {
+ type = "String"
+ }
+ column "action_id" {
+ type = "String"
+ }
+ column "kind" {
+ type = "LowCardinality(String)"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "String"
+ }
+ column "recipient" {
+ type = "String"
+ }
+ column "subject" {
+ type = "String"
+ }
+ column "status" {
+ type = "LowCardinality(String)"
+ }
+ column "sent_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ column "html" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "message_assets_data"
+ }
+ }
+
+ table "performance_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_performance_events"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "person" {
+ order_by = ["team_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ default = "0"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "last_seen_at" {
+ type = "Nullable(DateTime64(3))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/am0005_20220705151225_noshard/posthog.person"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_distinct_id" {
+ order_by = ["team_id", "distinct_id", "person_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "distinct_id" {
+ type = "String"
+ comment = "skip_0003_fill_person_distinct_id2"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_sign" {
+ type = "Int8"
+ default = "1"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ alias = "if(_sign = -1, 1, 0)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "person_distinct_id2" {
+ order_by = ["team_id", "distinct_id"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ default = "1"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id2"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_distinct_id_overrides" {
+ order_by = ["team_id", "distinct_id"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_person_distinct_id_overrides" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id_overrides"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_overrides" {
+ order_by = ["team_id", "old_person_id"]
+ partition_by = "toYYYYMM(oldest_event)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int32"
+ }
+ column "old_person_id" {
+ type = "UUID"
+ }
+ column "override_person_id" {
+ type = "UUID"
+ }
+ column "merged_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "oldest_event" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "version" {
+ type = "Int32"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_overrides"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_static_cohort" {
+ order_by = ["team_id", "cohort_id", "person_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_static_cohort"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "pg_embeddings" {
+ order_by = ["team_id", "domain", "id"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "domain" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "id" {
+ type = "String"
+ }
+ column "vector" {
+ type = "Array(Float32)"
+ }
+ column "text" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.pg_embeddings"
+ replica_name = "{replica}-{shard}"
+ version_column = "timestamp"
+ is_deleted_column = "is_deleted"
+ }
+ }
+
+ table "plugin_log_entries" {
+ order_by = ["team_id", "id"]
+ partition_by = "plugin_id"
+ ttl = "toDate(timestamp) + toIntervalWeek(1)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "plugin_id" {
+ type = "Int64"
+ }
+ column "plugin_config_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "UUID"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.plugin_log_entries"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "poc_events" {
+ order_by = ["team_id", "toDate(timestamp)", "cityHash64(distinct_id)", "cityHash64(uuid)"]
+ partition_by = "toYYYYMM(timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ engine "merge_tree" {
+ }
+ }
+
+ table "posthog_document_embeddings" {
+ order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "model_name", "rendering", "cityHash64(document_id)"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ index "kafka_timestamp_minmax_posthog_document_embeddings" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.posthog_document_embeddings"
+ replica_name = "{replica}-{shard}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "preaggregation_results" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "uniq_exact_state" {
+ type = "AggregateFunction(uniqExact, UUID)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_preaggregation_results"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "precalculated_events" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "condition" {
+ type = "String"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_precalculated_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "precalculated_person_properties" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "condition" {
+ type = "String"
+ }
+ column "matches" {
+ type = "Bool"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_precalculated_person_properties"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "property_definitions" {
+ order_by = ["team_id", "type", "coalesce(event, '')", "name", "coalesce(group_type_index, 255)"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt32"
+ }
+ column "project_id" {
+ type = "Nullable(UInt32)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "property_type" {
+ type = "Nullable(String)"
+ }
+ column "event" {
+ type = "Nullable(String)"
+ }
+ column "group_type_index" {
+ type = "Nullable(UInt8)"
+ }
+ column "type" {
+ type = "UInt8"
+ default = "1"
+ }
+ column "last_seen_at" {
+ type = "DateTime"
+ }
+ column "version" {
+ type = "UInt64"
+ materialized = "bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.property_definitions"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "property_values_distributed" {
+ column "team_id" {
+ type = "Int64"
+ codec = "DoubleDelta, ZSTD(1)"
+ }
+ column "property_type" {
+ type = "LowCardinality(String)"
+ }
+ column "property_key" {
+ type = "LowCardinality(String)"
+ }
+ column "property_value" {
+ type = "String"
+ }
+ column "property_count" {
+ type = "SimpleAggregateFunction(sum, UInt64)"
+ }
+ column "last_seen" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ default = "now()"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "property_values"
+ }
+ }
+
+ table "query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['RealTimeMicroseconds']"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['OSCPUVirtualTimeMicroseconds']"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ alias = "ProfileEvents['S3Clients']"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3DeleteObjects']"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CopyObject']"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3ListObjects']"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3HeadObject']"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObjectAttributes']"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CreateMultipartUpload']"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPartCopy']"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPart']"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3AbortMultipartUpload']"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CompleteMultipartUpload']"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3PutObject']"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObject']"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['ReadBufferFromS3Bytes']"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['WriteBufferFromS3Bytes']"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workflow"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.kind"
+ }
+ column "lc_id" {
+ type = "String"
+ alias = "CAST(log_comment.id, 'String')"
+ }
+ column "lc_route_id" {
+ type = "String"
+ alias = "CAST(log_comment.route_id, 'String')"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.access_method"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_label, 'String')"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_mask, 'String')"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.query_type"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.product"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ alias = "log_comment.chargeable"
+ }
+ column "lc_name" {
+ type = "String"
+ alias = "CAST(log_comment.name, 'String')"
+ }
+ column "lc_request_name" {
+ type = "String"
+ alias = "CAST(log_comment.request_name, 'String')"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ alias = "CAST(log_comment.client_query_id, 'String')"
+ }
+ column "lc_org_id" {
+ type = "String"
+ alias = "CAST(log_comment.org_id, 'String')"
+ }
+ column "lc_user_id" {
+ type = "Int64"
+ alias = "log_comment.user_id"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ alias = "log_comment.is_impersonated"
+ }
+ column "lc_session_id" {
+ type = "String"
+ alias = "CAST(log_comment.session_id, 'String')"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ alias = "log_comment.dashboard_id"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ alias = "log_comment.insight_id"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ alias = "log_comment.cohort_id"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ alias = "CAST(log_comment.batch_export_id, 'String')"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ alias = "log_comment.experiment_id"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ alias = "CAST(log_comment.experiment_feature_flag_key, 'String')"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ alias = "CAST(log_comment.alert_config_id, 'String')"
+ }
+ column "lc_feature" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.feature"
+ }
+ column "lc_table_id" {
+ type = "String"
+ alias = "CAST(log_comment.table_id, 'String')"
+ }
+ column "lc_warehouse_query" {
+ type = "Bool"
+ alias = "log_comment.warehouse_query"
+ }
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.person_on_events_mode"
+ }
+ column "lc_service_name" {
+ type = "String"
+ alias = "CAST(log_comment.service_name, 'String')"
+ }
+ column "lc_workload" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workload"
+ }
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
+ alias = "if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind'))"
+ }
+ column "lc_query__query" {
+ type = "String"
+ alias = "multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query'))"
+ }
+ column "lc_query" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), '')"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_namespace`, 'String')"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_type`, 'String')"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_id`, 'String')"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_run_id`, 'String')"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_type`, 'String')"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_id`, 'String')"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ alias = "log_comment.`temporal.attempt`"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.job_name`, 'String')"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.run_id`, 'String')"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.tags.owner`, 'String')"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_query_log_archive"
+ }
+ }
+
+ table "raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "raw_sessions_v3" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "rds_inventory" {
+ order_by = ["region", "instance_name"]
+ partition_by = "toYYYYMMDD(collected_at)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "collected_at" {
+ type = "DateTime"
+ }
+ column "region" {
+ type = "String"
+ }
+ column "instance_name" {
+ type = "String"
+ }
+ column "cluster_name" {
+ type = "String"
+ }
+ column "endpoint" {
+ type = "String"
+ }
+ column "ip_address" {
+ type = "String"
+ }
+ engine "replacing_merge_tree" {
+ version_column = "collected_at"
+ }
+ }
+
+ table "session_recording_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "has_full_snapshot" {
+ type = "Int8"
+ comment = "column_materializer::has_full_snapshot"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "events_summary" {
+ type = "Array(String)"
+ comment = "column_materializer::events_summary"
+ }
+ column "click_count" {
+ type = "Int8"
+ comment = "column_materializer::click_count"
+ }
+ column "keypress_count" {
+ type = "Int8"
+ comment = "column_materializer::keypress_count"
+ }
+ column "timestamps_summary" {
+ type = "Array(DateTime64(6, 'UTC'))"
+ comment = "column_materializer::timestamps_summary"
+ }
+ column "first_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::first_event_timestamp"
+ }
+ column "last_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::last_event_timestamp"
+ }
+ column "urls" {
+ type = "Array(String)"
+ comment = "column_materializer::urls"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_recording_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "session_replay_embeddings" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_embeddings"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "session_replay_events" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "session_replay_features" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_position_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_sum_x" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_sum_x_squared" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_sum_y" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_sum_y_squared" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_distance_traveled" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_direction_change_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_velocity_sum" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_velocity_sum_of_squares" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_velocity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "scroll_event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "total_scroll_magnitude" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "scroll_direction_reversal_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "rapid_scroll_reversal_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "scroll_to_top_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "rage_click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "dead_click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "backspace_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "inter_action_gap_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "inter_action_gap_sum_ms" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "inter_action_gap_sum_of_squares_ms" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "max_idle_gap_ms" {
+ type = "SimpleAggregateFunction(max, Float64)"
+ }
+ column "long_idle_gap_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "quick_back_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "page_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "unique_url_count" {
+ type = "AggregateFunction(uniqCombined(12), String)"
+ }
+ column "login_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "signup_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "checkout_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "cart_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "billing_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "settings_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "account_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "error_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "not_found_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "admin_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "dashboard_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "onboarding_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "cancel_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "refund_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_after_click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_request_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_failed_request_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_4xx_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_5xx_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_request_duration_sum" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "network_request_duration_sum_of_squares" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "network_request_duration_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mutation_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "viewport_resize_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "touch_event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "max_scroll_y" {
+ type = "SimpleAggregateFunction(max, Float64)"
+ }
+ column "unique_click_target_count" {
+ type = "AggregateFunction(uniqCombined(12), Int64)"
+ }
+ column "unique_form_field_count" {
+ type = "AggregateFunction(uniqCombined(12), Int64)"
+ }
+ column "text_selection_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "selection_copy_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_features"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "sharded_app_metrics" {
+ order_by = ["team_id", "plugin_config_id", "job_id", "category", "toStartOfHour(timestamp)", "error_type", "error_uuid"]
+ partition_by = "toYYYYMM(timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "plugin_config_id" {
+ type = "Int64"
+ }
+ column "category" {
+ type = "LowCardinality(String)"
+ }
+ column "job_id" {
+ type = "String"
+ }
+ column "successes" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "successes_on_retry" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "failures" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "error_uuid" {
+ type = "UUID"
+ }
+ column "error_type" {
+ type = "String"
+ }
+ column "error_details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_app_metrics"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_app_metrics2" {
+ order_by = ["team_id", "app_source", "app_source_id", "instance_id", "toStartOfHour(timestamp)", "metric_kind", "metric_name"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "app_source" {
+ type = "LowCardinality(String)"
+ }
+ column "app_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "metric_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ 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_billing_usage_records" {
+ order_by = ["team_id", "toDate(timestamp)", "producer_id", "usage_key", "record_id"]
+ partition_by = "toYYYYMM(timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "schema_version" {
+ type = "UInt8"
+ }
+ column "record_id" {
+ type = "String"
+ }
+ column "producer_id" {
+ type = "LowCardinality(String)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "organization_id" {
+ type = "UUID"
+ }
+ column "usage_key" {
+ type = "LowCardinality(String)"
+ }
+ column "unit" {
+ type = "LowCardinality(String)"
+ }
+ column "quantity" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_billing_usage_records"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ 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"
+ replicated_fetches_min_part_level = "1"
+ replicated_fetches_min_part_level_timeout_seconds = "300"
+ }
+ 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_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 "$group_0" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_0"
+ }
+ column "$group_1" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_1"
+ }
+ column "$group_2" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_2"
+ }
+ column "$group_3" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_3"
+ }
+ column "$group_4" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_4"
+ }
+ column "$window_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$window_id"
+ }
+ column "$session_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$session_id"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "person_created_at" {
+ type = "DateTime64(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 "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"
+ materialized = "EXTRACT(elements_chain, '(?::|\")href=\"(.*?)\"')"
+ }
+ column "elements_chain_texts" {
+ type = "Array(String)"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")text=\"(.*?)\"'))"
+ }
+ column "elements_chain_ids" {
+ type = "Array(String)"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
+ }
+ 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'))), 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 "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_trace_id" {
+ type = "Nullable(String)"
+ materialized = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
+ }
+ column "mat_historical_migration" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, 'historical_migration', '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 "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)"
+ 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)')"
+ }
+ 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 "sharded_events_codec_test" {
+ order_by = ["team_id", "toDate(timestamp)", "event", "cityHash64(distinct_id)", "cityHash64(uuid)"]
+ partition_by = "toYYYYMM(timestamp)"
+ sample_by = "cityHash64(distinct_id)"
+ settings = {
+ default_compression_codec = "ZSTD(3)"
+ 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_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 "$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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "person_created_at" {
+ type = "DateTime64(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 "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"
+ 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 "elements_chain_ids" {
+ type = "Array(String)"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
+ }
+ 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'))), 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 "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_map_ephemeral" {
+ type = "Map(String, String)"
+ }
+ column "person_properties_map_ephemeral" {
+ type = "Map(String, 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_trace_id" {
+ type = "Nullable(String)"
+ materialized = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
+ }
+ column "mat_historical_migration" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, 'historical_migration', '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 "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)"
+ 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_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 "replacing_merge_tree" {
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_experiment_exposures_preaggregated" {
+ order_by = ["team_id", "job_id", "entity_id", "breakdown_value"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "expires_at"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "entity_id" {
+ type = "String"
+ }
+ column "variant" {
+ type = "String"
+ }
+ column "first_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "last_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "exposure_event_uuid" {
+ type = "UUID"
+ }
+ column "exposure_session_id" {
+ type = "String"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.experiment_exposures_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_flag_evaluations" {
+ order_by = ["team_id", "flag_key", "toDate(timestamp)", "cityHash64(distinct_id)"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "LowCardinality(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 "person_id" {
+ type = "UUID"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "timestamp"
+ }
+ column "$group_0" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_0"
+ }
+ column "$group_1" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_1"
+ }
+ column "$group_2" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_2"
+ }
+ column "$group_3" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_3"
+ }
+ column "$group_4" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_4"
+ }
+ column "flag_key" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag"
+ }
+ column "response" {
+ type = "LowCardinality(String)"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag_response"
+ }
+ column "session_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$session_id"
+ }
+ column "request_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_request_id'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag_request_id"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "distinct_id_idx" {
+ expr = "distinct_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "person_id_idx" {
+ expr = "person_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "session_id_idx" {
+ expr = "session_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "request_id_idx" {
+ expr = "request_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "inserted_at_idx" {
+ expr = "inserted_at"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.flag_evaluations"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_heatmaps" {
+ order_by = ["type", "team_id", "toDate(timestamp)", "current_url", "viewport_width"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "x" {
+ type = "Int16"
+ }
+ column "y" {
+ type = "Int16"
+ }
+ column "scale_factor" {
+ type = "Int16"
+ }
+ column "viewport_width" {
+ type = "Int16"
+ }
+ column "viewport_height" {
+ type = "Int16"
+ }
+ column "pointer_target_fixed" {
+ type = "Bool"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.heatmaps"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_log_entries" {
+ order_by = ["team_id", "log_source", "log_source_id", "instance_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_log_entries"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_performance_events" {
+ order_by = ["team_id", "toDate(timestamp)", "session_id", "pageview_id", "timestamp"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalWeek(3)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.performance_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_buffer" {
+ order_by = ["inserted_at", "model_name", "cityHash64(document_id)"]
+ partition_by = "toDate(inserted_at)"
+ ttl = "inserted_at + toIntervalDay(1)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_buffer"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_text_embedding_3_large_3072" {
+ order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "rendering", "cityHash64(document_id)"]
+ partition_by = "toMonday(timestamp)"
+ ttl = "timestamp + toIntervalMonth(3)"
+ settings = {
+ index_granularity = "512"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_large_3072" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ index "embedding_idx_l2" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'L2Distance', 3072)"
+ granularity = 100000000
+ }
+ index "embedding_idx_cosine" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'cosineDistance', 3072)"
+ granularity = 100000000
+ }
+ constraint "embedding_dimension_check" {
+ check = "length(embedding) = 3072"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_text_embedding_3_small_1536" {
+ order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "rendering", "cityHash64(document_id)"]
+ partition_by = "toMonday(timestamp)"
+ ttl = "timestamp + toIntervalMonth(3)"
+ settings = {
+ index_granularity = "512"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_small_1536" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ index "embedding_idx_l2" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'L2Distance', 1536)"
+ granularity = 100000000
+ }
+ index "embedding_idx_cosine" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'cosineDistance', 1536)"
+ granularity = 100000000
+ }
+ constraint "embedding_dimension_check" {
+ check = "length(embedding) = 1536"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_preaggregation_results" {
+ order_by = ["team_id", "job_id", "time_window_start", "breakdown_value"]
+ partition_by = "toYYYYMM(time_window_start)"
+ ttl = "expires_at"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "uniq_exact_state" {
+ type = "AggregateFunction(uniqExact, UUID)"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.preaggregation_results"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_precalculated_events" {
+ order_by = ["team_id", "condition", "date", "distinct_id", "uuid"]
+ partition_by = "toYYYYMM(date)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "condition" {
+ type = "String"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_precalculated_events"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_precalculated_person_properties" {
+ order_by = ["team_id", "condition", "distinct_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "condition" {
+ type = "String"
+ }
+ column "matches" {
+ type = "Bool"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_precalculated_person_properties"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_raw_sessions" {
+ order_by = ["team_id", "toStartOfHour(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)))", "cityHash64(session_id_v7)", "session_id_v7"]
+ partition_by = "toYYYYMM(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)))"
+ sample_by = "cityHash64(session_id_v7)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_raw_sessions_v3" {
+ order_by = ["team_id", "session_timestamp", "session_id_v7"]
+ partition_by = "toYYYYMM(session_timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ index "event_names_bloom_filter" {
+ expr = "event_names"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ index "flag_keys_bloom_filter" {
+ expr = "flag_keys"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions_v3"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_session_recording_events" {
+ order_by = ["team_id", "toHour(timestamp)", "session_id", "timestamp", "uuid"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(created_at) + toIntervalWeek(3)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "has_full_snapshot" {
+ type = "Int8"
+ materialized = "JSONExtractBool(snapshot_data, 'has_full_snapshot')"
+ comment = "column_materializer::has_full_snapshot"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "events_summary" {
+ type = "Array(String)"
+ materialized = "JSONExtract(JSON_QUERY(snapshot_data, '$.events_summary[*]'), 'Array(String)')"
+ }
+ column "click_count" {
+ type = "Int8"
+ materialized = "length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 2) AND (JSONExtractInt(x, 'data', 'source') = 2)), events_summary))"
+ }
+ column "keypress_count" {
+ type = "Int8"
+ materialized = "length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 5)), events_summary))"
+ }
+ column "timestamps_summary" {
+ type = "Array(DateTime64(6, 'UTC'))"
+ materialized = "arraySort(arrayMap(x -> toDateTime(JSONExtractInt(x, 'timestamp') / 1000), events_summary))"
+ }
+ column "first_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ materialized = "arrayReduce('min', timestamps_summary)"
+ }
+ column "last_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ materialized = "arrayReduce('max', timestamps_summary)"
+ }
+ column "urls" {
+ type = "Array(String)"
+ materialized = "arrayFilter(x -> (x != ''), arrayMap(x -> JSONExtractString(x, 'data', 'href'), events_summary))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_recording_events"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_session_replay_embeddings" {
+ order_by = ["toDate(generation_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(generation_timestamp)"
+ ttl = "toDate(generation_timestamp) + toIntervalYear(1)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_embeddings"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_session_replay_events" {
+ order_by = ["toDate(min_first_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(min_first_timestamp)"
+ settings = {
+ index_granularity = "512"
+ ttl_only_drop_parts = "1"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_sessions" {
+ order_by = ["toStartOfDay(min_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(min_timestamp)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sessions"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "tophog" {
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "metric" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ default = "'sum'"
+ }
+ column "key" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "0"
+ }
+ column "pipeline" {
+ type = "LowCardinality(String)"
+ }
+ column "lane" {
+ type = "LowCardinality(String)"
+ }
+ column "labels" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_tophog"
+ sharding_key = "cityHash64(toString(key))"
+ }
+ }
+
+ table "usage_report_events_preagg" {
+ column "date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_mode" {
+ type = "LowCardinality(String)"
+ }
+ column "lib" {
+ type = "LowCardinality(String)"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "distinct_events_unique" {
+ type = "AggregateFunction(uniqExact, Tuple(UInt64, UInt64, UInt64))"
+ }
+ column "event_count" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_usage_report_events_preagg"
+ sharding_key = "sipHash64(date)"
+ }
+ }
+
+ table "web_bot_definition" {
+ column "id" {
+ type = "UInt64"
+ }
+ column "parent_id" {
+ type = "UInt64"
+ }
+ column "regexp" {
+ type = "String"
+ }
+ column "keys" {
+ type = "Array(String)"
+ }
+ column "values" {
+ type = "Array(String)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_bot_definition"
+ sharding_key = "sipHash64(id)"
+ }
+ }
+
+ table "web_bounces_dimensional_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_bounces_dimensional_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_goals_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "action_id" {
+ type = "Int64"
+ }
+ column "count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "unique_persons_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_goals_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_overview_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "uniq_sessions_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_duration_state" {
+ type = "AggregateFunction(avg, Float64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_overview_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_pre_aggregated_bounces" {
+ order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "web_pre_aggregated_stats" {
+ order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "web_pre_aggregated_teams" {
+ order_by = ["team_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "enabled_by" {
+ type = "String"
+ default = "'system'"
+ }
+ column "version" {
+ type = "UInt32"
+ default = "toUnixTimestamp(now())"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_analytics_team_selection"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "web_stats_dimensional_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_dimensional_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_stats_frustration_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "sum_rage_clicks_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "sum_dead_clicks_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "sum_errors_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_frustration_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_stats_paths_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Nullable(Float64))"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_paths_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_stats_paths_preaggregated_pathkey" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Nullable(Float64))"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_paths_preaggregated_pathkey"
+ sharding_key = "sipHash64(breakdown_value)"
+ }
+ }
+
+ table "web_stats_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_by" {
+ type = "String"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_vitals_paths_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "path" {
+ type = "String"
+ }
+ column "inp_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "lcp_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "cls_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "fcp_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_vitals_paths_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "writable_events" {
+ 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 "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "person_created_at" {
+ type = "DateTime64(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 "consumer_breadcrumbs" {
+ type = "Array(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)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_events_dead_letter_queue" {
+ column "id" {
+ type = "UUID"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "ip" {
+ type = "String"
+ }
+ column "site_url" {
+ type = "String"
+ }
+ column "now" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "raw_payload" {
+ type = "String"
+ }
+ column "error_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "error_location" {
+ type = "String"
+ }
+ column "error" {
+ type = "String"
+ }
+ column "tags" {
+ type = "Array(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog_single_shard"
+ remote_database = "posthog"
+ remote_table = "events_dead_letter_queue"
+ }
+ }
+
+ table "writable_events_recent" {
+ 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 "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"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports_writable"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_log_entries" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_log_entries"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_buffer" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_buffer"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_text_embedding_3_large_3072" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_text_embedding_3_small_1536" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "query_log_archive_buffer"
+ }
+ }
+
+ table "writable_raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_raw_sessions_v3" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_session_recording_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_recording_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_session_replay_embeddings" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_embeddings"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "writable_session_replay_events" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "writeable_performance_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_performance_events"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ materialized_view "ops_query_log_archive_mv" {
+ to_table = "posthog.writable_query_log_archive"
+ query = <<SQL
+SELECT
+ hostname,
+ user,
+ query_id,
+ initial_query_id,
+ is_initial_query,
+ type,
+ event_date,
+ event_time,
+ event_time_microseconds,
+ query_start_time,
+ query_start_time_microseconds,
+ query_duration_ms,
+ read_rows,
+ read_bytes,
+ written_rows,
+ written_bytes,
+ result_rows,
+ result_bytes,
+ memory_usage,
+ peak_threads_usage,
+ current_database,
+ query,
+ formatted_query,
+ normalized_query_hash,
+ query_kind,
+ exception_code,
+ exception,
+ stack_trace,
+ JSONExtractInt(log_comment, 'team_id') AS team_id,
+ if(isValidJSON(log_comment), log_comment, '{}') AS log_comment,
+ ProfileEvents
+FROM system.query_log
+WHERE type != 'QueryStart'
+SQL
+
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "String"
+ }
+ column "ProfileEvents" {
+ type = "Map(LowCardinality(String), UInt64)"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-large-3072'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-small-1536'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ view "custom_metrics" {
+ query = <<SQL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_test
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_replication_queue
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_server_crash
+UNION ALL
+SELECT *
+FROM posthog.custom_metrics_table_sizes
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_part_counts
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_dictionaries
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_S3DiskBytesUsed' AS name,
+ map('instance', hostname(), 'disk', disk_name) AS labels,
+ toFloat64(sum(bytes_on_disk)) AS value,
+ 'Bytes currently used by ClickHouse parts on S3-backed disks on this node' AS help,
+ 'gauge' AS type
+FROM system.parts
+WHERE disk_name IN ('s3disk', 'cache')
+GROUP BY
+ disk_name
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeFailures15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(count()) AS value,
+ 'Number of failed merge operations in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM system.part_log
+WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+AND
+ (event_type = 'MergeParts')
+AND
+ (error > 0)
+AND
+ (merge_reason != 'NotAMerge')
+AND
+ (error != 40)
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeRetriesMaxPerTable15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(max(cnt)) AS value,
+ 'Max failed merge retries for any single table in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT count() AS cnt
+ FROM system.part_log
+ WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+ AND
+ (event_type = 'MergeParts')
+ AND
+ (error > 0)
+ AND
+ (merge_reason != 'NotAMerge')
+ AND
+ (error != 40)
+ GROUP BY
+ database, `table`, partition_id
+ )
+SQL
+
+ }
+
+ view "custom_metrics_backups" {
+ query = <<SQL
+WITH
+ ['ClickHouseCustomMetric_BackupFailed', 'ClickHouseCustomMetric_BackupSuccess', 'ClickHouseCustomMetric_BackupCancelled', 'ClickHouseCustomMetric_BackupAttempts'] AS names,
+ [toInt64(countIf(status = 'BACKUP_FAILED')), toInt64(countIf(status = 'BACKUP_CREATED')), toInt64(countIf(status = 'BACKUP_CANCELLED')), toInt64(countIf(status = 'CREATING_BACKUP'))] AS `values`,
+ ['Number of failed backups', 'Number of successful backups', 'Number of cancelled backups', 'Number of backup attempts'] AS descriptions,
+ ['gauge', 'gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.backup_log
+WHERE event_date = today()
+GROUP BY
+ event_date
+SQL
+
+ }
+
+ view "custom_metrics_dictionaries" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_DictionariesFailed' AS name,
+ map(
+ 'instance',
+ hostname(),
+ 'database',
+ d.database,
+ 'dictionary',
+ d.dict_name,
+ 'uuid',
+ toString(d.uuid),
+ 'status',
+ toString(d.status)
+ ) AS labels,
+ toUInt64(1) AS value,
+ 'Dictionary is in FAILED or FAILED_AND_RELOADING status' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT name AS dict_name, database, uuid, status
+ FROM system.dictionaries
+ WHERE status IN ('FAILED', 'FAILED_AND_RELOADING')
+ ) AS d
+SQL
+
+ }
+
+ view "custom_metrics_part_counts" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_MaxPartCountPerPartition' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`, 'partition', partition) AS labels,
+ part_count AS value,
+ 'Maximum number of active parts for any partition in a PostHog table' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT database, `table`, partition, count() AS part_count
+ FROM system.parts
+ WHERE
+ active
+ AND
+ (database = 'posthog')
+ GROUP BY
+ database, `table`, partition
+ ORDER BY database ASC, `table` ASC, part_count DESC, partition ASC
+ LIMIT 1 BY database, `table`
+ )
+SQL
+
+ }
+
+ view "custom_metrics_replication_queue" {
+ query = <<SQL
+WITH
+ ['ClickHouseCustomMetric_ReplicationQueueStuckEntries', 'ClickHouseCustomMetric_ReplicationQueueMaxPostponedEntrySeconds', 'ClickHouseCustomMetric_ReplicationQueueMaxErrorEntrySeconds'] AS names,
+ [toInt64(countIf(create_time < (now() - toIntervalDay(15)))), maxIf(dateDiff('seconds', create_time, last_postpone_time), last_postpone_time != '1970-01-01'), maxIf(dateDiff('seconds', create_time, last_exception_time), (last_exception_time != '1970-01-01') AND (last_exception_time > (now() - toIntervalMinute(5))))] AS `values`,
+ ['Number of entries that have been in the replication queue for more than 15 days', 'Maximum number of seconds that an entry has been postponed', 'Maximum number of seconds that an entry has been in error'] AS descriptions,
+ ['gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('table', `table`, 'instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.replication_queue
+GROUP BY
+ `table`
+HAVING
+ value > 0
+SQL
+
+ }
+
+ view "custom_metrics_server_crash" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_ServerCrash' AS name,
+ map('instance', hostname()) AS labels,
+ count() AS value,
+ 'Number of server crashes for current date' AS help,
+ 'gauge' AS type
+FROM system.crash_log
+WHERE event_date = today()
+GROUP BY
+ hostname()
+SQL
+
+ }
+
+ view "custom_metrics_table_sizes" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_TableTotalBytes' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`) AS labels,
+ CAST(total_bytes, 'Float64') AS value,
+ 'Size of a database table on a given node (need a sum for sharded)' AS help,
+ 'gauge' AS type
+FROM system.tables
+WHERE
+ (database NOT IN ('INFORMATION_SCHEMA', 'information_schema'))
+AND
+ (total_bytes IS NOT NULL)
+SQL
+
+ }
+
+ view "custom_metrics_test" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_Test' AS name,
+ map('instance', hostname()) AS labels,
+ 1 AS value,
+ 'Test to check that the metric endpoint is working' AS help,
+ 'gauge' AS type
+SQL
+
+ }
+
+ view "events_batch_export" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (events.inserted_at >= {interval_start: DateTime64}) AND (events.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ (events.timestamp >= ({interval_start: DateTime64} - toIntervalDay({lookback_days: Int32})))
+AND
+ (events.timestamp < ({interval_end: DateTime64} + toIntervalDay(1)))
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "events_batch_export_recent" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ inserted_at AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events_recent
+PREWHERE
+ (events_recent.inserted_at >= {interval_start: DateTime64}) AND (events_recent.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events_recent.distinct_id), cityHash64(events_recent.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "events_batch_export_unbounded" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (events.inserted_at >= {interval_start: DateTime64}) AND (events.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "persons_batch_export" {
+ query = <<SQL
+WITH
+ new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
+ new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
+ all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
+SELECT
+ p.team_id AS team_id,
+ pd.distinct_id AS distinct_id,
+ toString(p.id) AS person_id,
+ p.properties AS properties,
+ pd.version AS person_distinct_id_version,
+ p.version AS person_version,
+ p.created_at AS created_at,
+ multiIf(
+ ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
+ pd._timestamp,
+ ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
+ p._timestamp,
+ least(p._timestamp, pd._timestamp)
+ ) AS _inserted_at
+FROM
+ posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((id, version) IN (all_new_persons))
+ORDER BY _inserted_at ASC
+SQL
+
+ }
+
+ view "posthog_document_embeddings_union_view" {
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-small-1536' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_small_1536
+UNION ALL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-large-3072' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_large_3072
+SQL
+
+ }
+
+ view "raw_sessions_v" {
+ query = <<SQL
+SELECT
+ session_id_v7,
+ fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)) AS session_timestamp,
+ team_id,
+ argMaxMerge(distinct_id) AS distinct_id,
+ 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(initial_browser) AS initial_browser,
+ argMinMerge(initial_browser_version) AS initial_browser_version,
+ argMinMerge(initial_os) AS initial_os,
+ argMinMerge(initial_os_version) AS initial_os_version,
+ argMinMerge(initial_device_type) AS initial_device_type,
+ argMinMerge(initial_viewport_width) AS initial_viewport_width,
+ argMinMerge(initial_viewport_height) AS initial_viewport_height,
+ argMinMerge(initial_geoip_country_code) AS initial_geoip_country_code,
+ argMinMerge(initial_geoip_subdivision_1_code) AS initial_geoip_subdivision_1_code,
+ argMinMerge(initial_geoip_subdivision_1_name) AS initial_geoip_subdivision_1_name,
+ argMinMerge(initial_geoip_subdivision_city_name) AS initial_geoip_subdivision_city_name,
+ argMinMerge(initial_geoip_time_zone) AS initial_geoip_time_zone,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ argMinMerge(initial__kx) AS initial__kx,
+ argMinMerge(initial_irclid) AS initial_irclid,
+ sum(pageview_count) AS pageview_count,
+ uniqMerge(pageview_uniq) AS pageview_uniq,
+ sum(autocapture_count) AS autocapture_count,
+ uniqMerge(autocapture_uniq) AS autocapture_uniq,
+ sum(screen_count) AS screen_count,
+ uniqMerge(screen_uniq) AS screen_uniq,
+ max(maybe_has_session_replay) AS maybe_has_session_replay,
+ uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,
+ argMinMerge(vitals_lcp) AS vitals_lcp
+FROM posthog.raw_sessions
+GROUP BY
+ session_id_v7, team_id
+SQL
+
+ }
+
+ view "raw_sessions_v3_v" {
+ 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" {
+ query = <<SQL
+SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(exit_url) AS exit_url,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ sumMap(event_count_map) AS event_count_map,
+ sum(pageview_count) AS pageview_count,
+ sum(autocapture_count) AS autocapture_count
+FROM posthog.sessions
+GROUP BY
+ session_id, team_id
+SQL
+
+ }
+
+ dictionary "channel_definition_dict" {
+ primary_key = ["domain", "kind"]
+ lifetime {
+ min = 3000
+ max = 3600
+ }
+ attribute "domain" {
+ type = "String"
+ }
+ attribute "kind" {
+ type = "String"
+ }
+ attribute "domain_type" {
+ type = "Nullable(String)"
+ }
+ attribute "type_if_paid" {
+ type = "Nullable(String)"
+ }
+ attribute "type_if_organic" {
+ type = "Nullable(String)"
+ }
+ source "clickhouse" {
+ user = "dict_reader"
+ table = "channel_definition"
+ }
+ layout "complex_key_hashed" {
+ }
+ }
+
+ dictionary "web_bot_definition_dict" {
+ primary_key = ["regexp"]
+ lifetime {
+ min = 3000
+ max = 3600
+ }
+ attribute "regexp" {
+ type = "String"
+ }
+ attribute "name" {
+ type = "String"
+ }
+ attribute "category" {
+ type = "String"
+ }
+ attribute "traffic_type" {
+ type = "String"
+ }
+ attribute "operator" {
+ type = "String"
+ }
+ source "clickhouse" {
+ user = "default"
+ db = "posthog"
+ table = "web_bot_definition"
+ }
+ layout "regexp_tree" {
+ }
+ }
+
+ dictionary "web_pre_aggregated_teams_dict" {
+ primary_key = ["team_id"]
+ lifetime {
+ min = 3000
+ max = 3600
+ }
+ attribute "team_id" {
+ type = "UInt64"
+ }
+ source "clickhouse" {
+ user = "dict_reader"
+ query = "SELECT team_id FROM `web_pre_aggregated_teams` FINAL WHERE version > 0"
+ }
+ layout "hashed" {
+ }
+ }
+}
+
+named_collection "msk_cluster" {
+ external = true
+}
+
+named_collection "warpstream_calculated_events" {
+ external = true
+}
+
+named_collection "warpstream_cyclotron" {
+ external = true
+}
+
+named_collection "warpstream_ingestion" {
+ external = true
+}
+
+named_collection "warpstream_logs" {
+ external = true
+}
+
+named_collection "warpstream_metrics" {
+ external = true
+}
+
+named_collection "warpstream_replay" {
+ external = true
+}
+
+named_collection "warpstream_shared" {
+ external = true
+}
+
+named_collection "warpstream_traces" {
+ external = true
+}
diff --git a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl
new file mode 100644
index 000000000000..cca729f909e7
--- /dev/null
+++ b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl
@@ -0,0 +1,10093 @@
+database "posthog" {
+ table "adhoc_events_deletion" {
+ order_by = ["team_id", "uuid"]
+ ttl = "deleted_at + toIntervalMonth(3) WHERE is_deleted = 1"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ column "deleted_at" {
+ type = "DateTime"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ default = "0"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.adhoc_events_deletion"
+ replica_name = "{replica}-{shard}"
+ version_column = "deleted_at"
+ is_deleted_column = "is_deleted"
+ }
+ }
+
+ table "ai_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "LowCardinality(String)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "retention_days" {
+ type = "Int16"
+ default = "30"
+ }
+ column "drop_date" {
+ type = "Date"
+ materialized = "toDate(timestamp) + toIntervalDay(retention_days)"
+ }
+ column "trace_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "Nullable(String)"
+ }
+ column "parent_id" {
+ type = "Nullable(String)"
+ }
+ column "span_id" {
+ type = "Nullable(String)"
+ }
+ column "span_type" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "generation_id" {
+ type = "Nullable(String)"
+ }
+ column "experiment_id" {
+ type = "Nullable(String)"
+ }
+ column "span_name" {
+ type = "Nullable(String)"
+ }
+ column "trace_name" {
+ type = "Nullable(String)"
+ }
+ column "prompt_name" {
+ type = "Nullable(String)"
+ }
+ column "model" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "provider" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "framework" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "total_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "text_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "text_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "image_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "image_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "audio_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "audio_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "video_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "video_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "reasoning_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "cache_read_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "cache_creation_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "web_search_count" {
+ type = "Nullable(Int64)"
+ }
+ column "input_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "output_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "total_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "request_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "web_search_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "audio_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "image_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "video_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "latency" {
+ type = "Nullable(Float64)"
+ }
+ column "time_to_first_token" {
+ type = "Nullable(Float64)"
+ }
+ column "is_error" {
+ type = "UInt8"
+ }
+ column "error" {
+ type = "Nullable(String)"
+ }
+ column "error_type" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "error_normalized" {
+ type = "Nullable(String)"
+ }
+ column "input" {
+ type = "Nullable(String)"
+ }
+ column "output" {
+ type = "Nullable(String)"
+ }
+ column "output_choices" {
+ type = "Nullable(String)"
+ }
+ column "input_state" {
+ type = "Nullable(String)"
+ }
+ column "output_state" {
+ type = "Nullable(String)"
+ }
+ column "tools" {
+ type = "Nullable(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "ai_events"
+ remote_database = "posthog"
+ remote_table = "ai_events"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "app_metrics2" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "app_source" {
+ type = "LowCardinality(String)"
+ }
+ column "app_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "metric_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_app_metrics2"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "async_deletion_run" {
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "deletion_type", "key"]
+ }
+ }
+
+ table "asyncdeletion" {
+ order_by = ["deletion_type", "delete_verified_at"]
+ partition_by = "toYYYYMM(created_at)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "delete_verified_at" {
+ type = "DateTime"
+ }
+ column "created_by_id" {
+ type = "UInt64"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/asyncdeletion"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "billing_usage_records" {
+ column "schema_version" {
+ type = "UInt8"
+ }
+ column "record_id" {
+ type = "String"
+ }
+ column "producer_id" {
+ type = "LowCardinality(String)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "organization_id" {
+ type = "UUID"
+ }
+ column "usage_key" {
+ type = "LowCardinality(String)"
+ }
+ column "unit" {
+ type = "LowCardinality(String)"
+ }
+ column "quantity" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_billing_usage_records"
+ sharding_key = "cityHash64(team_id)"
+ }
+ }
+
+ table "channel_definition" {
+ order_by = ["domain", "kind"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "domain" {
+ type = "String"
+ }
+ column "kind" {
+ type = "String"
+ }
+ column "domain_type" {
+ type = "Nullable(String)"
+ }
+ column "type_if_paid" {
+ type = "Nullable(String)"
+ }
+ column "type_if_organic" {
+ type = "Nullable(String)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.channel_definition"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "clickhouse_cleanup_deleted_persons" {
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "max_version" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_orphaned_distinct_ids" {
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "own_tombstone" {
+ type = "UInt8"
+ }
+ column "max_version" {
+ type = "Int64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_distinct_ids" {
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_persons" {
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "cohort_membership" {
+ order_by = ["team_id", "cohort_id", "person_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "status" {
+ type = "Enum8('entered'=1, 'left'=2)"
+ }
+ column "last_updated" {
+ type = "DateTime64(6)"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.cohort_membership"
+ replica_name = "{replica}-{shard}"
+ version_column = "last_updated"
+ }
+ }
+
+ table "cohortpeople" {
+ order_by = ["team_id", "cohort_id", "person_id"]
+ partition_by = "team_id % 16"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "sign" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.cohortpeople_new_partitioned"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "conversion_goal_attributed_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "conversion_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "conversion_value" {
+ type = "Float64"
+ }
+ column "touchpoint_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "touchpoint_weight" {
+ type = "Float64"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "medium_name" {
+ type = "String"
+ }
+ column "content_name" {
+ type = "String"
+ }
+ column "term_name" {
+ type = "String"
+ }
+ column "referring_domain_name" {
+ type = "String"
+ }
+ column "gclid_name" {
+ type = "String"
+ }
+ column "fbclid_name" {
+ type = "String"
+ }
+ column "gad_source_name" {
+ type = "String"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_conversion_goal_attributed_preaggregated"
+ sharding_key = "cityHash64(person_id)"
+ }
+ }
+
+ table "distinct_id_usage" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "minute" {
+ type = "DateTime"
+ }
+ column "event_count" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_distinct_id_usage"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_events_recent" {
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ column "_timestamp_ms" {
+ type = "DateTime64(3)"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings_text_embedding_3_large_3072" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings_text_embedding_3_small_1536" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_system_processes" {
+ settings = {
+ skip_unavailable_shards = "1"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "user" {
+ type = "String"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "address" {
+ type = "IPv6"
+ }
+ column "port" {
+ type = "UInt16"
+ }
+ column "initial_user" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "initial_address" {
+ type = "IPv6"
+ }
+ column "initial_port" {
+ type = "UInt16"
+ }
+ column "interface" {
+ type = "UInt8"
+ }
+ column "os_user" {
+ type = "String"
+ }
+ column "client_hostname" {
+ type = "String"
+ }
+ column "client_name" {
+ type = "String"
+ }
+ column "client_revision" {
+ type = "UInt64"
+ }
+ column "client_version_major" {
+ type = "UInt64"
+ }
+ column "client_version_minor" {
+ type = "UInt64"
+ }
+ column "client_version_patch" {
+ type = "UInt64"
+ }
+ column "http_method" {
+ type = "UInt8"
+ }
+ column "http_user_agent" {
+ type = "String"
+ }
+ column "http_referer" {
+ type = "String"
+ }
+ column "forwarded_for" {
+ type = "String"
+ }
+ column "quota_key" {
+ type = "String"
+ }
+ column "distributed_depth" {
+ type = "UInt64"
+ }
+ column "elapsed" {
+ type = "Float64"
+ }
+ column "is_cancelled" {
+ type = "UInt8"
+ }
+ column "is_all_data_sent" {
+ type = "UInt8"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "total_rows_approx" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "Int64"
+ }
+ column "peak_memory_usage" {
+ type = "Int64"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "query_kind" {
+ type = "String"
+ }
+ column "thread_ids" {
+ type = "Array(UInt64)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "Settings" {
+ type = "Map(String, String)"
+ }
+ column "current_database" {
+ type = "String"
+ }
+ column "ProfileEvents.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(ProfileEvents)"
+ }
+ column "ProfileEvents.Values" {
+ type = "Array(UInt64)"
+ alias = "mapValues(ProfileEvents)"
+ }
+ column "Settings.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(Settings)"
+ }
+ column "Settings.Values" {
+ type = "Array(String)"
+ alias = "mapValues(Settings)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "system"
+ remote_table = "processes"
+ }
+ }
+
+ table "duplicate_events" {
+ order_by = ["team_id", "distinct_id", "event", "inserted_at"]
+ partition_by = "toYYYYMMDD(inserted_at)"
+ ttl = "inserted_at + toIntervalDay(7)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "source_uuid" {
+ type = "UUID"
+ }
+ column "duplicate_uuid" {
+ type = "UUID"
+ }
+ column "similarity_score" {
+ type = "Float64"
+ }
+ column "dedup_type" {
+ type = "LowCardinality(String)"
+ }
+ column "is_confirmed" {
+ type = "UInt8"
+ }
+ column "reason" {
+ type = "Nullable(String)"
+ }
+ column "version" {
+ type = "String"
+ }
+ column "different_property_count" {
+ type = "UInt32"
+ }
+ column "properties_similarity" {
+ type = "Float64"
+ }
+ column "source_message" {
+ type = "String"
+ }
+ column "duplicate_message" {
+ type = "String"
+ }
+ column "distinct_fields" {
+ type = "Array(Tuple(field_name String, original_value String, new_value String))"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_duplicate_events" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.duplicate_events"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "error_tracking_fingerprint_issue_state" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "fingerprint" {
+ type = "String"
+ }
+ column "issue_id" {
+ type = "UUID"
+ }
+ column "issue_name" {
+ type = "Nullable(String)"
+ }
+ column "issue_description" {
+ type = "Nullable(String)"
+ }
+ column "issue_status" {
+ type = "String"
+ }
+ column "issue_severity" {
+ type = "Nullable(String)"
+ }
+ column "assigned_user_id" {
+ type = "Nullable(Int64)"
+ }
+ column "assigned_role_id" {
+ type = "Nullable(UUID)"
+ }
+ column "first_seen" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "raw_error_tracking_fingerprint_issue_state"
+ }
+ }
+
+ table "error_tracking_issue_fingerprint_overrides" {
+ order_by = ["team_id", "fingerprint"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "fingerprint" {
+ type = "String"
+ }
+ column "issue_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_error_tracking_issue_fingerprint_overrides" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.error_tracking_issue_fingerprint_overrides"
+ replica_name = "{replica}-{shard}"
+ 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 "$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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ default = "now64()"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ column "mat_metadata_backend" {
+ type = "String"
+ comment = "column_materializer::properties::metadata.backend"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "String"
+ comment = "column_materializer::properties::metadata.loggedIn"
+ }
+ 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_feature_flags" {
+ type = "Map(String, String)"
+ }
+ column "is_deleted" {
+ type = "Bool"
+ }
+ column "person_properties_map_custom" {
+ type = "Map(String, String)"
+ }
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_trace_id"
+ }
+ 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)"
+ comment = "column_materializer::properties::historical_migration"
+ }
+ 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)"
+ }
+ 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)"
+ 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_dead_letter_queue" {
+ order_by = ["id", "event_uuid", "distinct_id", "team_id"]
+ ttl = "toDate(_timestamp) + toIntervalWeek(4)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "ip" {
+ type = "String"
+ }
+ column "site_url" {
+ type = "String"
+ }
+ column "now" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "raw_payload" {
+ type = "String"
+ }
+ column "error_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "error_location" {
+ type = "String"
+ }
+ column "error" {
+ type = "String"
+ }
+ column "tags" {
+ type = "Array(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.events_dead_letter_queue"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "events_recent" {
+ 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 "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"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "exchange_rate" {
+ order_by = ["date", "currency"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "currency" {
+ type = "String"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "rate" {
+ type = "Decimal(18, 10)"
+ }
+ column "version" {
+ type = "UInt32"
+ default = "toUnixTimestamp(now())"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.exchange_rate"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "experiment_exposures_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "entity_id" {
+ type = "String"
+ }
+ column "variant" {
+ type = "String"
+ }
+ column "first_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "last_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "exposure_event_uuid" {
+ type = "UUID"
+ }
+ column "exposure_session_id" {
+ type = "String"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_experiment_exposures_preaggregated"
+ sharding_key = "cityHash64(entity_id)"
+ }
+ }
+
+ table "experiment_metric_events_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "entity_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "numeric_value" {
+ type = "Float64"
+ default = "0"
+ }
+ column "steps" {
+ type = "Array(UInt8)"
+ default = "[]"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_experiment_metric_events_preaggregated"
+ sharding_key = "cityHash64(entity_id)"
+ }
+ }
+
+ table "flag_evaluations" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "LowCardinality(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 "person_id" {
+ type = "UUID"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "timestamp"
+ }
+ 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 "flag_key" {
+ type = "String"
+ comment = "column_materializer::properties::$feature_flag"
+ }
+ column "response" {
+ type = "LowCardinality(String)"
+ comment = "column_materializer::properties::$feature_flag_response"
+ }
+ column "session_id" {
+ type = "String"
+ comment = "column_materializer::properties::$session_id"
+ }
+ column "request_id" {
+ type = "String"
+ comment = "column_materializer::properties::$feature_flag_request_id"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_flag_evaluations"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "groups" {
+ order_by = ["team_id", "group_type_index", "group_key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "group_type_index" {
+ type = "UInt8"
+ }
+ column "group_key" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "group_properties" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "Bool"
+ }
+ index "is_deleted_idx" {
+ expr = "is_deleted"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.groups"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "heatmaps" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "x" {
+ type = "Int16"
+ }
+ column "y" {
+ type = "Int16"
+ }
+ column "scale_factor" {
+ type = "Int16"
+ }
+ column "viewport_width" {
+ type = "Int16"
+ }
+ column "viewport_height" {
+ type = "Int16"
+ }
+ column "pointer_target_fixed" {
+ type = "Bool"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_heatmaps"
+ sharding_key = "cityHash64(concat(toString(team_id), '-', session_id, '-', toString(toDate(timestamp))))"
+ }
+ }
+
+ table "hog_invocation_results" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "function_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "function_id" {
+ type = "String"
+ }
+ column "invocation_id" {
+ type = "String"
+ }
+ column "parent_run_id" {
+ type = "String"
+ }
+ column "status" {
+ type = "LowCardinality(String)"
+ }
+ column "attempts" {
+ type = "UInt8"
+ }
+ column "is_retry" {
+ type = "UInt8"
+ }
+ column "scheduled_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "first_scheduled_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "started_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ }
+ column "finished_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ }
+ column "duration_ms" {
+ type = "Nullable(UInt32)"
+ }
+ column "error_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "error_message" {
+ type = "String"
+ }
+ column "event_uuid" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "String"
+ }
+ column "invocation_globals" {
+ type = "String"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "hog_invocation_results_data"
+ }
+ }
+
+ table "ingestion_warnings" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_ingestion_warnings"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "ingestion_warnings_v2_distributed" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "details" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "category" {
+ type = "LowCardinality(String)"
+ default = "coalesce(nullIf(JSONExtractString(details, 'category'), ''), 'unknown')"
+ }
+ column "severity" {
+ type = "LowCardinality(String)"
+ default = "coalesce(nullIf(JSONExtractString(details, 'severity'), ''), 'warning')"
+ }
+ column "pipeline_step" {
+ type = "LowCardinality(String)"
+ default = "coalesce(nullIf(JSONExtractString(details, 'pipelineStep'), ''), 'unknown')"
+ }
+ column "event_uuid" {
+ type = "Nullable(UUID)"
+ default = "toUUIDOrNull(JSONExtractString(details, 'eventUuid'))"
+ }
+ column "distinct_id" {
+ type = "Nullable(String)"
+ default = "nullIf(JSONExtractString(details, 'distinctId'), '')"
+ }
+ column "group_key" {
+ type = "Nullable(String)"
+ default = "nullIf(JSONExtractString(details, 'groupKey'), '')"
+ }
+ column "person_id" {
+ type = "Nullable(UUID)"
+ default = "toUUIDOrNull(JSONExtractString(details, 'personId'))"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "ingestion_warnings_v2"
+ }
+ }
+
+ table "kafka_session_replay_features" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "batch_id" {
+ type = "String"
+ }
+ column "first_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "last_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "event_count" {
+ type = "Int64"
+ }
+ column "mouse_position_count" {
+ type = "Int64"
+ }
+ column "mouse_sum_x" {
+ type = "Float64"
+ }
+ column "mouse_sum_x_squared" {
+ type = "Float64"
+ }
+ column "mouse_sum_y" {
+ type = "Float64"
+ }
+ column "mouse_sum_y_squared" {
+ type = "Float64"
+ }
+ column "mouse_distance_traveled" {
+ type = "Float64"
+ }
+ column "mouse_direction_change_count" {
+ type = "Int64"
+ }
+ column "mouse_velocity_sum" {
+ type = "Float64"
+ }
+ column "mouse_velocity_sum_of_squares" {
+ type = "Float64"
+ }
+ column "mouse_velocity_count" {
+ type = "Int64"
+ }
+ column "scroll_event_count" {
+ type = "Int64"
+ }
+ column "total_scroll_magnitude" {
+ type = "Float64"
+ }
+ column "scroll_direction_reversal_count" {
+ type = "Int64"
+ }
+ column "rapid_scroll_reversal_count" {
+ type = "Int64"
+ }
+ column "click_count" {
+ type = "Int64"
+ }
+ column "keypress_count" {
+ type = "Int64"
+ }
+ column "mouse_activity_count" {
+ type = "Int64"
+ }
+ column "rage_click_count" {
+ type = "Int64"
+ }
+ column "dead_click_count" {
+ type = "Int64"
+ }
+ column "inter_action_gap_count" {
+ type = "Int64"
+ }
+ column "inter_action_gap_sum_ms" {
+ type = "Float64"
+ }
+ column "inter_action_gap_sum_of_squares_ms" {
+ type = "Float64"
+ }
+ column "max_idle_gap_ms" {
+ type = "Float64"
+ }
+ column "quick_back_count" {
+ type = "Int64"
+ }
+ column "page_visit_count" {
+ type = "Int64"
+ }
+ column "visited_urls" {
+ type = "Array(String)"
+ }
+ column "console_error_count" {
+ type = "Int64"
+ }
+ column "console_error_after_click_count" {
+ type = "Int64"
+ }
+ column "network_request_count" {
+ type = "Int64"
+ }
+ column "network_failed_request_count" {
+ type = "Int64"
+ }
+ column "network_request_duration_sum" {
+ type = "Float64"
+ }
+ column "network_request_duration_sum_of_squares" {
+ type = "Float64"
+ }
+ column "network_request_duration_count" {
+ type = "Int64"
+ }
+ column "max_scroll_y" {
+ type = "Float64"
+ }
+ column "click_target_ids" {
+ type = "Array(Int64)"
+ }
+ column "text_selection_count" {
+ type = "Int64"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ engine "kafka" {
+ collection = "msk_cluster"
+ topic_list = "clickhouse_session_replay_features"
+ group_name = "group1"
+ format = "JSONEachRow"
+ }
+ }
+
+ table "llma_metrics_daily" {
+ order_by = ["team_id", "date", "metric_name"]
+ partition_by = "toYYYYMM(date)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "String"
+ }
+ column "metric_value" {
+ type = "Float64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.llma_metrics_daily"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "log_entries" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_log_entries"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "log_entries_distributed" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
+ table "marketing_conversions_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "conversion_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "conversion_math_value" {
+ type = "Float64"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "medium_name" {
+ type = "String"
+ }
+ column "content_name" {
+ type = "String"
+ }
+ column "term_name" {
+ type = "String"
+ }
+ column "referring_domain_name" {
+ type = "String"
+ }
+ column "gclid_name" {
+ type = "String"
+ }
+ column "fbclid_name" {
+ type = "String"
+ }
+ column "gad_source_name" {
+ type = "String"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_marketing_conversions_preaggregated"
+ sharding_key = "cityHash64(person_id)"
+ }
+ }
+
+ table "marketing_costs_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "source_id" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "grain" {
+ type = "LowCardinality(String)"
+ }
+ column "match_key" {
+ type = "String"
+ }
+ column "campaign_id" {
+ type = "String"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "ad_group_id" {
+ type = "String"
+ }
+ column "ad_group_name" {
+ type = "String"
+ }
+ column "ad_id" {
+ type = "String"
+ }
+ column "ad_name" {
+ type = "String"
+ }
+ column "cost_date" {
+ type = "Date"
+ }
+ column "cost" {
+ type = "Float64"
+ }
+ column "clicks" {
+ type = "Float64"
+ }
+ column "impressions" {
+ type = "Float64"
+ }
+ column "reported_conversions" {
+ type = "Float64"
+ }
+ column "reported_conversion_value" {
+ type = "Float64"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_marketing_costs_preaggregated"
+ sharding_key = "cityHash64(source_name, campaign_id)"
+ }
+ }
+
+ table "marketing_touchpoints_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "touchpoint_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "medium_name" {
+ type = "String"
+ }
+ column "content_name" {
+ type = "String"
+ }
+ column "term_name" {
+ type = "String"
+ }
+ column "referring_domain_name" {
+ type = "String"
+ }
+ column "gclid_name" {
+ type = "String"
+ }
+ column "fbclid_name" {
+ type = "String"
+ }
+ column "gad_source_name" {
+ type = "String"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_marketing_touchpoints_preaggregated"
+ sharding_key = "cityHash64(person_id)"
+ }
+ }
+
+ table "message_assets" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "function_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "function_id" {
+ type = "String"
+ }
+ column "parent_run_id" {
+ type = "String"
+ }
+ column "invocation_id" {
+ type = "String"
+ }
+ column "action_id" {
+ type = "String"
+ }
+ column "kind" {
+ type = "LowCardinality(String)"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "String"
+ }
+ column "recipient" {
+ type = "String"
+ }
+ column "subject" {
+ type = "String"
+ }
+ column "status" {
+ type = "LowCardinality(String)"
+ }
+ column "sent_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ column "html" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "message_assets_data"
+ }
+ }
+
+ table "metrics_query_log" {
+ order_by = ["toDate(timestamp)", "team_id", "query_type"]
+ partition_by = "toYYYYMM(timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "team_events_last_month" {
+ type = "UInt64"
+ }
+ column "user_id" {
+ type = "Int64"
+ }
+ column "kind" {
+ type = "String"
+ }
+ column "query_type" {
+ type = "String"
+ }
+ column "client_query_id" {
+ type = "String"
+ }
+ column "id" {
+ type = "String"
+ }
+ column "route_id" {
+ type = "String"
+ }
+ column "query_time_range_days" {
+ type = "Int64"
+ }
+ column "has_joins" {
+ type = "UInt8"
+ }
+ column "has_json_operations" {
+ type = "UInt8"
+ }
+ column "filter_by_type" {
+ type = "Array(String)"
+ }
+ column "breakdown_by" {
+ type = "Array(String)"
+ }
+ column "entity_math" {
+ type = "Array(String)"
+ }
+ column "filter" {
+ type = "String"
+ }
+ column "tables" {
+ type = "Array(LowCardinality(String))"
+ }
+ column "columns" {
+ type = "Array(LowCardinality(String))"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "log_comment" {
+ type = "String"
+ }
+ column "is_exception" {
+ type = "UInt8"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.metrics_query_log"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "new_raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "new_sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "new_writable_raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "new_writable_sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "pending_person_deletes_reporting" {
+ order_by = ["team_id", "deletion_type", "key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "Nullable(String)"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "delete_verified_at" {
+ type = "Nullable(DateTime)"
+ }
+ column "created_by_id" {
+ type = "Nullable(String)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/pending_person_deletes_reporting"
+ replica_name = "{shard}-{replica}"
+ }
+ }
+
+ table "performance_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_performance_events"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "person" {
+ order_by = ["team_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ default = "0"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "last_seen_at" {
+ type = "Nullable(DateTime64(3))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_collapsing" {
+ order_by = ["team_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_sign" {
+ type = "Int8"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/noshard/posthog.person_collapsing"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "person_distinct_id" {
+ order_by = ["team_id", "distinct_id", "person_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "distinct_id" {
+ type = "String"
+ comment = "skip_0003_fill_person_distinct_id2"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_sign" {
+ type = "Int8"
+ default = "1"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ alias = "if(_sign = -1, 1, 0)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "person_distinct_id2" {
+ order_by = ["team_id", "distinct_id"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ default = "1"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id2"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_distinct_id_overrides" {
+ order_by = ["team_id", "distinct_id"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_person_distinct_id_overrides" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id_overrides"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_overrides" {
+ order_by = ["team_id", "old_person_id"]
+ partition_by = "toYYYYMM(oldest_event)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int32"
+ }
+ column "old_person_id" {
+ type = "UUID"
+ }
+ column "override_person_id" {
+ type = "UUID"
+ }
+ column "merged_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "oldest_event" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "version" {
+ type = "Int32"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_overrides"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_overrides_to_delete" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "partitions" {
+ type = "Array(String)"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "distinct_id"]
+ }
+ }
+
+ table "person_static_cohort" {
+ order_by = ["team_id", "cohort_id", "person_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_static_cohort"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "pg_embeddings" {
+ order_by = ["team_id", "domain", "id"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "domain" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "id" {
+ type = "String"
+ }
+ column "vector" {
+ type = "Array(Float32)"
+ }
+ column "text" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.pg_embeddings"
+ replica_name = "{replica}-{shard}"
+ version_column = "timestamp"
+ is_deleted_column = "is_deleted"
+ }
+ }
+
+ table "plugin_log_entries" {
+ order_by = ["team_id", "plugin_id", "plugin_config_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalWeek(1)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "plugin_id" {
+ type = "Int64"
+ }
+ column "plugin_config_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "UUID"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.plugin_log_entries.fixed"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "preaggregation_results" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "uniq_exact_state" {
+ type = "AggregateFunction(uniqExact, UUID)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_preaggregation_results"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "property_definitions" {
+ order_by = ["team_id", "type", "coalesce(event, '')", "name", "coalesce(group_type_index, 255)"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt32"
+ }
+ column "project_id" {
+ type = "Nullable(UInt32)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "property_type" {
+ type = "Nullable(String)"
+ }
+ column "event" {
+ type = "Nullable(String)"
+ }
+ column "group_type_index" {
+ type = "Nullable(UInt8)"
+ }
+ column "type" {
+ type = "UInt8"
+ default = "1"
+ }
+ column "last_seen_at" {
+ type = "DateTime"
+ }
+ column "version" {
+ type = "UInt64"
+ materialized = "bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.property_definitions"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "property_values_distributed" {
+ column "team_id" {
+ type = "Int64"
+ codec = "DoubleDelta, ZSTD(1)"
+ }
+ column "property_type" {
+ type = "LowCardinality(String)"
+ }
+ column "property_key" {
+ type = "LowCardinality(String)"
+ }
+ column "property_value" {
+ type = "String"
+ }
+ column "property_count" {
+ type = "SimpleAggregateFunction(sum, UInt64)"
+ }
+ column "last_seen" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ default = "now()"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "property_values"
+ }
+ }
+
+ table "query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['RealTimeMicroseconds']"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['OSCPUVirtualTimeMicroseconds']"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ alias = "ProfileEvents['S3Clients']"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3DeleteObjects']"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CopyObject']"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3ListObjects']"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3HeadObject']"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObjectAttributes']"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CreateMultipartUpload']"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPartCopy']"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPart']"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3AbortMultipartUpload']"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CompleteMultipartUpload']"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3PutObject']"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObject']"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['ReadBufferFromS3Bytes']"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['WriteBufferFromS3Bytes']"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workflow"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.kind"
+ }
+ column "lc_id" {
+ type = "String"
+ alias = "CAST(log_comment.id, 'String')"
+ }
+ column "lc_route_id" {
+ type = "String"
+ alias = "CAST(log_comment.route_id, 'String')"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.access_method"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_label, 'String')"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_mask, 'String')"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.query_type"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.product"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ alias = "log_comment.chargeable"
+ }
+ column "lc_name" {
+ type = "String"
+ alias = "CAST(log_comment.name, 'String')"
+ }
+ column "lc_request_name" {
+ type = "String"
+ alias = "CAST(log_comment.request_name, 'String')"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ alias = "CAST(log_comment.client_query_id, 'String')"
+ }
+ column "lc_org_id" {
+ type = "String"
+ alias = "CAST(log_comment.org_id, 'String')"
+ }
+ column "lc_user_id" {
+ type = "Int64"
+ alias = "log_comment.user_id"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ alias = "log_comment.is_impersonated"
+ }
+ column "lc_session_id" {
+ type = "String"
+ alias = "CAST(log_comment.session_id, 'String')"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ alias = "log_comment.dashboard_id"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ alias = "log_comment.insight_id"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ alias = "log_comment.cohort_id"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ alias = "CAST(log_comment.batch_export_id, 'String')"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ alias = "log_comment.experiment_id"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ alias = "CAST(log_comment.experiment_feature_flag_key, 'String')"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ alias = "CAST(log_comment.alert_config_id, 'String')"
+ }
+ column "lc_feature" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.feature"
+ }
+ column "lc_table_id" {
+ type = "String"
+ alias = "CAST(log_comment.table_id, 'String')"
+ }
+ column "lc_warehouse_query" {
+ type = "Bool"
+ alias = "log_comment.warehouse_query"
+ }
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.person_on_events_mode"
+ }
+ column "lc_service_name" {
+ type = "String"
+ alias = "CAST(log_comment.service_name, 'String')"
+ }
+ column "lc_workload" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workload"
+ }
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
+ alias = "if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind'))"
+ }
+ column "lc_query__query" {
+ type = "String"
+ alias = "multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query'))"
+ }
+ column "lc_query" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), '')"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_namespace`, 'String')"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_type`, 'String')"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_id`, 'String')"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_run_id`, 'String')"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_type`, 'String')"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_id`, 'String')"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ alias = "log_comment.`temporal.attempt`"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.job_name`, 'String')"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.run_id`, 'String')"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.tags.owner`, 'String')"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_query_log_archive"
+ }
+ }
+
+ table "raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "raw_sessions_v3" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "session_recording_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "has_full_snapshot" {
+ type = "Int8"
+ comment = "column_materializer::has_full_snapshot"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "events_summary" {
+ type = "Array(String)"
+ comment = "column_materializer::events_summary"
+ }
+ column "click_count" {
+ type = "Int8"
+ comment = "column_materializer::click_count"
+ }
+ column "keypress_count" {
+ type = "Int8"
+ comment = "column_materializer::keypress_count"
+ }
+ column "timestamps_summary" {
+ type = "Array(DateTime64(6, 'UTC'))"
+ comment = "column_materializer::timestamps_summary"
+ }
+ column "first_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::first_event_timestamp"
+ }
+ column "last_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::last_event_timestamp"
+ }
+ column "urls" {
+ type = "Array(String)"
+ comment = "column_materializer::urls"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_recording_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "session_replay_embeddings" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_embeddings"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "session_replay_events" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "session_replay_features" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_position_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_sum_x" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_sum_x_squared" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_sum_y" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_sum_y_squared" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_distance_traveled" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_direction_change_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_velocity_sum" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_velocity_sum_of_squares" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_velocity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "scroll_event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "total_scroll_magnitude" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "scroll_direction_reversal_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "rapid_scroll_reversal_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "scroll_to_top_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "rage_click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "dead_click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "backspace_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "inter_action_gap_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "inter_action_gap_sum_ms" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "inter_action_gap_sum_of_squares_ms" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "max_idle_gap_ms" {
+ type = "SimpleAggregateFunction(max, Float64)"
+ }
+ column "long_idle_gap_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "quick_back_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "page_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "unique_url_count" {
+ type = "AggregateFunction(uniqCombined(12), String)"
+ }
+ column "login_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "signup_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "checkout_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "cart_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "billing_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "settings_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "account_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "error_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "not_found_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "admin_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "dashboard_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "onboarding_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "cancel_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "refund_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_after_click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_request_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_failed_request_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_4xx_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_5xx_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_request_duration_sum" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "network_request_duration_sum_of_squares" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "network_request_duration_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mutation_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "viewport_resize_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "touch_event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "max_scroll_y" {
+ type = "SimpleAggregateFunction(max, Float64)"
+ }
+ column "unique_click_target_count" {
+ type = "AggregateFunction(uniqCombined(12), Int64)"
+ }
+ column "unique_form_field_count" {
+ type = "AggregateFunction(uniqCombined(12), Int64)"
+ }
+ column "text_selection_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "selection_copy_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_features"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "sharded_app_metrics2" {
+ order_by = ["team_id", "app_source", "app_source_id", "instance_id", "toStartOfHour(timestamp)", "metric_kind", "metric_name"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "app_source" {
+ type = "LowCardinality(String)"
+ }
+ column "app_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "metric_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ 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"
+ max_avg_part_size_for_too_many_parts = "0"
+ }
+ 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 "$group_0" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_0"
+ }
+ column "$group_1" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_1"
+ }
+ column "$group_2" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_2"
+ }
+ column "$group_3" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_3"
+ }
+ column "$group_4" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_4"
+ }
+ column "$window_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$window_id"
+ }
+ column "$session_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$session_id"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ default = "now64()"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ column "mat_metadata_backend" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, 'metadata.backend'), '^\"|\"$', '')"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, 'metadata.loggedIn'), '^\"|\"$', '')"
+ }
+ 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_ids" {
+ type = "Array(String)"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
+ }
+ 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'))), 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 "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 "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
+ }
+ 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_historical_migration" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, 'historical_migration', '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 "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)"
+ 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)')"
+ }
+ 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
+ }
+ index "bloom_filter_$session_id" {
+ expr = "nullIf(nullIf(`$session_id`, ''), 'null')"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ index "minmax_mat_metadata_backend" {
+ expr = "mat_metadata_backend"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_mat_metadata_loggedIn" {
+ expr = "mat_metadata_loggedIn"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_mat_$ai_trace_id" {
+ expr = "`mat_$ai_trace_id`"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.events"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_experiment_exposures_preaggregated" {
+ order_by = ["team_id", "job_id", "entity_id", "breakdown_value"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "expires_at"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "entity_id" {
+ type = "String"
+ }
+ column "variant" {
+ type = "String"
+ }
+ column "first_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "last_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "exposure_event_uuid" {
+ type = "UUID"
+ }
+ column "exposure_session_id" {
+ type = "String"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.experiment_exposures_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_flag_evaluations" {
+ order_by = ["team_id", "flag_key", "toDate(timestamp)", "cityHash64(distinct_id)"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "LowCardinality(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 "person_id" {
+ type = "UUID"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "timestamp"
+ }
+ column "$group_0" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_0"
+ }
+ column "$group_1" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_1"
+ }
+ column "$group_2" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_2"
+ }
+ column "$group_3" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_3"
+ }
+ column "$group_4" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_4"
+ }
+ column "flag_key" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag"
+ }
+ column "response" {
+ type = "LowCardinality(String)"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag_response"
+ }
+ column "session_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$session_id"
+ }
+ column "request_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_request_id'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag_request_id"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "distinct_id_idx" {
+ expr = "distinct_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "person_id_idx" {
+ expr = "person_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "session_id_idx" {
+ expr = "session_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "request_id_idx" {
+ expr = "request_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "inserted_at_idx" {
+ expr = "inserted_at"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.flag_evaluations"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_heatmaps" {
+ order_by = ["type", "team_id", "toDate(timestamp)", "current_url", "viewport_width"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "x" {
+ type = "Int16"
+ }
+ column "y" {
+ type = "Int16"
+ }
+ column "scale_factor" {
+ type = "Int16"
+ }
+ column "viewport_width" {
+ type = "Int16"
+ }
+ column "viewport_height" {
+ type = "Int16"
+ }
+ column "pointer_target_fixed" {
+ type = "Bool"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.heatmaps"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_log_entries" {
+ order_by = ["team_id", "log_source", "log_source_id", "instance_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_log_entries"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_performance_events" {
+ order_by = ["team_id", "toDate(timestamp)", "session_id", "pageview_id", "timestamp"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalWeek(3)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.performance_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_buffer" {
+ order_by = ["inserted_at", "model_name", "cityHash64(document_id)"]
+ partition_by = "toDate(inserted_at)"
+ ttl = "inserted_at + toIntervalDay(1)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_buffer"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_text_embedding_3_large_3072" {
+ order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "rendering", "cityHash64(document_id)"]
+ partition_by = "toMonday(timestamp)"
+ ttl = "timestamp + toIntervalMonth(3)"
+ settings = {
+ index_granularity = "512"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_large_3072" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ index "embedding_idx_l2" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'L2Distance', 3072)"
+ granularity = 100000000
+ }
+ index "embedding_idx_cosine" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'cosineDistance', 3072)"
+ granularity = 100000000
+ }
+ constraint "embedding_dimension_check" {
+ check = "length(embedding) = 3072"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_text_embedding_3_small_1536" {
+ order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "rendering", "cityHash64(document_id)"]
+ partition_by = "toMonday(timestamp)"
+ ttl = "timestamp + toIntervalMonth(3)"
+ settings = {
+ index_granularity = "512"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_small_1536" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ index "embedding_idx_l2" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'L2Distance', 1536)"
+ granularity = 100000000
+ }
+ index "embedding_idx_cosine" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'cosineDistance', 1536)"
+ granularity = 100000000
+ }
+ constraint "embedding_dimension_check" {
+ check = "length(embedding) = 1536"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_preaggregation_results" {
+ order_by = ["team_id", "job_id", "time_window_start", "breakdown_value"]
+ partition_by = "toYYYYMM(time_window_start)"
+ ttl = "expires_at"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "uniq_exact_state" {
+ type = "AggregateFunction(uniqExact, UUID)"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.preaggregation_results"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_precalculated_person_properties" {
+ order_by = ["team_id", "condition", "distinct_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "condition" {
+ type = "String"
+ }
+ column "matches" {
+ type = "Bool"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_precalculated_person_properties"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_raw_sessions_v3" {
+ order_by = ["team_id", "session_timestamp", "session_id_v7"]
+ partition_by = "toYYYYMM(session_timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ index "event_names_bloom_filter" {
+ expr = "event_names"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ index "flag_keys_bloom_filter" {
+ expr = "flag_keys"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions_v3"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_session_recording_events" {
+ order_by = ["team_id", "toHour(timestamp)", "session_id", "timestamp", "uuid"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(created_at) + toIntervalWeek(3)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "has_full_snapshot" {
+ type = "Int8"
+ materialized = "JSONExtractBool(snapshot_data, 'has_full_snapshot')"
+ comment = "column_materializer::has_full_snapshot"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "events_summary" {
+ type = "Array(String)"
+ materialized = "JSONExtract(JSON_QUERY(snapshot_data, '$.events_summary[*]'), 'Array(String)')"
+ }
+ column "click_count" {
+ type = "Int8"
+ materialized = "length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 2) AND (JSONExtractInt(x, 'data', 'source') = 2)), events_summary))"
+ }
+ column "keypress_count" {
+ type = "Int8"
+ materialized = "length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 5)), events_summary))"
+ }
+ column "timestamps_summary" {
+ type = "Array(DateTime64(6, 'UTC'))"
+ materialized = "arraySort(arrayMap(x -> toDateTime(JSONExtractInt(x, 'timestamp') / 1000), events_summary))"
+ }
+ column "first_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ materialized = "arrayReduce('min', timestamps_summary)"
+ }
+ column "last_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ materialized = "arrayReduce('max', timestamps_summary)"
+ }
+ column "urls" {
+ type = "Array(String)"
+ materialized = "arrayFilter(x -> (x != ''), arrayMap(x -> JSONExtractString(x, 'data', 'href'), events_summary))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_recording_events"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_session_replay_embeddings" {
+ order_by = ["toDate(generation_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(generation_timestamp)"
+ ttl = "toDate(generation_timestamp) + toIntervalYear(1)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_embeddings"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_session_replay_events" {
+ order_by = ["toDate(min_first_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(min_first_timestamp)"
+ settings = {
+ index_granularity = "512"
+ ttl_only_drop_parts = "1"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "swap_person_distinct_id" {
+ order_by = ["team_id", "distinct_id", "person_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_sign" {
+ type = "Int8"
+ default = "1"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ alias = "if(_sign = -1, 1, 0)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/noshard/posthog.swap_person_distinct_id"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "tophog" {
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "metric" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ default = "'sum'"
+ }
+ column "key" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "0"
+ }
+ column "pipeline" {
+ type = "LowCardinality(String)"
+ }
+ column "lane" {
+ type = "LowCardinality(String)"
+ }
+ column "labels" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_tophog"
+ sharding_key = "cityHash64(toString(key))"
+ }
+ }
+
+ table "usage_report_events_preagg" {
+ column "date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_mode" {
+ type = "LowCardinality(String)"
+ }
+ column "lib" {
+ type = "LowCardinality(String)"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "distinct_events_unique" {
+ type = "AggregateFunction(uniqExact, Tuple(UInt64, UInt64, UInt64))"
+ }
+ column "event_count" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_usage_report_events_preagg"
+ sharding_key = "sipHash64(date)"
+ }
+ }
+
+ table "web_bot_definition" {
+ column "id" {
+ type = "UInt64"
+ }
+ column "parent_id" {
+ type = "UInt64"
+ }
+ column "regexp" {
+ type = "String"
+ }
+ column "keys" {
+ type = "Array(String)"
+ }
+ column "values" {
+ type = "Array(String)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_bot_definition"
+ sharding_key = "sipHash64(id)"
+ }
+ }
+
+ table "web_bounces_daily_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "updated_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_bounces_daily"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_bounces_dimensional_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_bounces_dimensional_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_bounces_hourly_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "updated_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_bounces_hourly"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_goals_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "action_id" {
+ type = "Int64"
+ }
+ column "count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "unique_persons_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_goals_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_overview_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "uniq_sessions_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_duration_state" {
+ type = "AggregateFunction(avg, Float64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_overview_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_pre_aggregated_bounces" {
+ order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "web_pre_aggregated_stats" {
+ order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "web_pre_aggregated_teams" {
+ order_by = ["team_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "enabled_by" {
+ type = "String"
+ default = "'system'"
+ }
+ column "version" {
+ type = "UInt32"
+ default = "toUnixTimestamp(now())"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_analytics_team_selection"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "web_stats_daily_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "updated_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_stats_daily"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_stats_dimensional_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_dimensional_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_stats_frustration_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "sum_rage_clicks_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "sum_dead_clicks_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "sum_errors_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_frustration_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_stats_hourly_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "updated_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_stats_hourly"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_stats_paths_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Nullable(Float64))"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_paths_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_stats_paths_preaggregated_pathkey" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Nullable(Float64))"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_paths_preaggregated_pathkey"
+ sharding_key = "sipHash64(breakdown_value)"
+ }
+ }
+
+ table "web_stats_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_by" {
+ type = "String"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_vitals_paths_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "path" {
+ type = "String"
+ }
+ column "inp_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "lcp_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "cls_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "fcp_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_vitals_paths_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "writable_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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ column "consumer_breadcrumbs" {
+ type = "Array(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)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_events_dead_letter_queue" {
+ column "id" {
+ type = "UUID"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "ip" {
+ type = "String"
+ }
+ column "site_url" {
+ type = "String"
+ }
+ column "now" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "raw_payload" {
+ type = "String"
+ }
+ column "error_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "error_location" {
+ type = "String"
+ }
+ column "error" {
+ type = "String"
+ }
+ column "tags" {
+ type = "Array(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog_single_shard"
+ remote_database = "posthog"
+ remote_table = "events_dead_letter_queue"
+ }
+ }
+
+ table "writable_events_recent" {
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports_writable"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_log_entries" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_log_entries"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_text_embedding_3_large_3072" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_text_embedding_3_small_1536" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "query_log_archive_buffer"
+ }
+ }
+
+ table "writable_raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_raw_sessions_v3" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ 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)"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_session_recording_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_recording_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_session_replay_embeddings" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_embeddings"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "writable_session_replay_events" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "writeable_performance_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_performance_events"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ materialized_view "ops_query_log_archive_mv" {
+ to_table = "posthog.writable_query_log_archive"
+ query = <<SQL
+SELECT
+ hostname,
+ user,
+ query_id,
+ initial_query_id,
+ is_initial_query,
+ type,
+ event_date,
+ event_time,
+ event_time_microseconds,
+ query_start_time,
+ query_start_time_microseconds,
+ query_duration_ms,
+ read_rows,
+ read_bytes,
+ written_rows,
+ written_bytes,
+ result_rows,
+ result_bytes,
+ memory_usage,
+ peak_threads_usage,
+ current_database,
+ query,
+ formatted_query,
+ normalized_query_hash,
+ query_kind,
+ exception_code,
+ exception,
+ stack_trace,
+ JSONExtractInt(log_comment, 'team_id') AS team_id,
+ if(isValidJSON(log_comment), log_comment, '{}') AS log_comment,
+ ProfileEvents
+FROM system.query_log
+WHERE type != 'QueryStart'
+SQL
+
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "String"
+ }
+ column "ProfileEvents" {
+ type = "Map(LowCardinality(String), UInt64)"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-large-3072'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-small-1536'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "session_replay_features_mv" {
+ to_table = "posthog.writable_session_replay_features"
+ query = <<SQL
+SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(first_timestamp) AS min_first_timestamp,
+ max(last_timestamp) AS max_last_timestamp,
+ sum(event_count) AS event_count,
+ sum(mouse_position_count) AS mouse_position_count,
+ sum(mouse_sum_x) AS mouse_sum_x,
+ sum(mouse_sum_x_squared) AS mouse_sum_x_squared,
+ sum(mouse_sum_y) AS mouse_sum_y,
+ sum(mouse_sum_y_squared) AS mouse_sum_y_squared,
+ sum(mouse_distance_traveled) AS mouse_distance_traveled,
+ sum(mouse_direction_change_count) AS mouse_direction_change_count,
+ sum(mouse_velocity_sum) AS mouse_velocity_sum,
+ sum(mouse_velocity_sum_of_squares) AS mouse_velocity_sum_of_squares,
+ sum(mouse_velocity_count) AS mouse_velocity_count,
+ sum(scroll_event_count) AS scroll_event_count,
+ sum(total_scroll_magnitude) AS total_scroll_magnitude,
+ sum(scroll_direction_reversal_count) AS scroll_direction_reversal_count,
+ sum(rapid_scroll_reversal_count) AS rapid_scroll_reversal_count,
+ sum(click_count) AS click_count,
+ sum(keypress_count) AS keypress_count,
+ sum(mouse_activity_count) AS mouse_activity_count,
+ sum(rage_click_count) AS rage_click_count,
+ sum(dead_click_count) AS dead_click_count,
+ sum(inter_action_gap_count) AS inter_action_gap_count,
+ sum(inter_action_gap_sum_ms) AS inter_action_gap_sum_ms,
+ sum(inter_action_gap_sum_of_squares_ms) AS inter_action_gap_sum_of_squares_ms,
+ max(max_idle_gap_ms) AS max_idle_gap_ms,
+ sum(quick_back_count) AS quick_back_count,
+ sum(page_visit_count) AS page_visit_count,
+ uniqExactArrayState(visited_urls) AS unique_url_count,
+ sum(console_error_count) AS console_error_count,
+ sum(console_error_after_click_count) AS console_error_after_click_count,
+ sum(network_request_count) AS network_request_count,
+ sum(network_failed_request_count) AS network_failed_request_count,
+ sum(network_request_duration_sum) AS network_request_duration_sum,
+ sum(network_request_duration_sum_of_squares) AS network_request_duration_sum_of_squares,
+ sum(network_request_duration_count) AS network_request_duration_count,
+ max(max_scroll_y) AS max_scroll_y,
+ uniqExactArrayState(click_target_ids) AS unique_click_target_count,
+ sum(text_selection_count) AS text_selection_count,
+ max(is_deleted) AS is_deleted
+FROM posthog.kafka_session_replay_features
+GROUP BY
+ session_id, team_id
+SQL
+
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "max_last_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "event_count" {
+ type = "Int64"
+ }
+ column "mouse_position_count" {
+ type = "Int64"
+ }
+ column "mouse_sum_x" {
+ type = "Float64"
+ }
+ column "mouse_sum_x_squared" {
+ type = "Float64"
+ }
+ column "mouse_sum_y" {
+ type = "Float64"
+ }
+ column "mouse_sum_y_squared" {
+ type = "Float64"
+ }
+ column "mouse_distance_traveled" {
+ type = "Float64"
+ }
+ column "mouse_direction_change_count" {
+ type = "Int64"
+ }
+ column "mouse_velocity_sum" {
+ type = "Float64"
+ }
+ column "mouse_velocity_sum_of_squares" {
+ type = "Float64"
+ }
+ column "mouse_velocity_count" {
+ type = "Int64"
+ }
+ column "scroll_event_count" {
+ type = "Int64"
+ }
+ column "total_scroll_magnitude" {
+ type = "Float64"
+ }
+ column "scroll_direction_reversal_count" {
+ type = "Int64"
+ }
+ column "rapid_scroll_reversal_count" {
+ type = "Int64"
+ }
+ column "click_count" {
+ type = "Int64"
+ }
+ column "keypress_count" {
+ type = "Int64"
+ }
+ column "mouse_activity_count" {
+ type = "Int64"
+ }
+ column "rage_click_count" {
+ type = "Int64"
+ }
+ column "dead_click_count" {
+ type = "Int64"
+ }
+ column "inter_action_gap_count" {
+ type = "Int64"
+ }
+ column "inter_action_gap_sum_ms" {
+ type = "Float64"
+ }
+ column "inter_action_gap_sum_of_squares_ms" {
+ type = "Float64"
+ }
+ column "max_idle_gap_ms" {
+ type = "Float64"
+ }
+ column "quick_back_count" {
+ type = "Int64"
+ }
+ column "page_visit_count" {
+ type = "Int64"
+ }
+ column "unique_url_count" {
+ type = "AggregateFunction(uniqExactArray, Array(String))"
+ }
+ column "console_error_count" {
+ type = "Int64"
+ }
+ column "console_error_after_click_count" {
+ type = "Int64"
+ }
+ column "network_request_count" {
+ type = "Int64"
+ }
+ column "network_failed_request_count" {
+ type = "Int64"
+ }
+ column "network_request_duration_sum" {
+ type = "Float64"
+ }
+ column "network_request_duration_sum_of_squares" {
+ type = "Float64"
+ }
+ column "network_request_duration_count" {
+ type = "Int64"
+ }
+ column "max_scroll_y" {
+ type = "Float64"
+ }
+ column "unique_click_target_count" {
+ type = "AggregateFunction(uniqExactArray, Array(Int64))"
+ }
+ column "text_selection_count" {
+ type = "Int64"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ }
+
+ view "custom_metrics" {
+ query = <<SQL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_test
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_replication_queue
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_server_crash
+UNION ALL
+SELECT *
+FROM posthog.custom_metrics_table_sizes
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_part_counts
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_dictionaries
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_S3DiskBytesUsed' AS name,
+ map('instance', hostname(), 'disk', disk_name) AS labels,
+ toFloat64(sum(bytes_on_disk)) AS value,
+ 'Bytes currently used by ClickHouse parts on S3-backed disks on this node' AS help,
+ 'gauge' AS type
+FROM system.parts
+WHERE disk_name IN ('s3disk', 'cache')
+GROUP BY
+ disk_name
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeFailures15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(count()) AS value,
+ 'Number of failed merge operations in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM system.part_log
+WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+AND
+ (event_type = 'MergeParts')
+AND
+ (error > 0)
+AND
+ (merge_reason != 'NotAMerge')
+AND
+ (error != 40)
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeRetriesMaxPerTable15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(max(cnt)) AS value,
+ 'Max failed merge retries for any single table in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT count() AS cnt
+ FROM system.part_log
+ WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+ AND
+ (event_type = 'MergeParts')
+ AND
+ (error > 0)
+ AND
+ (merge_reason != 'NotAMerge')
+ AND
+ (error != 40)
+ GROUP BY
+ database, `table`, partition_id
+ )
+SQL
+
+ }
+
+ view "custom_metrics_backups" {
+ query = <<SQL
+WITH
+ ['ClickHouseCustomMetric_BackupFailed', 'ClickHouseCustomMetric_BackupSuccess', 'ClickHouseCustomMetric_BackupCancelled', 'ClickHouseCustomMetric_BackupAttempts'] AS names,
+ [toInt64(countIf(status = 'BACKUP_FAILED')), toInt64(countIf(status = 'BACKUP_CREATED')), toInt64(countIf(status = 'BACKUP_CANCELLED')), toInt64(countIf(status = 'CREATING_BACKUP'))] AS `values`,
+ ['Number of failed backups', 'Number of successful backups', 'Number of cancelled backups', 'Number of backup attempts'] AS descriptions,
+ ['gauge', 'gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.backup_log
+WHERE event_date = today()
+GROUP BY
+ event_date
+SQL
+
+ }
+
+ view "custom_metrics_dictionaries" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_DictionariesFailed' AS name,
+ map(
+ 'instance',
+ hostname(),
+ 'database',
+ d.database,
+ 'dictionary',
+ d.dict_name,
+ 'uuid',
+ toString(d.uuid),
+ 'status',
+ toString(d.status)
+ ) AS labels,
+ toUInt64(1) AS value,
+ 'Dictionary is in FAILED or FAILED_AND_RELOADING status' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT name AS dict_name, database, uuid, status
+ FROM system.dictionaries
+ WHERE status IN ('FAILED', 'FAILED_AND_RELOADING')
+ ) AS d
+SQL
+
+ }
+
+ view "custom_metrics_part_counts" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_MaxPartCountPerPartition' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`, 'partition', partition) AS labels,
+ part_count AS value,
+ 'Maximum number of active parts for any partition in a PostHog table' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT database, `table`, partition, count() AS part_count
+ FROM system.parts
+ WHERE
+ active
+ AND
+ (database = 'posthog')
+ GROUP BY
+ database, `table`, partition
+ ORDER BY database ASC, `table` ASC, part_count DESC, partition ASC
+ LIMIT 1 BY database, `table`
+ )
+SQL
+
+ }
+
+ view "custom_metrics_replication_queue" {
+ query = <<SQL
+WITH
+ ['ClickHouseCustomMetric_ReplicationQueueStuckEntries', 'ClickHouseCustomMetric_ReplicationQueueMaxPostponedEntrySeconds', 'ClickHouseCustomMetric_ReplicationQueueMaxErrorEntrySeconds'] AS names,
+ [toInt64(countIf(create_time < (now() - toIntervalDay(15)))), maxIf(dateDiff('seconds', create_time, last_postpone_time), last_postpone_time != '1970-01-01'), maxIf(dateDiff('seconds', create_time, last_exception_time), (last_exception_time != '1970-01-01') AND (last_exception_time > (now() - toIntervalMinute(5))))] AS `values`,
+ ['Number of entries that have been in the replication queue for more than 15 days', 'Maximum number of seconds that an entry has been postponed', 'Maximum number of seconds that an entry has been in error'] AS descriptions,
+ ['gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('table', `table`, 'instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.replication_queue
+GROUP BY
+ `table`
+HAVING
+ value > 0
+SQL
+
+ }
+
+ view "custom_metrics_server_crash" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_ServerCrash' AS name,
+ map('instance', hostname()) AS labels,
+ count() AS value,
+ 'Number of server crashes for current date' AS help,
+ 'gauge' AS type
+FROM system.crash_log
+WHERE event_date = today()
+GROUP BY
+ hostname()
+SQL
+
+ }
+
+ view "custom_metrics_table_sizes" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_TableTotalBytes' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`) AS labels,
+ CAST(total_bytes, 'Float64') AS value,
+ 'Size of a database table on a given node (need a sum for sharded)' AS help,
+ 'gauge' AS type
+FROM system.tables
+WHERE
+ (database NOT IN ('INFORMATION_SCHEMA', 'information_schema'))
+AND
+ (total_bytes IS NOT NULL)
+SQL
+
+ }
+
+ view "custom_metrics_test" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_Test' AS name,
+ map('instance', hostname()) AS labels,
+ 1 AS value,
+ 'Test to check that the metric endpoint is working' AS help,
+ 'gauge' AS type
+SQL
+
+ }
+
+ view "events_batch_export" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ (events.timestamp >= ({interval_start: DateTime64} - toIntervalDay({lookback_days: Int32})))
+AND
+ (events.timestamp < ({interval_end: DateTime64} + toIntervalDay(1)))
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "events_batch_export_recent" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ inserted_at AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events_recent
+PREWHERE
+ (events_recent.inserted_at >= {interval_start: DateTime64}) AND (events_recent.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events_recent.distinct_id), cityHash64(events_recent.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "events_batch_export_unbounded" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "persons_batch_export" {
+ query = <<SQL
+WITH
+ new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
+ new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
+ all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
+SELECT
+ p.team_id AS team_id,
+ pd.distinct_id AS distinct_id,
+ toString(p.id) AS person_id,
+ p.properties AS properties,
+ pd.version AS person_distinct_id_version,
+ p.version AS person_version,
+ p.created_at AS created_at,
+ multiIf(
+ ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
+ pd._timestamp,
+ ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
+ p._timestamp,
+ least(p._timestamp, pd._timestamp)
+ ) AS _inserted_at
+FROM
+ posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((id, version) IN (all_new_persons))
+ORDER BY _inserted_at ASC
+SQL
+
+ }
+
+ view "posthog_document_embeddings_union_view" {
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-small-1536' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_small_1536
+UNION ALL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-large-3072' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_large_3072
+SQL
+
+ }
+
+ view "raw_sessions_v" {
+ query = <<SQL
+SELECT
+ session_id_v7,
+ fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)) AS session_timestamp,
+ team_id,
+ argMaxMerge(distinct_id) AS distinct_id,
+ 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(initial_browser) AS initial_browser,
+ argMinMerge(initial_browser_version) AS initial_browser_version,
+ argMinMerge(initial_os) AS initial_os,
+ argMinMerge(initial_os_version) AS initial_os_version,
+ argMinMerge(initial_device_type) AS initial_device_type,
+ argMinMerge(initial_viewport_width) AS initial_viewport_width,
+ argMinMerge(initial_viewport_height) AS initial_viewport_height,
+ argMinMerge(initial_geoip_country_code) AS initial_geoip_country_code,
+ argMinMerge(initial_geoip_subdivision_1_code) AS initial_geoip_subdivision_1_code,
+ argMinMerge(initial_geoip_subdivision_1_name) AS initial_geoip_subdivision_1_name,
+ argMinMerge(initial_geoip_subdivision_city_name) AS initial_geoip_subdivision_city_name,
+ argMinMerge(initial_geoip_time_zone) AS initial_geoip_time_zone,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ argMinMerge(initial__kx) AS initial__kx,
+ argMinMerge(initial_irclid) AS initial_irclid,
+ sum(pageview_count) AS pageview_count,
+ uniqMerge(pageview_uniq) AS pageview_uniq,
+ sum(autocapture_count) AS autocapture_count,
+ uniqMerge(autocapture_uniq) AS autocapture_uniq,
+ sum(screen_count) AS screen_count,
+ uniqMerge(screen_uniq) AS screen_uniq,
+ max(maybe_has_session_replay) AS maybe_has_session_replay,
+ uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,
+ argMinMerge(vitals_lcp) AS vitals_lcp
+FROM posthog.raw_sessions
+GROUP BY
+ session_id_v7, team_id
+SQL
+
+ }
+
+ view "raw_sessions_v3_v" {
+ 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" {
+ query = <<SQL
+SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(exit_url) AS exit_url,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ sumMap(event_count_map) AS event_count_map,
+ sum(pageview_count) AS pageview_count,
+ sum(autocapture_count) AS autocapture_count
+FROM posthog.sessions
+GROUP BY
+ session_id, team_id
+SQL
+
+ }
+
+ dictionary "channel_definition_dict" {
+ primary_key = ["domain", "kind"]
+ lifetime {
+ min = 3000
+ max = 3600
+ }
+ attribute "domain" {
+ type = "String"
+ }
+ attribute "kind" {
+ type = "String"
+ }
+ attribute "domain_type" {
+ type = "Nullable(String)"
+ }
+ attribute "type_if_paid" {
+ type = "Nullable(String)"
+ }
+ attribute "type_if_organic" {
+ type = "Nullable(String)"
+ }
+ source "clickhouse" {
+ user = "dict_reader"
+ table = "channel_definition"
+ }
+ layout "complex_key_hashed" {
+ }
+ }
+
+ dictionary "web_bot_definition_dict" {
+ primary_key = ["regexp"]
+ lifetime {
+ min = 3000
+ max = 3600
+ }
+ attribute "regexp" {
+ type = "String"
+ }
+ attribute "name" {
+ type = "String"
+ }
+ attribute "category" {
+ type = "String"
+ }
+ attribute "traffic_type" {
+ type = "String"
+ }
+ attribute "operator" {
+ type = "String"
+ }
+ source "clickhouse" {
+ user = "default"
+ db = "posthog"
+ table = "web_bot_definition"
+ }
+ layout "regexp_tree" {
+ }
+ }
+
+ dictionary "web_pre_aggregated_teams_dict" {
+ primary_key = ["team_id"]
+ lifetime {
+ min = 3000
+ max = 3600
+ }
+ attribute "team_id" {
+ type = "UInt64"
+ }
+ source "clickhouse" {
+ user = "dict_reader"
+ query = "SELECT team_id FROM `web_pre_aggregated_teams` FINAL WHERE version > 0"
+ }
+ layout "hashed" {
+ }
+ }
+}
+
+named_collection "msk_cluster" {
+ external = true
+}
+
+named_collection "warpstream_calculated_events" {
+ external = true
+}
+
+named_collection "warpstream_cyclotron" {
+ external = true
+}
+
+named_collection "warpstream_ingestion" {
+ external = true
+}
+
+named_collection "warpstream_logs" {
+ external = true
+}
+
+named_collection "warpstream_metrics" {
+ external = true
+}
+
+named_collection "warpstream_replay" {
+ external = true
+}
+
+named_collection "warpstream_shared" {
+ external = true
+}
+
+named_collection "warpstream_traces" {
+ external = true
+}
diff --git a/posthog/clickhouse/hcl/golden/prod-us/data.hcl b/posthog/clickhouse/hcl/golden/prod-us/data.hcl
new file mode 100644
index 000000000000..dd290d04fb23
--- /dev/null
+++ b/posthog/clickhouse/hcl/golden/prod-us/data.hcl
@@ -0,0 +1,9893 @@
+database "posthog" {
+ table "adhoc_events_deletion" {
+ order_by = ["team_id", "uuid"]
+ ttl = "deleted_at + toIntervalMonth(3) WHERE is_deleted = 1"
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ column "deleted_at" {
+ type = "DateTime"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ default = "0"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.adhoc_events_deletion"
+ replica_name = "{replica}-{shard}"
+ version_column = "deleted_at"
+ is_deleted_column = "is_deleted"
+ }
+ }
+
+ table "ai_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "LowCardinality(String)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "retention_days" {
+ type = "Int16"
+ default = "30"
+ }
+ column "drop_date" {
+ type = "Date"
+ materialized = "toDate(timestamp) + toIntervalDay(retention_days)"
+ }
+ column "trace_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "Nullable(String)"
+ }
+ column "parent_id" {
+ type = "Nullable(String)"
+ }
+ column "span_id" {
+ type = "Nullable(String)"
+ }
+ column "span_type" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "generation_id" {
+ type = "Nullable(String)"
+ }
+ column "experiment_id" {
+ type = "Nullable(String)"
+ }
+ column "span_name" {
+ type = "Nullable(String)"
+ }
+ column "trace_name" {
+ type = "Nullable(String)"
+ }
+ column "prompt_name" {
+ type = "Nullable(String)"
+ }
+ column "model" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "provider" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "framework" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "total_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "text_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "text_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "image_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "image_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "audio_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "audio_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "video_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "video_output_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "reasoning_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "cache_read_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "cache_creation_input_tokens" {
+ type = "Nullable(Int64)"
+ }
+ column "web_search_count" {
+ type = "Nullable(Int64)"
+ }
+ column "input_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "output_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "total_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "request_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "web_search_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "audio_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "image_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "video_cost_usd" {
+ type = "Nullable(Float64)"
+ }
+ column "latency" {
+ type = "Nullable(Float64)"
+ }
+ column "time_to_first_token" {
+ type = "Nullable(Float64)"
+ }
+ column "is_error" {
+ type = "UInt8"
+ }
+ column "error" {
+ type = "Nullable(String)"
+ }
+ column "error_type" {
+ type = "LowCardinality(Nullable(String))"
+ }
+ column "error_normalized" {
+ type = "Nullable(String)"
+ }
+ column "input" {
+ type = "Nullable(String)"
+ }
+ column "output" {
+ type = "Nullable(String)"
+ }
+ column "output_choices" {
+ type = "Nullable(String)"
+ }
+ column "input_state" {
+ type = "Nullable(String)"
+ }
+ column "output_state" {
+ type = "Nullable(String)"
+ }
+ column "tools" {
+ type = "Nullable(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "ai_events"
+ remote_database = "posthog"
+ remote_table = "ai_events"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "app_metrics2" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "app_source" {
+ type = "LowCardinality(String)"
+ }
+ column "app_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "metric_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_app_metrics2"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "async_deletion_run" {
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "deletion_type", "key"]
+ }
+ }
+
+ table "asyncdeletion" {
+ order_by = ["deletion_type", "delete_verified_at"]
+ partition_by = "toYYYYMM(created_at)"
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "delete_verified_at" {
+ type = "DateTime"
+ }
+ column "created_by_id" {
+ type = "UInt64"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/asyncdeletion"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "asyncdeletion_join" {
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "delete_verified_at" {
+ type = "DateTime"
+ }
+ column "created_by_id" {
+ type = "UInt64"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "key"]
+ }
+ }
+
+ table "billing_usage_records" {
+ column "schema_version" {
+ type = "UInt8"
+ }
+ column "record_id" {
+ type = "String"
+ }
+ column "producer_id" {
+ type = "LowCardinality(String)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "organization_id" {
+ type = "UUID"
+ }
+ column "usage_key" {
+ type = "LowCardinality(String)"
+ }
+ column "unit" {
+ type = "LowCardinality(String)"
+ }
+ column "quantity" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_billing_usage_records"
+ sharding_key = "cityHash64(team_id)"
+ }
+ }
+
+ table "channel_definition" {
+ order_by = ["domain", "kind"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "domain" {
+ type = "String"
+ }
+ column "kind" {
+ type = "String"
+ }
+ column "domain_type" {
+ type = "Nullable(String)"
+ }
+ column "type_if_paid" {
+ type = "Nullable(String)"
+ }
+ column "type_if_organic" {
+ type = "Nullable(String)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.channel_definition"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "clickhouse_cleanup_deleted_persons" {
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "max_version" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_orphaned_distinct_ids" {
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "own_tombstone" {
+ type = "UInt8"
+ }
+ column "max_version" {
+ type = "Int64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_distinct_ids" {
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_persons" {
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "cohort_membership" {
+ order_by = ["team_id", "cohort_id", "person_id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "status" {
+ type = "Enum8('entered'=1, 'left'=2)"
+ }
+ column "last_updated" {
+ type = "DateTime64(6)"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/posthog.cohort_membership"
+ replica_name = "{replica}-{shard}"
+ version_column = "last_updated"
+ }
+ }
+
+ table "cohortpeople" {
+ order_by = ["team_id", "cohort_id", "person_id"]
+ partition_by = "team_id % 16"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "sign" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.cohortpeople_new_partitioned"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "conversion_goal_attributed_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "conversion_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "conversion_value" {
+ type = "Float64"
+ }
+ column "touchpoint_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "touchpoint_weight" {
+ type = "Float64"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "medium_name" {
+ type = "String"
+ }
+ column "content_name" {
+ type = "String"
+ }
+ column "term_name" {
+ type = "String"
+ }
+ column "referring_domain_name" {
+ type = "String"
+ }
+ column "gclid_name" {
+ type = "String"
+ }
+ column "fbclid_name" {
+ type = "String"
+ }
+ column "gad_source_name" {
+ type = "String"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_conversion_goal_attributed_preaggregated"
+ sharding_key = "cityHash64(person_id)"
+ }
+ }
+
+ table "distinct_id_usage" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "minute" {
+ type = "DateTime"
+ }
+ column "event_count" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_distinct_id_usage"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_events_recent" {
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ column "_timestamp_ms" {
+ type = "DateTime64(3)"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_person" {
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_person"
+ sharding_key = "sipHash64(id)"
+ }
+ }
+
+ table "distributed_person_distinct_id" {
+ column "id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_person_distinct_id"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings_text_embedding_3_large_3072" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings_text_embedding_3_small_1536" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_system_processes" {
+ settings = {
+ skip_unavailable_shards = "1"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "user" {
+ type = "String"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "address" {
+ type = "IPv6"
+ }
+ column "port" {
+ type = "UInt16"
+ }
+ column "initial_user" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "initial_address" {
+ type = "IPv6"
+ }
+ column "initial_port" {
+ type = "UInt16"
+ }
+ column "interface" {
+ type = "UInt8"
+ }
+ column "os_user" {
+ type = "String"
+ }
+ column "client_hostname" {
+ type = "String"
+ }
+ column "client_name" {
+ type = "String"
+ }
+ column "client_revision" {
+ type = "UInt64"
+ }
+ column "client_version_major" {
+ type = "UInt64"
+ }
+ column "client_version_minor" {
+ type = "UInt64"
+ }
+ column "client_version_patch" {
+ type = "UInt64"
+ }
+ column "http_method" {
+ type = "UInt8"
+ }
+ column "http_user_agent" {
+ type = "String"
+ }
+ column "http_referer" {
+ type = "String"
+ }
+ column "forwarded_for" {
+ type = "String"
+ }
+ column "quota_key" {
+ type = "String"
+ }
+ column "distributed_depth" {
+ type = "UInt64"
+ }
+ column "elapsed" {
+ type = "Float64"
+ }
+ column "is_cancelled" {
+ type = "UInt8"
+ }
+ column "is_all_data_sent" {
+ type = "UInt8"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "total_rows_approx" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "Int64"
+ }
+ column "peak_memory_usage" {
+ type = "Int64"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "query_kind" {
+ type = "String"
+ }
+ column "thread_ids" {
+ type = "Array(UInt64)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "Settings" {
+ type = "Map(String, String)"
+ }
+ column "current_database" {
+ type = "String"
+ }
+ column "ProfileEvents.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(ProfileEvents)"
+ }
+ column "ProfileEvents.Values" {
+ type = "Array(UInt64)"
+ alias = "mapValues(ProfileEvents)"
+ }
+ column "Settings.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(Settings)"
+ }
+ column "Settings.Values" {
+ type = "Array(String)"
+ alias = "mapValues(Settings)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "system"
+ remote_table = "processes"
+ }
+ }
+
+ table "duplicate_events" {
+ order_by = ["team_id", "distinct_id", "event", "inserted_at"]
+ partition_by = "toYYYYMMDD(inserted_at)"
+ ttl = "inserted_at + toIntervalDay(7)"
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "source_uuid" {
+ type = "UUID"
+ }
+ column "duplicate_uuid" {
+ type = "UUID"
+ }
+ column "similarity_score" {
+ type = "Float64"
+ }
+ column "dedup_type" {
+ type = "LowCardinality(String)"
+ }
+ column "is_confirmed" {
+ type = "UInt8"
+ }
+ column "reason" {
+ type = "Nullable(String)"
+ }
+ column "version" {
+ type = "String"
+ }
+ column "different_property_count" {
+ type = "UInt32"
+ }
+ column "properties_similarity" {
+ type = "Float64"
+ }
+ column "source_message" {
+ type = "String"
+ }
+ column "duplicate_message" {
+ type = "String"
+ }
+ column "distinct_fields" {
+ type = "Array(Tuple(field_name String, original_value String, new_value String))"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_duplicate_events" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.duplicate_events"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "error_tracking_fingerprint_issue_state" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "fingerprint" {
+ type = "String"
+ }
+ column "issue_id" {
+ type = "UUID"
+ }
+ column "issue_name" {
+ type = "Nullable(String)"
+ }
+ column "issue_description" {
+ type = "Nullable(String)"
+ }
+ column "issue_status" {
+ type = "String"
+ }
+ column "issue_severity" {
+ type = "Nullable(String)"
+ }
+ column "assigned_user_id" {
+ type = "Nullable(Int64)"
+ }
+ column "assigned_role_id" {
+ type = "Nullable(UUID)"
+ }
+ column "first_seen" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "raw_error_tracking_fingerprint_issue_state"
+ }
+ }
+
+ table "error_tracking_issue_fingerprint_overrides" {
+ order_by = ["team_id", "fingerprint"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "fingerprint" {
+ type = "String"
+ }
+ column "issue_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_error_tracking_issue_fingerprint_overrides" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.error_tracking_issue_fingerprint_overrides"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "events" {
+ 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 "elements_hash" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "elements_chain" {
+ type = "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 "group_0" {
+ type = "String"
+ alias = "`$group_0`"
+ }
+ column "group_1" {
+ type = "String"
+ alias = "`$group_1`"
+ }
+ column "group_2" {
+ type = "String"
+ alias = "`$group_2`"
+ }
+ column "group_3" {
+ type = "String"
+ alias = "`$group_3`"
+ }
+ column "group_4" {
+ type = "String"
+ alias = "`$group_4`"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ column "person_created_at" {
+ type = "DateTime64(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 "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"
+ 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_feature_flags" {
+ type = "Map(String, String)"
+ }
+ column "is_deleted" {
+ type = "Bool"
+ }
+ column "person_properties_map_custom" {
+ type = "Map(String, String)"
+ }
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_trace_id"
+ }
+ 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)"
+ comment = "column_materializer::properties::historical_migration"
+ }
+ 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)"
+ }
+ 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)"
+ 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_dead_letter_queue" {
+ order_by = ["id", "event_uuid", "distinct_id", "team_id"]
+ ttl = "toDate(_timestamp) + toIntervalWeek(4)"
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "ip" {
+ type = "String"
+ }
+ column "site_url" {
+ type = "String"
+ }
+ column "now" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "raw_payload" {
+ type = "String"
+ }
+ column "error_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "error_location" {
+ type = "String"
+ }
+ column "error" {
+ type = "String"
+ }
+ column "tags" {
+ type = "Array(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ index "kafka_timestamp_minmax_events_dead_letter_queue" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.new_events_dead_letter_queue_2"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "events_recent" {
+ 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 "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"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "exchange_rate" {
+ order_by = ["date", "currency"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "currency" {
+ type = "String"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "rate" {
+ type = "Decimal(18, 10)"
+ }
+ column "version" {
+ type = "UInt32"
+ default = "toUnixTimestamp(now())"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.exchange_rate"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "experiment_exposures_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "entity_id" {
+ type = "String"
+ }
+ column "variant" {
+ type = "String"
+ }
+ column "first_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "last_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "exposure_event_uuid" {
+ type = "UUID"
+ }
+ column "exposure_session_id" {
+ type = "String"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_experiment_exposures_preaggregated"
+ sharding_key = "cityHash64(entity_id)"
+ }
+ }
+
+ table "experiment_metric_events_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "entity_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "numeric_value" {
+ type = "Float64"
+ default = "0"
+ }
+ column "steps" {
+ type = "Array(UInt8)"
+ default = "[]"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_experiment_metric_events_preaggregated"
+ sharding_key = "cityHash64(entity_id)"
+ }
+ }
+
+ table "flag_evaluations" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "LowCardinality(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 "person_id" {
+ type = "UUID"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "timestamp"
+ }
+ 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 "flag_key" {
+ type = "String"
+ comment = "column_materializer::properties::$feature_flag"
+ }
+ column "response" {
+ type = "LowCardinality(String)"
+ comment = "column_materializer::properties::$feature_flag_response"
+ }
+ column "session_id" {
+ type = "String"
+ comment = "column_materializer::properties::$session_id"
+ }
+ column "request_id" {
+ type = "String"
+ comment = "column_materializer::properties::$feature_flag_request_id"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_flag_evaluations"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "groups" {
+ order_by = ["team_id", "group_type_index", "group_key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "group_type_index" {
+ type = "UInt8"
+ }
+ column "group_key" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "group_properties" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "Bool"
+ }
+ index "is_deleted_idx" {
+ expr = "is_deleted"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.groups"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "heatmaps" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "x" {
+ type = "Int16"
+ }
+ column "y" {
+ type = "Int16"
+ }
+ column "scale_factor" {
+ type = "Int16"
+ }
+ column "viewport_width" {
+ type = "Int16"
+ }
+ column "viewport_height" {
+ type = "Int16"
+ }
+ column "pointer_target_fixed" {
+ type = "Bool"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_heatmaps"
+ sharding_key = "cityHash64(concat(toString(team_id), '-', session_id, '-', toString(toDate(timestamp))))"
+ }
+ }
+
+ table "hog_invocation_results" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "function_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "function_id" {
+ type = "String"
+ }
+ column "invocation_id" {
+ type = "String"
+ }
+ column "parent_run_id" {
+ type = "String"
+ }
+ column "status" {
+ type = "LowCardinality(String)"
+ }
+ column "attempts" {
+ type = "UInt8"
+ }
+ column "is_retry" {
+ type = "UInt8"
+ }
+ column "scheduled_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "first_scheduled_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "started_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ }
+ column "finished_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ }
+ column "duration_ms" {
+ type = "Nullable(UInt32)"
+ }
+ column "error_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "error_message" {
+ type = "String"
+ }
+ column "event_uuid" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "String"
+ }
+ column "invocation_globals" {
+ type = "String"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "hog_invocation_results_data"
+ }
+ }
+
+ table "ingestion_warnings" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_ingestion_warnings"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "ingestion_warnings_v2_distributed" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "details" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "category" {
+ type = "LowCardinality(String)"
+ default = "coalesce(nullIf(JSONExtractString(details, 'category'), ''), 'unknown')"
+ }
+ column "severity" {
+ type = "LowCardinality(String)"
+ default = "coalesce(nullIf(JSONExtractString(details, 'severity'), ''), 'warning')"
+ }
+ column "pipeline_step" {
+ type = "LowCardinality(String)"
+ default = "coalesce(nullIf(JSONExtractString(details, 'pipelineStep'), ''), 'unknown')"
+ }
+ column "event_uuid" {
+ type = "Nullable(UUID)"
+ default = "toUUIDOrNull(JSONExtractString(details, 'eventUuid'))"
+ }
+ column "distinct_id" {
+ type = "Nullable(String)"
+ default = "nullIf(JSONExtractString(details, 'distinctId'), '')"
+ }
+ column "group_key" {
+ type = "Nullable(String)"
+ default = "nullIf(JSONExtractString(details, 'groupKey'), '')"
+ }
+ column "person_id" {
+ type = "Nullable(UUID)"
+ default = "toUUIDOrNull(JSONExtractString(details, 'personId'))"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "ingestion_warnings_v2"
+ }
+ }
+
+ table "llma_metrics_daily" {
+ order_by = ["team_id", "date", "metric_name"]
+ partition_by = "toYYYYMM(date)"
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "String"
+ }
+ column "metric_value" {
+ type = "Float64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.llma_metrics_daily"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "log_entries" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_log_entries"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "log_entries_distributed" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
+ table "marketing_conversions_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "conversion_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "conversion_math_value" {
+ type = "Float64"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "medium_name" {
+ type = "String"
+ }
+ column "content_name" {
+ type = "String"
+ }
+ column "term_name" {
+ type = "String"
+ }
+ column "referring_domain_name" {
+ type = "String"
+ }
+ column "gclid_name" {
+ type = "String"
+ }
+ column "fbclid_name" {
+ type = "String"
+ }
+ column "gad_source_name" {
+ type = "String"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_marketing_conversions_preaggregated"
+ sharding_key = "cityHash64(person_id)"
+ }
+ }
+
+ table "marketing_costs_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "source_id" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "grain" {
+ type = "LowCardinality(String)"
+ }
+ column "match_key" {
+ type = "String"
+ }
+ column "campaign_id" {
+ type = "String"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "ad_group_id" {
+ type = "String"
+ }
+ column "ad_group_name" {
+ type = "String"
+ }
+ column "ad_id" {
+ type = "String"
+ }
+ column "ad_name" {
+ type = "String"
+ }
+ column "cost_date" {
+ type = "Date"
+ }
+ column "cost" {
+ type = "Float64"
+ }
+ column "clicks" {
+ type = "Float64"
+ }
+ column "impressions" {
+ type = "Float64"
+ }
+ column "reported_conversions" {
+ type = "Float64"
+ }
+ column "reported_conversion_value" {
+ type = "Float64"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_marketing_costs_preaggregated"
+ sharding_key = "cityHash64(source_name, campaign_id)"
+ }
+ }
+
+ table "marketing_touchpoints_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "touchpoint_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "campaign_name" {
+ type = "String"
+ }
+ column "source_name" {
+ type = "String"
+ }
+ column "medium_name" {
+ type = "String"
+ }
+ column "content_name" {
+ type = "String"
+ }
+ column "term_name" {
+ type = "String"
+ }
+ column "referring_domain_name" {
+ type = "String"
+ }
+ column "gclid_name" {
+ type = "String"
+ }
+ column "fbclid_name" {
+ type = "String"
+ }
+ column "gad_source_name" {
+ type = "String"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_marketing_touchpoints_preaggregated"
+ sharding_key = "cityHash64(person_id)"
+ }
+ }
+
+ table "message_assets" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "function_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "function_id" {
+ type = "String"
+ }
+ column "parent_run_id" {
+ type = "String"
+ }
+ column "invocation_id" {
+ type = "String"
+ }
+ column "action_id" {
+ type = "String"
+ }
+ column "kind" {
+ type = "LowCardinality(String)"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "String"
+ }
+ column "recipient" {
+ type = "String"
+ }
+ column "subject" {
+ type = "String"
+ }
+ column "status" {
+ type = "LowCardinality(String)"
+ }
+ column "sent_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ column "html" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "message_assets_data"
+ }
+ }
+
+ table "new_raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "new_sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "new_writable_sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "pending_person_deletes_reporting" {
+ order_by = ["team_id", "deletion_type", "key"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "Nullable(String)"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "delete_verified_at" {
+ type = "Nullable(DateTime)"
+ }
+ column "created_by_id" {
+ type = "Nullable(String)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/pending_person_deletes_reporting"
+ replica_name = "{shard}-{replica}"
+ }
+ }
+
+ table "performance_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_performance_events"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "person" {
+ order_by = ["team_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ default = "0"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt32"
+ }
+ column "last_seen_at" {
+ type = "Nullable(DateTime64(3))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/am0005_20220623103132_noshard/posthog.person"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_collapsing" {
+ order_by = ["team_id", "id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_sign" {
+ type = "Int8"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/noshard/posthog.person_collapsing"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "person_distinct_id" {
+ order_by = ["team_id", "distinct_id", "person_id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "distinct_id" {
+ type = "String"
+ comment = "skip_0003_fill_person_distinct_id2"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_sign" {
+ type = "Int8"
+ default = "1"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ alias = "if(_sign = -1, 1, 0)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id-swap2-2021-08-18"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "person_distinct_id2" {
+ order_by = ["team_id", "distinct_id"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ default = "1"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id2"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_distinct_id_overrides" {
+ order_by = ["team_id", "distinct_id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_person_distinct_id_overrides" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id_overrides"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_distinct_id_overrides_join_table" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "distinct_id"]
+ }
+ }
+
+ table "person_distinct_id_overrides_to_delete" {
+ order_by = ["team_id", "distinct_id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id_overrides_to_delete"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_distinct_id_overrides_to_delete_join" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "distinct_id"]
+ }
+ }
+
+ table "person_overrides" {
+ order_by = ["team_id", "old_person_id"]
+ partition_by = "toYYYYMM(oldest_event)"
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int32"
+ }
+ column "old_person_id" {
+ type = "UUID"
+ }
+ column "override_person_id" {
+ type = "UUID"
+ }
+ column "merged_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "oldest_event" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "version" {
+ type = "Int32"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_overrides"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_overrides_join_table" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "distinct_id"]
+ }
+ }
+
+ table "person_overrides_to_delete" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "partitions" {
+ type = "Array(String)"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "distinct_id"]
+ }
+ }
+
+ table "person_static_cohort" {
+ order_by = ["team_id", "cohort_id", "person_id", "id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/noshard/person_static_cohort"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "pg_embeddings" {
+ order_by = ["team_id", "domain", "id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "512"
+ }
+ column "domain" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "id" {
+ type = "String"
+ }
+ column "vector" {
+ type = "Array(Float32)"
+ }
+ column "text" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.pg_embeddings"
+ replica_name = "{replica}-{shard}"
+ version_column = "timestamp"
+ is_deleted_column = "is_deleted"
+ }
+ }
+
+ table "plugin_log_entries" {
+ order_by = ["team_id", "plugin_id", "plugin_config_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalWeek(1)"
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "plugin_id" {
+ type = "Int64"
+ }
+ column "plugin_config_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "UUID"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.plugin_log_entries"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "preaggregation_results" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "uniq_exact_state" {
+ type = "AggregateFunction(uniqExact, UUID)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_preaggregation_results"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "property_definitions" {
+ order_by = ["team_id", "type", "coalesce(event, '')", "name", "coalesce(group_type_index, 255)"]
+ settings = {
+ always_fetch_merged_part = "0"
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ replicated_can_become_leader = "1"
+ }
+ column "team_id" {
+ type = "UInt32"
+ }
+ column "project_id" {
+ type = "Nullable(UInt32)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "property_type" {
+ type = "Nullable(String)"
+ }
+ column "event" {
+ type = "Nullable(String)"
+ }
+ column "group_type_index" {
+ type = "Nullable(UInt8)"
+ }
+ column "type" {
+ type = "UInt8"
+ default = "1"
+ }
+ column "last_seen_at" {
+ type = "DateTime"
+ }
+ column "version" {
+ type = "UInt64"
+ materialized = "bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.property_definitions"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "property_values_distributed" {
+ column "team_id" {
+ type = "Int64"
+ codec = "DoubleDelta, ZSTD(1)"
+ }
+ column "property_type" {
+ type = "LowCardinality(String)"
+ }
+ column "property_key" {
+ type = "LowCardinality(String)"
+ }
+ column "property_value" {
+ type = "String"
+ }
+ column "property_count" {
+ type = "SimpleAggregateFunction(sum, UInt64)"
+ }
+ column "last_seen" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ default = "now()"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "property_values"
+ }
+ }
+
+ table "query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['RealTimeMicroseconds']"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['OSCPUVirtualTimeMicroseconds']"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ alias = "ProfileEvents['S3Clients']"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3DeleteObjects']"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CopyObject']"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3ListObjects']"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3HeadObject']"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObjectAttributes']"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CreateMultipartUpload']"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPartCopy']"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPart']"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3AbortMultipartUpload']"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CompleteMultipartUpload']"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3PutObject']"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObject']"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['ReadBufferFromS3Bytes']"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['WriteBufferFromS3Bytes']"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workflow"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.kind"
+ }
+ column "lc_id" {
+ type = "String"
+ alias = "CAST(log_comment.id, 'String')"
+ }
+ column "lc_route_id" {
+ type = "String"
+ alias = "CAST(log_comment.route_id, 'String')"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.access_method"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_label, 'String')"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_mask, 'String')"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.query_type"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.product"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ alias = "log_comment.chargeable"
+ }
+ column "lc_name" {
+ type = "String"
+ alias = "CAST(log_comment.name, 'String')"
+ }
+ column "lc_request_name" {
+ type = "String"
+ alias = "CAST(log_comment.request_name, 'String')"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ alias = "CAST(log_comment.client_query_id, 'String')"
+ }
+ column "lc_org_id" {
+ type = "String"
+ alias = "CAST(log_comment.org_id, 'String')"
+ }
+ column "lc_user_id" {
+ type = "Int64"
+ alias = "log_comment.user_id"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ alias = "log_comment.is_impersonated"
+ }
+ column "lc_session_id" {
+ type = "String"
+ alias = "CAST(log_comment.session_id, 'String')"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ alias = "log_comment.dashboard_id"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ alias = "log_comment.insight_id"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ alias = "log_comment.cohort_id"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ alias = "CAST(log_comment.batch_export_id, 'String')"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ alias = "log_comment.experiment_id"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ alias = "CAST(log_comment.experiment_feature_flag_key, 'String')"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ alias = "CAST(log_comment.alert_config_id, 'String')"
+ }
+ column "lc_feature" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.feature"
+ }
+ column "lc_table_id" {
+ type = "String"
+ alias = "CAST(log_comment.table_id, 'String')"
+ }
+ column "lc_warehouse_query" {
+ type = "Bool"
+ alias = "log_comment.warehouse_query"
+ }
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.person_on_events_mode"
+ }
+ column "lc_service_name" {
+ type = "String"
+ alias = "CAST(log_comment.service_name, 'String')"
+ }
+ column "lc_workload" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workload"
+ }
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
+ alias = "if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind'))"
+ }
+ column "lc_query__query" {
+ type = "String"
+ alias = "multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query'))"
+ }
+ column "lc_query" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), '')"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_namespace`, 'String')"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_type`, 'String')"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_id`, 'String')"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_run_id`, 'String')"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_type`, 'String')"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_id`, 'String')"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ alias = "log_comment.`temporal.attempt`"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.job_name`, 'String')"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.run_id`, 'String')"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.tags.owner`, 'String')"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_query_log_archive"
+ }
+ }
+
+ table "raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "raw_sessions_v3" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "session_recording_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "has_full_snapshot" {
+ type = "Int8"
+ comment = "column_materializer::has_full_snapshot"
+ }
+ column "events_summary" {
+ type = "Array(String)"
+ comment = "column_materializer::events_summary"
+ }
+ column "click_count" {
+ type = "Int8"
+ comment = "column_materializer::click_count"
+ }
+ column "keypress_count" {
+ type = "Int8"
+ comment = "column_materializer::keypress_count"
+ }
+ column "timestamps_summary" {
+ type = "Array(DateTime64(6, 'UTC'))"
+ comment = "column_materializer::timestamps_summary"
+ }
+ column "first_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::first_event_timestamp"
+ }
+ column "last_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::last_event_timestamp"
+ }
+ column "urls" {
+ type = "Array(String)"
+ comment = "column_materializer::urls"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_recording_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "session_replay_embeddings" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_embeddings"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "session_replay_events" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "session_replay_features" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_position_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_sum_x" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_sum_x_squared" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_sum_y" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_sum_y_squared" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_distance_traveled" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_direction_change_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_velocity_sum" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_velocity_sum_of_squares" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "mouse_velocity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "scroll_event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "total_scroll_magnitude" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "scroll_direction_reversal_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "rapid_scroll_reversal_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "scroll_to_top_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "rage_click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "dead_click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "backspace_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "inter_action_gap_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "inter_action_gap_sum_ms" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "inter_action_gap_sum_of_squares_ms" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "max_idle_gap_ms" {
+ type = "SimpleAggregateFunction(max, Float64)"
+ }
+ column "long_idle_gap_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "quick_back_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "page_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "unique_url_count" {
+ type = "AggregateFunction(uniqCombined(12), String)"
+ }
+ column "login_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "signup_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "checkout_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "cart_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "billing_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "settings_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "account_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "error_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "not_found_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "admin_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "dashboard_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "onboarding_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "cancel_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "refund_path_visit_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_after_click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_request_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_failed_request_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_4xx_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_5xx_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "network_request_duration_sum" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "network_request_duration_sum_of_squares" {
+ type = "SimpleAggregateFunction(sum, Float64)"
+ }
+ column "network_request_duration_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mutation_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "viewport_resize_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "touch_event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "max_scroll_y" {
+ type = "SimpleAggregateFunction(max, Float64)"
+ }
+ column "unique_click_target_count" {
+ type = "AggregateFunction(uniqCombined(12), Int64)"
+ }
+ column "unique_form_field_count" {
+ type = "AggregateFunction(uniqCombined(12), Int64)"
+ }
+ column "text_selection_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "selection_copy_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_features"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "sharded_app_metrics2" {
+ order_by = ["team_id", "app_source", "app_source_id", "instance_id", "toStartOfHour(timestamp)", "metric_kind", "metric_name"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "app_source" {
+ type = "LowCardinality(String)"
+ }
+ column "app_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "metric_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{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"
+ max_avg_part_size_for_too_many_parts = "0"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "elements_hash" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "$group_0" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$group_1" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$group_2" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$group_3" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$group_4" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$window_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$session_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "group0_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "group1_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "group2_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "group3_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "group4_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "person_created_at" {
+ type = "DateTime64(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 "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"
+ 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 "elements_chain_ids" {
+ type = "Array(String)"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
+ }
+ 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'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
+ codec = "Default"
+ }
+ column "properties_group_feature_flags" {
+ type = "Map(String, String)"
+ materialized = "mapSort(mapFilter((key, _) -> (key LIKE '$feature/%'), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
+ codec = "Default"
+ }
+ 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 = "Default"
+ }
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
+ }
+ column "$session_id_uuid" {
+ type = "Nullable(UInt128)"
+ materialized = "toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)'))"
+ }
+ column "consumer_breadcrumbs" {
+ type = "Array(String)"
+ }
+ column "properties_map_ephemeral" {
+ type = "Map(String, String)"
+ }
+ column "person_properties_map_ephemeral" {
+ type = "Map(String, 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 = "Default"
+ }
+ column "mat_historical_migration" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, 'historical_migration', '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 "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)"
+ materialized = "JSONExtract(properties, '$ai_prompt_name', 'Nullable(String)')"
+ }
+ column "mat_$ai_experiment_id" {
+ type = "Nullable(String)"
+ materialized = "JSONExtract(properties, '$ai_experiment_id', 'Nullable(String)')"
+ }
+ index "kafka_timestamp_minmax_sharded_events" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ 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_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 "minmax_mat_$ai_trace_id" {
+ expr = "`mat_$ai_trace_id`"
+ type = "minmax"
+ 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
+ }
+ index "bloom_filter_$session_id" {
+ expr = "nullIf(nullIf(`$session_id`, ''), 'null')"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard3/{shard}/posthog.sharded_events"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_experiment_exposures_preaggregated" {
+ order_by = ["team_id", "job_id", "entity_id", "breakdown_value"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "expires_at"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "entity_id" {
+ type = "String"
+ }
+ column "variant" {
+ type = "String"
+ }
+ column "first_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "last_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "exposure_event_uuid" {
+ type = "UUID"
+ }
+ column "exposure_session_id" {
+ type = "String"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.experiment_exposures_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_flag_evaluations" {
+ order_by = ["team_id", "flag_key", "toDate(timestamp)", "cityHash64(distinct_id)"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "LowCardinality(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 "person_id" {
+ type = "UUID"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "timestamp"
+ }
+ column "$group_0" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_0"
+ }
+ column "$group_1" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_1"
+ }
+ column "$group_2" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_2"
+ }
+ column "$group_3" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_3"
+ }
+ column "$group_4" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_4"
+ }
+ column "flag_key" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag"
+ }
+ column "response" {
+ type = "LowCardinality(String)"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag_response"
+ }
+ column "session_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$session_id"
+ }
+ column "request_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_request_id'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag_request_id"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "distinct_id_idx" {
+ expr = "distinct_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "person_id_idx" {
+ expr = "person_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "session_id_idx" {
+ expr = "session_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "request_id_idx" {
+ expr = "request_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "inserted_at_idx" {
+ expr = "inserted_at"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.flag_evaluations"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_heatmaps" {
+ order_by = ["type", "team_id", "toDate(timestamp)", "current_url", "viewport_width"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "x" {
+ type = "Int16"
+ }
+ column "y" {
+ type = "Int16"
+ }
+ column "scale_factor" {
+ type = "Int16"
+ }
+ column "viewport_width" {
+ type = "Int16"
+ }
+ column "viewport_height" {
+ type = "Int16"
+ }
+ column "pointer_target_fixed" {
+ type = "Bool"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.heatmaps"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_log_entries" {
+ order_by = ["team_id", "log_source", "log_source_id", "instance_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_log_entries"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_performance_events" {
+ order_by = ["team_id", "toDate(timestamp)", "session_id", "pageview_id", "timestamp"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalWeek(3)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.performance_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_person" {
+ order_by = ["team_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_person"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_person_distinct_id" {
+ order_by = ["team_id", "distinct_id", "person_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_person_distinct_id"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_buffer" {
+ order_by = ["inserted_at", "model_name", "cityHash64(document_id)"]
+ partition_by = "toDate(inserted_at)"
+ ttl = "inserted_at + toIntervalDay(1)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_posthog_document_embeddings_buffer"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_text_embedding_3_large_3072" {
+ order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "rendering", "cityHash64(document_id)"]
+ partition_by = "toMonday(timestamp)"
+ ttl = "timestamp + toIntervalMonth(3)"
+ settings = {
+ index_granularity = "512"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_large_3072" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ index "embedding_idx_l2" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'L2Distance', 3072)"
+ granularity = 100000000
+ }
+ index "embedding_idx_cosine" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'cosineDistance', 3072)"
+ granularity = 100000000
+ }
+ constraint "embedding_dimension_check" {
+ check = "length(embedding) = 3072"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_text_embedding_3_small_1536" {
+ order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "rendering", "cityHash64(document_id)"]
+ partition_by = "toMonday(timestamp)"
+ ttl = "timestamp + toIntervalMonth(3)"
+ settings = {
+ index_granularity = "512"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_small_1536" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ index "embedding_idx_l2" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'L2Distance', 1536)"
+ granularity = 100000000
+ }
+ index "embedding_idx_cosine" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'cosineDistance', 1536)"
+ granularity = 100000000
+ }
+ constraint "embedding_dimension_check" {
+ check = "length(embedding) = 1536"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_preaggregation_results" {
+ order_by = ["team_id", "job_id", "time_window_start", "breakdown_value"]
+ partition_by = "toYYYYMM(time_window_start)"
+ ttl = "expires_at"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "uniq_exact_state" {
+ type = "AggregateFunction(uniqExact, UUID)"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.preaggregation_results"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_raw_sessions_v3" {
+ order_by = ["team_id", "session_timestamp", "session_id_v7"]
+ partition_by = "toYYYYMM(session_timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ default = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ index "event_names_bloom_filter" {
+ expr = "event_names"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ index "flag_keys_bloom_filter" {
+ expr = "flag_keys"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.raw_sessions_v3"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_session_replay_embeddings" {
+ order_by = ["toDate(generation_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(generation_timestamp)"
+ ttl = "toDate(generation_timestamp) + toIntervalYear(1)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.session_replay_embeddings"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_session_replay_events" {
+ order_by = ["toDate(min_first_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(min_first_timestamp)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.session_replay_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "swap_person_distinct_id" {
+ order_by = ["team_id", "distinct_id", "person_id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_sign" {
+ type = "Int8"
+ default = "1"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ alias = "if(_sign = -1, 1, 0)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/noshard/posthog.person_distinct_id_"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "tophog" {
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "metric" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ default = "'sum'"
+ }
+ column "key" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "0"
+ }
+ column "pipeline" {
+ type = "LowCardinality(String)"
+ }
+ column "lane" {
+ type = "LowCardinality(String)"
+ }
+ column "labels" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_tophog"
+ sharding_key = "cityHash64(toString(key))"
+ }
+ }
+
+ table "usage_report_events_preagg" {
+ column "date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_mode" {
+ type = "LowCardinality(String)"
+ }
+ column "lib" {
+ type = "LowCardinality(String)"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "distinct_events_unique" {
+ type = "AggregateFunction(uniqExact, Tuple(UInt64, UInt64, UInt64))"
+ }
+ column "event_count" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_usage_report_events_preagg"
+ sharding_key = "sipHash64(date)"
+ }
+ }
+
+ table "web_bot_definition" {
+ column "id" {
+ type = "UInt64"
+ }
+ column "parent_id" {
+ type = "UInt64"
+ }
+ column "regexp" {
+ type = "String"
+ }
+ column "keys" {
+ type = "Array(String)"
+ }
+ column "values" {
+ type = "Array(String)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_bot_definition"
+ sharding_key = "sipHash64(id)"
+ }
+ }
+
+ table "web_bounces_daily_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_bounces_daily"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_bounces_dimensional_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_bounces_dimensional_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_bounces_hourly_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_bounces_hourly"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_goals_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "action_id" {
+ type = "Int64"
+ }
+ column "count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "unique_persons_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_goals_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_overview_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "uniq_sessions_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_duration_state" {
+ type = "AggregateFunction(avg, Float64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_overview_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_pre_aggregated_bounces" {
+ order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "web_pre_aggregated_stats" {
+ order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "web_pre_aggregated_teams" {
+ order_by = ["team_id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "enabled_by" {
+ type = "String"
+ default = "'system'"
+ }
+ column "version" {
+ type = "UInt32"
+ default = "toUnixTimestamp(now())"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_analytics_team_selection"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "web_stats_daily_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_stats_daily"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_stats_dimensional_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_dimensional_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_stats_frustration_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "sum_rage_clicks_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "sum_dead_clicks_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "sum_errors_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_frustration_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_stats_hourly_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_stats_hourly"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_stats_paths_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Nullable(Float64))"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_paths_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_stats_paths_preaggregated_pathkey" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Nullable(Float64))"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_paths_preaggregated_pathkey"
+ sharding_key = "sipHash64(breakdown_value)"
+ }
+ }
+
+ table "web_stats_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_by" {
+ type = "String"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_vitals_paths_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "path" {
+ type = "String"
+ }
+ column "inp_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "lcp_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "cls_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "fcp_quantiles_state" {
+ type = "AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_vitals_paths_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "writable_events_recent" {
+ 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 "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"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports_writable"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_ingestion_warnings" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_ingestion_warnings"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "writable_posthog_document_embeddings" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_buffer" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_buffer"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_text_embedding_3_large_3072" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_text_embedding_3_small_1536" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "query_log_archive_buffer"
+ }
+ }
+
+ table "writable_raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_raw_sessions_primary" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_raw_sessions_v3" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ 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)"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_session_recording_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_recording_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_session_replay_embeddings" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_embeddings"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "writable_session_replay_events" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog_writable"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog_writable"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "writable_sessions_background" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "writeable_performance_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_performance_events"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ materialized_view "ops_query_log_archive_mv" {
+ to_table = "posthog.writable_query_log_archive"
+ query = <<SQL
+SELECT
+ hostname,
+ user,
+ query_id,
+ initial_query_id,
+ is_initial_query,
+ type,
+ event_date,
+ event_time,
+ event_time_microseconds,
+ query_start_time,
+ query_start_time_microseconds,
+ query_duration_ms,
+ read_rows,
+ read_bytes,
+ written_rows,
+ written_bytes,
+ result_rows,
+ result_bytes,
+ memory_usage,
+ peak_threads_usage,
+ current_database,
+ query,
+ formatted_query,
+ normalized_query_hash,
+ query_kind,
+ exception_code,
+ exception,
+ stack_trace,
+ JSONExtractInt(log_comment, 'team_id') AS team_id,
+ if(isValidJSON(log_comment), log_comment, '{}') AS log_comment,
+ ProfileEvents
+FROM system.query_log
+WHERE type != 'QueryStart'
+SQL
+
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "String"
+ }
+ column "ProfileEvents" {
+ type = "Map(LowCardinality(String), UInt64)"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-large-3072'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-small-1536'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ view "custom_metrics" {
+ query = <<SQL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_test
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_replication_queue
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_server_crash
+UNION ALL
+SELECT *
+FROM posthog.custom_metrics_table_sizes
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_part_counts
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_dictionaries
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_S3DiskBytesUsed' AS name,
+ map('instance', hostname(), 'disk', disk_name) AS labels,
+ toFloat64(sum(bytes_on_disk)) AS value,
+ 'Bytes currently used by ClickHouse parts on S3-backed disks on this node' AS help,
+ 'gauge' AS type
+FROM system.parts
+WHERE disk_name IN ('s3disk', 'cache')
+GROUP BY
+ disk_name
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeFailures15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(count()) AS value,
+ 'Number of failed merge operations in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM system.part_log
+WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+AND
+ (event_type = 'MergeParts')
+AND
+ (error > 0)
+AND
+ (merge_reason != 'NotAMerge')
+AND
+ (error != 40)
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeRetriesMaxPerTable15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(max(cnt)) AS value,
+ 'Max failed merge retries for any single table in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT count() AS cnt
+ FROM system.part_log
+ WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+ AND
+ (event_type = 'MergeParts')
+ AND
+ (error > 0)
+ AND
+ (merge_reason != 'NotAMerge')
+ AND
+ (error != 40)
+ GROUP BY
+ database, `table`, partition_id
+ )
+SQL
+
+ }
+
+ view "custom_metrics_backups" {
+ query = <<SQL
+WITH
+ ['ClickHouseCustomMetric_BackupFailed', 'ClickHouseCustomMetric_BackupSuccess', 'ClickHouseCustomMetric_BackupCancelled', 'ClickHouseCustomMetric_BackupAttempts'] AS names,
+ [toInt64(countIf(status = 'BACKUP_FAILED')), toInt64(countIf(status = 'BACKUP_CREATED')), toInt64(countIf(status = 'BACKUP_CANCELLED')), toInt64(countIf(status = 'CREATING_BACKUP'))] AS `values`,
+ ['Number of failed backups', 'Number of successful backups', 'Number of cancelled backups', 'Number of backup attempts'] AS descriptions,
+ ['gauge', 'gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.backup_log
+WHERE event_date = today()
+GROUP BY
+ event_date
+SQL
+
+ }
+
+ view "custom_metrics_dictionaries" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_DictionariesFailed' AS name,
+ map(
+ 'instance',
+ hostname(),
+ 'database',
+ d.database,
+ 'dictionary',
+ d.dict_name,
+ 'uuid',
+ toString(d.uuid),
+ 'status',
+ toString(d.status)
+ ) AS labels,
+ toUInt64(1) AS value,
+ 'Dictionary is in FAILED or FAILED_AND_RELOADING status' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT name AS dict_name, database, uuid, status
+ FROM system.dictionaries
+ WHERE status IN ('FAILED', 'FAILED_AND_RELOADING')
+ ) AS d
+SQL
+
+ }
+
+ view "custom_metrics_part_counts" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_MaxPartCountPerPartition' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`, 'partition', partition) AS labels,
+ part_count AS value,
+ 'Maximum number of active parts for any partition in a PostHog table' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT database, `table`, partition, count() AS part_count
+ FROM system.parts
+ WHERE
+ active
+ AND
+ (database = 'posthog')
+ GROUP BY
+ database, `table`, partition
+ ORDER BY database ASC, `table` ASC, part_count DESC, partition ASC
+ LIMIT 1 BY database, `table`
+ )
+SQL
+
+ }
+
+ view "custom_metrics_replication_queue" {
+ query = <<SQL
+WITH
+ ['ClickHouseCustomMetric_ReplicationQueueStuckEntries', 'ClickHouseCustomMetric_ReplicationQueueMaxPostponedEntrySeconds', 'ClickHouseCustomMetric_ReplicationQueueMaxErrorEntrySeconds'] AS names,
+ [toInt64(countIf(create_time < (now() - toIntervalDay(15)))), maxIf(dateDiff('seconds', create_time, last_postpone_time), last_postpone_time != '1970-01-01'), maxIf(dateDiff('seconds', create_time, last_exception_time), (last_exception_time != '1970-01-01') AND (last_exception_time > (now() - toIntervalMinute(5))))] AS `values`,
+ ['Number of entries that have been in the replication queue for more than 15 days', 'Maximum number of seconds that an entry has been postponed', 'Maximum number of seconds that an entry has been in error'] AS descriptions,
+ ['gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('table', `table`, 'instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.replication_queue
+GROUP BY
+ `table`
+HAVING
+ value > 0
+SQL
+
+ }
+
+ view "custom_metrics_server_crash" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_ServerCrash' AS name,
+ map('instance', hostname()) AS labels,
+ count() AS value,
+ 'Number of server crashes for current date' AS help,
+ 'gauge' AS type
+FROM system.crash_log
+WHERE event_date = today()
+GROUP BY
+ hostname()
+SQL
+
+ }
+
+ view "custom_metrics_table_sizes" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_TableTotalBytes' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`) AS labels,
+ CAST(total_bytes, 'Float64') AS value,
+ 'Size of a database table on a given node (need a sum for sharded)' AS help,
+ 'gauge' AS type
+FROM system.tables
+WHERE
+ (database NOT IN ('INFORMATION_SCHEMA', 'information_schema'))
+AND
+ (total_bytes IS NOT NULL)
+SQL
+
+ }
+
+ view "custom_metrics_test" {
+ query = <<SQL
+SELECT
+ 'ClickHouseCustomMetric_Test' AS name,
+ map('instance', hostname()) AS labels,
+ 1 AS value,
+ 'Test to check that the metric endpoint is working' AS help,
+ 'gauge' AS type
+SQL
+
+ }
+
+ view "events_batch_export" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ (events.timestamp >= ({interval_start: DateTime64} - toIntervalDay({lookback_days: Int32})))
+AND
+ (events.timestamp < ({interval_end: DateTime64} + toIntervalDay(1)))
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "events_batch_export_recent" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ inserted_at AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events_recent
+PREWHERE
+ (events_recent.inserted_at >= {interval_start: DateTime64}) AND (events_recent.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events_recent.distinct_id), cityHash64(events_recent.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "events_batch_export_unbounded" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "events_with_array_props_view" {
+ query = <<SQL
+SELECT
+ uuid,
+ event,
+ properties,
+ timestamp,
+ team_id,
+ distinct_id,
+ elements_chain,
+ created_at,
+ arrayMap(k -> toString(k.1), JSONExtractKeysAndValuesRaw(properties)) AS array_property_keys,
+ arrayMap(k -> toString(k.2), JSONExtractKeysAndValuesRaw(properties)) AS array_property_values,
+ _timestamp,
+ _offset
+FROM posthog.events
+SQL
+
+ }
+
+ view "persons_batch_export" {
+ query = <<SQL
+WITH
+ new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
+ new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
+ all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
+SELECT
+ p.team_id AS team_id,
+ pd.distinct_id AS distinct_id,
+ toString(p.id) AS person_id,
+ p.properties AS properties,
+ pd.version AS person_distinct_id_version,
+ p.version AS person_version,
+ p.created_at AS created_at,
+ multiIf(
+ ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
+ pd._timestamp,
+ ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
+ p._timestamp,
+ least(p._timestamp, pd._timestamp)
+ ) AS _inserted_at
+FROM
+ posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((id, version) IN (all_new_persons))
+ORDER BY _inserted_at ASC
+SQL
+
+ }
+
+ view "persons_properties_up_to_date_view" {
+ query = <<SQL
+SELECT *
+FROM posthog.persons_properties_view
+WHERE
+ (id, created_at)
+ IN (SELECT id, maxMerge(updated_at) AS latest FROM posthog.persons_up_to_date GROUP BY id)
+SQL
+
+ }
+
+ view "persons_up_to_date_view" {
+ query = <<SQL
+SELECT
+ id,
+ minMerge(created_at_) AS created_at,
+ argMaxMerge(team_id) AS team_id,
+ argMaxMerge(properties) AS properties,
+ argMaxMerge(is_identified) AS is_identified,
+ maxMerge(updated_at) AS updated_at
+FROM posthog.persons_up_to_date
+GROUP BY
+ id
+SQL
+
+ }
+
+ view "posthog_document_embeddings_union_view" {
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-small-1536' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_small_1536
+UNION ALL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-large-3072' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_large_3072
+SQL
+
+ }
+
+ view "raw_sessions_v" {
+ query = <<SQL
+SELECT
+ session_id_v7,
+ fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)) AS session_timestamp,
+ team_id,
+ argMaxMerge(distinct_id) AS distinct_id,
+ 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(initial_browser) AS initial_browser,
+ argMinMerge(initial_browser_version) AS initial_browser_version,
+ argMinMerge(initial_os) AS initial_os,
+ argMinMerge(initial_os_version) AS initial_os_version,
+ argMinMerge(initial_device_type) AS initial_device_type,
+ argMinMerge(initial_viewport_width) AS initial_viewport_width,
+ argMinMerge(initial_viewport_height) AS initial_viewport_height,
+ argMinMerge(initial_geoip_country_code) AS initial_geoip_country_code,
+ argMinMerge(initial_geoip_subdivision_1_code) AS initial_geoip_subdivision_1_code,
+ argMinMerge(initial_geoip_subdivision_1_name) AS initial_geoip_subdivision_1_name,
+ argMinMerge(initial_geoip_subdivision_city_name) AS initial_geoip_subdivision_city_name,
+ argMinMerge(initial_geoip_time_zone) AS initial_geoip_time_zone,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ argMinMerge(initial__kx) AS initial__kx,
+ argMinMerge(initial_irclid) AS initial_irclid,
+ sum(pageview_count) AS pageview_count,
+ uniqMerge(pageview_uniq) AS pageview_uniq,
+ sum(autocapture_count) AS autocapture_count,
+ uniqMerge(autocapture_uniq) AS autocapture_uniq,
+ sum(screen_count) AS screen_count,
+ uniqMerge(screen_uniq) AS screen_uniq,
+ max(maybe_has_session_replay) AS maybe_has_session_replay,
+ uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,
+ argMinMerge(vitals_lcp) AS vitals_lcp
+FROM posthog.raw_sessions
+GROUP BY
+ session_id_v7, team_id
+SQL
+
+ }
+
+ view "raw_sessions_v3_v" {
+ 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" {
+ query = <<SQL
+SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(exit_url) AS exit_url,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ sumMap(event_count_map) AS event_count_map,
+ sum(pageview_count) AS pageview_count,
+ sum(autocapture_count) AS autocapture_count
+FROM posthog.sessions
+GROUP BY
+ session_id, team_id
+SQL
+
+ }
+
+ view "team_events_last_month_view" {
+ query = <<SQL
+SELECT team_id, count() AS event_count
+FROM posthog.events
+WHERE
+ (timestamp > (now() - toIntervalMonth(1)))
+AND
+ (timestamp < now())
+GROUP BY
+ team_id
+ORDER BY event_count DESC
+SQL
+
+ }
+
+ dictionary "channel_definition_dict" {
+ primary_key = ["domain", "kind"]
+ lifetime {
+ min = 3000
+ max = 3600
+ }
+ attribute "domain" {
+ type = "String"
+ }
+ attribute "kind" {
+ type = "String"
+ }
+ attribute "domain_type" {
+ type = "Nullable(String)"
+ }
+ attribute "type_if_paid" {
+ type = "Nullable(String)"
+ }
+ attribute "type_if_organic" {
+ type = "Nullable(String)"
+ }
+ source "clickhouse" {
+ user = "dict_reader"
+ table = "channel_definition"
+ }
+ layout "complex_key_hashed" {
+ }
+ }
+
+ dictionary "web_bot_definition_dict" {
+ primary_key = ["regexp"]
+ lifetime {
+ min = 3000
+ max = 3600
+ }
+ attribute "regexp" {
+ type = "String"
+ }
+ attribute "name" {
+ type = "String"
+ }
+ attribute "category" {
+ type = "String"
+ }
+ attribute "traffic_type" {
+ type = "String"
+ }
+ attribute "operator" {
+ type = "String"
+ }
+ source "clickhouse" {
+ user = "default"
+ db = "posthog"
+ table = "web_bot_definition"
+ }
+ layout "regexp_tree" {
+ }
+ }
+
+ dictionary "web_pre_aggregated_teams_dict" {
+ primary_key = ["team_id"]
+ lifetime {
+ min = 3000
+ max = 3600
+ }
+ attribute "team_id" {
+ type = "UInt64"
+ }
+ source "clickhouse" {
+ user = "dict_reader"
+ query = "SELECT team_id FROM `web_pre_aggregated_teams` FINAL WHERE version > 0"
+ }
+ layout "hashed" {
+ }
+ }
+}
+
+named_collection "msk_cluster" {
+ external = true
+}
+
+named_collection "warpstream_calculated_events" {
+ external = true
+}
+
+named_collection "warpstream_cyclotron" {
+ external = true
+}
+
+named_collection "warpstream_ingestion" {
+ external = true
+}
+
+named_collection "warpstream_logs" {
+ external = true
+}
+
+named_collection "warpstream_metrics" {
+ external = true
+}
+
+named_collection "warpstream_replay" {
+ external = true
+}
+
+named_collection "warpstream_shared" {
+ external = true
+}
+
+named_collection "warpstream_traces" {
+ external = true
+}
diff --git a/posthog/clickhouse/hcl/manifest.hcl b/posthog/clickhouse/hcl/manifest.hcl
index c3715ab7e8cd..54e392c31b76 100644
--- a/posthog/clickhouse/hcl/manifest.hcl
+++ b/posthog/clickhouse/hcl/manifest.hcl
@@ -108,7 +108,10 @@ 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/named_collections", "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/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/local"] }
+ env "dev" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/coshared/log_entries_write", "roles/data/dev"] }
+ env "prod-us" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/data/prod", "roles/data/prod-us"] }
+ env "prod-eu" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/coshared/log_entries_write", "roles/data/prod", "roles/data/prod-eu"] }
+ env "local-multi" { layers = ["roles/shared", "roles/coshared/named_collections", "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/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local"] }
}
# INGESTION satellites: the Kafka consumer layer. Each node carries the kafka_* engine
@@ -133,7 +136,7 @@ role "medium" {
# and not MULTINODE_CLICKHOUSE. Composed as the deduped union of the local-multi stacks it
# hosts, so any name two of those roles declare fails this load instead of drifting.
role "all" {
- env "local-single" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/ops/shared", "roles/ops/local", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/local", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/local", "roles/coshared/aux_data", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local", "roles/coshared/sessions_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/local", "roles/ingestion_events/local", "roles/ingestion_events/local-single", "roles/ingestion_small/local", "roles/ingestion_medium/local"] }
+ env "local-single" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/ops/shared", "roles/ops/local", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/local", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/local", "roles/coshared/aux_data", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local", "roles/coshared/sessions_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local", "roles/ingestion_events/local", "roles/ingestion_events/local-single", "roles/ingestion_small/local", "roles/ingestion_medium/local"] }
}
# role "endpoints" {
diff --git a/posthog/clickhouse/hcl/roles/data/cloud/shared_declarations.hcl b/posthog/clickhouse/hcl/roles/data/cloud/shared_declarations.hcl
new file mode 100644
index 000000000000..da14fae75219
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/data/cloud/shared_declarations.hcl
@@ -0,0 +1,76 @@
+# Objects more than one data layer used to declare. The declaration lives here,
+# in a layer every consumer composes; a cluster whose shape genuinely differs
+# restates it with override = true rather than declaring it a second time.
+database "posthog" {
+ table "session_recording_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "has_full_snapshot" {
+ type = "Int8"
+ comment = "column_materializer::has_full_snapshot"
+ }
+ column "events_summary" {
+ type = "Array(String)"
+ comment = "column_materializer::events_summary"
+ }
+ column "click_count" {
+ type = "Int8"
+ comment = "column_materializer::click_count"
+ }
+ column "keypress_count" {
+ type = "Int8"
+ comment = "column_materializer::keypress_count"
+ }
+ column "timestamps_summary" {
+ type = "Array(DateTime64(6, 'UTC'))"
+ comment = "column_materializer::timestamps_summary"
+ }
+ column "first_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::first_event_timestamp"
+ }
+ column "last_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::last_event_timestamp"
+ }
+ column "urls" {
+ type = "Array(String)"
+ comment = "column_materializer::urls"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_recording_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+}
diff --git a/posthog/clickhouse/hcl/roles/data/cloud/tables.hcl b/posthog/clickhouse/hcl/roles/data/cloud/tables.hcl
new file mode 100644
index 000000000000..c622ac5d9400
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/data/cloud/tables.hcl
@@ -0,0 +1,2183 @@
+# The cloud data clusters: every object here is on dev, prod-us and prod-eu.
+#
+# The patch_table blocks refine objects an earlier layer already declares. Most name
+# a real per-cluster split -- roles/coshared/sessions_data describes the Distributed
+# proxy the sessions nodes read through, while a data node holds the storage table.
+#
+# The materialized columns these tables carry in production are absent by design. The
+# materialization engine adds them per environment and they churn, so
+# posthog-cloud-infra layers them on top of this shape.
+database "posthog" {
+
+ table "async_deletion_run" {
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "deletion_type", "key"]
+ }
+ }
+
+ table "billing_usage_records" {
+ # The local node reads this through the aux cluster; a cloud data node holds
+ # its own copy. One name, two objects.
+ override = true
+ column "schema_version" {
+ type = "UInt8"
+ }
+ column "record_id" {
+ type = "String"
+ }
+ column "producer_id" {
+ type = "LowCardinality(String)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "organization_id" {
+ type = "UUID"
+ }
+ column "usage_key" {
+ type = "LowCardinality(String)"
+ }
+ column "unit" {
+ type = "LowCardinality(String)"
+ }
+ column "quantity" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_billing_usage_records"
+ sharding_key = "cityHash64(team_id)"
+ }
+ }
+
+ table "clickhouse_cleanup_deleted_persons" {
+ override = true
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "max_version" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_orphaned_distinct_ids" {
+ override = true
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "own_tombstone" {
+ type = "UInt8"
+ }
+ column "max_version" {
+ type = "Int64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_distinct_ids" {
+ override = true
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_persons" {
+ override = true
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "cohortpeople" {
+ override = true
+ order_by = ["team_id", "cohort_id", "person_id", "version"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "sign" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.cohortpeople"
+ replica_name = "{replica}-{shard}"
+ sign_column = "sign"
+ }
+ }
+
+ table "distributed_events_recent" {
+ override = true
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ column "_timestamp_ms" {
+ type = "DateTime64(3)"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_system_processes" {
+ override = true
+ settings = {
+ skip_unavailable_shards = "1"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "user" {
+ type = "String"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "address" {
+ type = "IPv6"
+ }
+ column "port" {
+ type = "UInt16"
+ }
+ column "initial_user" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "initial_address" {
+ type = "IPv6"
+ }
+ column "initial_port" {
+ type = "UInt16"
+ }
+ column "interface" {
+ type = "UInt8"
+ }
+ column "os_user" {
+ type = "String"
+ }
+ column "client_hostname" {
+ type = "String"
+ }
+ column "client_name" {
+ type = "String"
+ }
+ column "client_revision" {
+ type = "UInt64"
+ }
+ column "client_version_major" {
+ type = "UInt64"
+ }
+ column "client_version_minor" {
+ type = "UInt64"
+ }
+ column "client_version_patch" {
+ type = "UInt64"
+ }
+ column "http_method" {
+ type = "UInt8"
+ }
+ column "http_user_agent" {
+ type = "String"
+ }
+ column "http_referer" {
+ type = "String"
+ }
+ column "forwarded_for" {
+ type = "String"
+ }
+ column "quota_key" {
+ type = "String"
+ }
+ column "distributed_depth" {
+ type = "UInt64"
+ }
+ column "elapsed" {
+ type = "Float64"
+ }
+ column "is_cancelled" {
+ type = "UInt8"
+ }
+ column "is_all_data_sent" {
+ type = "UInt8"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "total_rows_approx" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "Int64"
+ }
+ column "peak_memory_usage" {
+ type = "Int64"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "query_kind" {
+ type = "String"
+ }
+ column "thread_ids" {
+ type = "Array(UInt64)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "Settings" {
+ type = "Map(String, String)"
+ }
+ column "current_database" {
+ type = "String"
+ }
+ column "ProfileEvents.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(ProfileEvents)"
+ }
+ column "ProfileEvents.Values" {
+ type = "Array(UInt64)"
+ alias = "mapValues(ProfileEvents)"
+ }
+ column "Settings.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(Settings)"
+ }
+ column "Settings.Values" {
+ type = "Array(String)"
+ alias = "mapValues(Settings)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "system"
+ remote_table = "processes"
+ }
+ }
+
+ table "events_dead_letter_queue" {
+ override = true
+ order_by = ["id", "event_uuid", "distinct_id", "team_id"]
+ ttl = "toDate(_timestamp) + toIntervalWeek(4)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "ip" {
+ type = "String"
+ }
+ column "site_url" {
+ type = "String"
+ }
+ column "now" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "raw_payload" {
+ type = "String"
+ }
+ column "error_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "error_location" {
+ type = "String"
+ }
+ column "error" {
+ type = "String"
+ }
+ column "tags" {
+ type = "Array(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.events_dead_letter_queue"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "groups" {
+ override = true
+ order_by = ["team_id", "group_type_index", "group_key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "group_type_index" {
+ type = "UInt8"
+ }
+ column "group_key" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "group_properties" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "Bool"
+ }
+ index "is_deleted_idx" {
+ expr = "is_deleted"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.groups"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "ingestion_warnings" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "details" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_ingestion_warnings"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "person_distinct_id2" {
+ override = true
+ order_by = ["team_id", "distinct_id"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ default = "1"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id2"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_distinct_id_overrides" {
+ override = true
+ order_by = ["team_id", "distinct_id"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_person_distinct_id_overrides" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id_overrides"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_static_cohort" {
+ override = true
+ order_by = ["team_id", "cohort_id", "person_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_static_cohort"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "plugin_log_entries" {
+ override = true
+ order_by = ["team_id", "id"]
+ partition_by = "plugin_id"
+ ttl = "toDate(timestamp) + toIntervalWeek(1)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "plugin_id" {
+ type = "Int64"
+ }
+ column "plugin_config_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "UUID"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.plugin_log_entries"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "property_definitions" {
+ override = true
+ order_by = ["team_id", "type", "coalesce(event, '')", "name", "coalesce(group_type_index, 255)"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt32"
+ }
+ column "project_id" {
+ type = "Nullable(UInt32)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "property_type" {
+ type = "Nullable(String)"
+ }
+ column "event" {
+ type = "Nullable(String)"
+ }
+ column "group_type_index" {
+ type = "Nullable(UInt8)"
+ }
+ column "type" {
+ type = "UInt8"
+ default = "1"
+ }
+ column "last_seen_at" {
+ type = "DateTime"
+ }
+ column "version" {
+ type = "UInt64"
+ materialized = "bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.property_definitions"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "raw_sessions_v3" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "session_replay_events" {
+ override = true
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "sharded_session_replay_events" {
+ override = true
+ order_by = ["toDate(min_first_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(min_first_timestamp)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "tophog" {
+ override = true
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "metric" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ default = "'sum'"
+ }
+ column "key" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "0"
+ }
+ column "pipeline" {
+ type = "LowCardinality(String)"
+ }
+ column "lane" {
+ type = "LowCardinality(String)"
+ }
+ column "labels" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_tophog"
+ sharding_key = "cityHash64(toString(key))"
+ }
+ }
+
+ table "web_pre_aggregated_bounces" {
+ override = true
+ order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "web_pre_aggregated_stats" {
+ override = true
+ order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "web_pre_aggregated_teams" {
+ override = true
+ order_by = ["team_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "enabled_by" {
+ type = "String"
+ default = "'system'"
+ }
+ column "version" {
+ type = "UInt32"
+ default = "toUnixTimestamp(now())"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_analytics_team_selection"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "writable_events_recent" {
+ override = 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 "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"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports_writable"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_raw_sessions" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_raw_sessions_v3" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_session_recording_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_recording_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_sessions" {
+ override = true
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
+ override = true
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-large-3072'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
+ override = true
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-small-1536'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ patch_table "raw_sessions" {
+ drop_columns = ["initial_epik", "initial_qclid", "initial_sccid"]
+ }
+
+ patch_table "sessions" {
+ drop_columns = ["initial_epik", "initial_qclid", "initial_sccid"]
+ }
+
+ patch_table "writable_session_replay_events" {
+ drop_columns = ["ai_highlighted", "ai_tags_fixed", "ai_tags_freeform", "surfacing_score"]
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/data/common/cloud_and_local.hcl b/posthog/clickhouse/hcl/roles/data/common/cloud_and_local.hcl
new file mode 100644
index 000000000000..3d4d21933a72
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/data/common/cloud_and_local.hcl
@@ -0,0 +1,2102 @@
+# Objects both the local data node and every cloud data cluster run, identically.
+# They sit here rather than in roles/data/local so the cloud stacks can compose
+# them: a layer only the local node composes cannot describe a shared table.
+database "posthog" {
+ table "adhoc_events_deletion" {
+ order_by = ["team_id", "uuid"]
+ ttl = "deleted_at + toIntervalMonth(3) WHERE is_deleted = 1"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ column "deleted_at" {
+ type = "DateTime"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ default = "0"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.adhoc_events_deletion"
+ replica_name = "{replica}-{shard}"
+ version_column = "deleted_at"
+ is_deleted_column = "is_deleted"
+ }
+ }
+
+ table "app_metrics2" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "app_source" {
+ type = "LowCardinality(String)"
+ }
+ column "app_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "metric_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_app_metrics2"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "channel_definition" {
+ order_by = ["domain", "kind"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "domain" {
+ type = "String"
+ }
+ column "kind" {
+ type = "String"
+ }
+ column "domain_type" {
+ type = "Nullable(String)"
+ }
+ column "type_if_paid" {
+ type = "Nullable(String)"
+ }
+ column "type_if_organic" {
+ type = "Nullable(String)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.channel_definition"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "cohort_membership" {
+ order_by = ["team_id", "cohort_id", "person_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "cohort_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "status" {
+ type = "Enum8('entered'=1, 'left'=2)"
+ }
+ column "last_updated" {
+ type = "DateTime64(6)"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.cohort_membership"
+ replica_name = "{replica}-{shard}"
+ version_column = "last_updated"
+ }
+ }
+
+ table "distinct_id_usage" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "minute" {
+ type = "DateTime"
+ }
+ column "event_count" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_distinct_id_usage"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings_text_embedding_3_large_3072" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings_text_embedding_3_small_1536" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "duplicate_events" {
+ order_by = ["team_id", "distinct_id", "event", "inserted_at"]
+ partition_by = "toYYYYMMDD(inserted_at)"
+ ttl = "inserted_at + toIntervalDay(7)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "source_uuid" {
+ type = "UUID"
+ }
+ column "duplicate_uuid" {
+ type = "UUID"
+ }
+ column "similarity_score" {
+ type = "Float64"
+ }
+ column "dedup_type" {
+ type = "LowCardinality(String)"
+ }
+ column "is_confirmed" {
+ type = "UInt8"
+ }
+ column "reason" {
+ type = "Nullable(String)"
+ }
+ column "version" {
+ type = "String"
+ }
+ column "different_property_count" {
+ type = "UInt32"
+ }
+ column "properties_similarity" {
+ type = "Float64"
+ }
+ column "source_message" {
+ type = "String"
+ }
+ column "duplicate_message" {
+ type = "String"
+ }
+ column "distinct_fields" {
+ type = "Array(Tuple(field_name String, original_value String, new_value String))"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_duplicate_events" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.duplicate_events"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "error_tracking_issue_fingerprint_overrides" {
+ order_by = ["team_id", "fingerprint"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "fingerprint" {
+ type = "String"
+ }
+ column "issue_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_error_tracking_issue_fingerprint_overrides" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.error_tracking_issue_fingerprint_overrides"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ view "events_batch_export_recent" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ inserted_at AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events_recent
+PREWHERE
+ (events_recent.inserted_at >= {interval_start: DateTime64}) AND (events_recent.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events_recent.distinct_id), cityHash64(events_recent.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ table "exchange_rate" {
+ order_by = ["date", "currency"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "currency" {
+ type = "String"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "rate" {
+ type = "Decimal(18, 10)"
+ }
+ column "version" {
+ type = "UInt32"
+ default = "toUnixTimestamp(now())"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.exchange_rate"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "experiment_exposures_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "entity_id" {
+ type = "String"
+ }
+ column "variant" {
+ type = "String"
+ }
+ column "first_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "last_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "exposure_event_uuid" {
+ type = "UUID"
+ }
+ column "exposure_session_id" {
+ type = "String"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_experiment_exposures_preaggregated"
+ sharding_key = "cityHash64(entity_id)"
+ }
+ }
+
+ table "heatmaps" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "x" {
+ type = "Int16"
+ }
+ column "y" {
+ type = "Int16"
+ }
+ column "scale_factor" {
+ type = "Int16"
+ }
+ column "viewport_width" {
+ type = "Int16"
+ }
+ column "viewport_height" {
+ type = "Int16"
+ }
+ column "pointer_target_fixed" {
+ type = "Bool"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_heatmaps"
+ sharding_key = "cityHash64(concat(toString(team_id), '-', session_id, '-', toString(toDate(timestamp))))"
+ }
+ }
+
+ table "llma_metrics_daily" {
+ order_by = ["team_id", "date", "metric_name"]
+ partition_by = "toYYYYMM(date)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "String"
+ }
+ column "metric_value" {
+ type = "Float64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.llma_metrics_daily"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "log_entries" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_log_entries"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "performance_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_performance_events"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "person_distinct_id" {
+ order_by = ["team_id", "distinct_id", "person_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "distinct_id" {
+ type = "String"
+ comment = "skip_0003_fill_person_distinct_id2"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_sign" {
+ type = "Int8"
+ default = "1"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ alias = "if(_sign = -1, 1, 0)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "person_overrides" {
+ order_by = ["team_id", "old_person_id"]
+ partition_by = "toYYYYMM(oldest_event)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int32"
+ }
+ column "old_person_id" {
+ type = "UUID"
+ }
+ column "override_person_id" {
+ type = "UUID"
+ }
+ column "merged_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "oldest_event" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "version" {
+ type = "Int32"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_overrides"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "pg_embeddings" {
+ order_by = ["team_id", "domain", "id"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "domain" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "id" {
+ type = "String"
+ }
+ column "vector" {
+ type = "Array(Float32)"
+ }
+ column "text" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.pg_embeddings"
+ replica_name = "{replica}-{shard}"
+ version_column = "timestamp"
+ is_deleted_column = "is_deleted"
+ }
+ }
+
+ view "posthog_document_embeddings_union_view" {
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-small-1536' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_small_1536
+UNION ALL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-large-3072' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_large_3072
+SQL
+
+ }
+
+ table "preaggregation_results" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "uniq_exact_state" {
+ type = "AggregateFunction(uniqExact, UUID)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_preaggregation_results"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ view "raw_sessions_v" {
+ query = <<SQL
+SELECT
+ session_id_v7,
+ fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)) AS session_timestamp,
+ team_id,
+ argMaxMerge(distinct_id) AS distinct_id,
+ 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(initial_browser) AS initial_browser,
+ argMinMerge(initial_browser_version) AS initial_browser_version,
+ argMinMerge(initial_os) AS initial_os,
+ argMinMerge(initial_os_version) AS initial_os_version,
+ argMinMerge(initial_device_type) AS initial_device_type,
+ argMinMerge(initial_viewport_width) AS initial_viewport_width,
+ argMinMerge(initial_viewport_height) AS initial_viewport_height,
+ argMinMerge(initial_geoip_country_code) AS initial_geoip_country_code,
+ argMinMerge(initial_geoip_subdivision_1_code) AS initial_geoip_subdivision_1_code,
+ argMinMerge(initial_geoip_subdivision_1_name) AS initial_geoip_subdivision_1_name,
+ argMinMerge(initial_geoip_subdivision_city_name) AS initial_geoip_subdivision_city_name,
+ argMinMerge(initial_geoip_time_zone) AS initial_geoip_time_zone,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ argMinMerge(initial__kx) AS initial__kx,
+ argMinMerge(initial_irclid) AS initial_irclid,
+ sum(pageview_count) AS pageview_count,
+ uniqMerge(pageview_uniq) AS pageview_uniq,
+ sum(autocapture_count) AS autocapture_count,
+ uniqMerge(autocapture_uniq) AS autocapture_uniq,
+ sum(screen_count) AS screen_count,
+ uniqMerge(screen_uniq) AS screen_uniq,
+ max(maybe_has_session_replay) AS maybe_has_session_replay,
+ uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,
+ argMinMerge(vitals_lcp) AS vitals_lcp
+FROM posthog.raw_sessions
+GROUP BY
+ session_id_v7, team_id
+SQL
+
+ }
+
+ table "session_replay_embeddings" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_embeddings"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "sharded_app_metrics2" {
+ order_by = ["team_id", "app_source", "app_source_id", "instance_id", "toStartOfHour(timestamp)", "metric_kind", "metric_name"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "app_source" {
+ type = "LowCardinality(String)"
+ }
+ column "app_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "metric_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ 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_experiment_exposures_preaggregated" {
+ order_by = ["team_id", "job_id", "entity_id", "breakdown_value"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "expires_at"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "entity_id" {
+ type = "String"
+ }
+ column "variant" {
+ type = "String"
+ }
+ column "first_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "last_exposure_time" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "exposure_event_uuid" {
+ type = "UUID"
+ }
+ column "exposure_session_id" {
+ type = "String"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "Date"
+ default = "today() + toIntervalDay(7)"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.experiment_exposures_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_heatmaps" {
+ order_by = ["type", "team_id", "toDate(timestamp)", "current_url", "viewport_width"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "x" {
+ type = "Int16"
+ }
+ column "y" {
+ type = "Int16"
+ }
+ column "scale_factor" {
+ type = "Int16"
+ }
+ column "viewport_width" {
+ type = "Int16"
+ }
+ column "viewport_height" {
+ type = "Int16"
+ }
+ column "pointer_target_fixed" {
+ type = "Bool"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.heatmaps"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_log_entries" {
+ order_by = ["team_id", "log_source", "log_source_id", "instance_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_log_entries"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_performance_events" {
+ order_by = ["team_id", "toDate(timestamp)", "session_id", "pageview_id", "timestamp"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalWeek(3)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.performance_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_buffer" {
+ order_by = ["inserted_at", "model_name", "cityHash64(document_id)"]
+ partition_by = "toDate(inserted_at)"
+ ttl = "inserted_at + toIntervalDay(1)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_buffer"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_text_embedding_3_large_3072" {
+ order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "rendering", "cityHash64(document_id)"]
+ partition_by = "toMonday(timestamp)"
+ ttl = "timestamp + toIntervalMonth(3)"
+ settings = {
+ index_granularity = "512"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_large_3072" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ index "embedding_idx_l2" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'L2Distance', 3072)"
+ granularity = 100000000
+ }
+ index "embedding_idx_cosine" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'cosineDistance', 3072)"
+ granularity = 100000000
+ }
+ constraint "embedding_dimension_check" {
+ check = "length(embedding) = 3072"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_posthog_document_embeddings_text_embedding_3_small_1536" {
+ order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "rendering", "cityHash64(document_id)"]
+ partition_by = "toMonday(timestamp)"
+ ttl = "timestamp + toIntervalMonth(3)"
+ settings = {
+ index_granularity = "512"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_small_1536" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ index "embedding_idx_l2" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'L2Distance', 1536)"
+ granularity = 100000000
+ }
+ index "embedding_idx_cosine" {
+ expr = "embedding"
+ type = "vector_similarity('hnsw', 'cosineDistance', 1536)"
+ granularity = 100000000
+ }
+ constraint "embedding_dimension_check" {
+ check = "length(embedding) = 1536"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_preaggregation_results" {
+ order_by = ["team_id", "job_id", "time_window_start", "breakdown_value"]
+ partition_by = "toYYYYMM(time_window_start)"
+ ttl = "expires_at"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ column "breakdown_value" {
+ type = "Array(String)"
+ }
+ column "uniq_exact_state" {
+ type = "AggregateFunction(uniqExact, UUID)"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.preaggregation_results"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_session_replay_embeddings" {
+ order_by = ["toDate(generation_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(generation_timestamp)"
+ ttl = "toDate(generation_timestamp) + toIntervalYear(1)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_embeddings"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "usage_report_events_preagg" {
+ column "date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_mode" {
+ type = "LowCardinality(String)"
+ }
+ column "lib" {
+ type = "LowCardinality(String)"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "distinct_events_unique" {
+ type = "AggregateFunction(uniqExact, Tuple(UInt64, UInt64, UInt64))"
+ }
+ column "event_count" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_usage_report_events_preagg"
+ sharding_key = "sipHash64(date)"
+ }
+ }
+
+ table "web_overview_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "uniq_sessions_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_duration_state" {
+ type = "AggregateFunction(avg, Float64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Int64)"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_overview_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_stats_paths_preaggregated" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Nullable(Float64))"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_paths_preaggregated"
+ sharding_key = "sipHash64(job_id)"
+ }
+ }
+
+ table "web_stats_paths_preaggregated_pathkey" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "job_id" {
+ type = "UUID"
+ }
+ column "time_window_start" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "breakdown_value" {
+ type = "String"
+ }
+ column "uniq_users_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sum_pageviews_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "avg_bounce_state" {
+ type = "AggregateFunction(avg, Nullable(Float64))"
+ }
+ column "computed_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "expires_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now() + toIntervalDay(7)"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_web_stats_paths_preaggregated_pathkey"
+ sharding_key = "sipHash64(breakdown_value)"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_text_embedding_3_large_3072" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_text_embedding_3_small_1536" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_session_replay_embeddings" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "embeddings" {
+ type = "Array(Float32)"
+ }
+ column "generation_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now('UTC')"
+ }
+ column "source_type" {
+ type = "LowCardinality(String)"
+ }
+ column "input" {
+ type = "String"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_embeddings"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "writeable_performance_events" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "pageview_id" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "entry_type" {
+ type = "LowCardinality(String)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
+ type = "String"
+ }
+ column "start_time" {
+ type = "Float64"
+ }
+ column "duration" {
+ type = "Float64"
+ }
+ column "redirect_start" {
+ type = "Float64"
+ }
+ column "redirect_end" {
+ type = "Float64"
+ }
+ column "worker_start" {
+ type = "Float64"
+ }
+ column "fetch_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_start" {
+ type = "Float64"
+ }
+ column "domain_lookup_end" {
+ type = "Float64"
+ }
+ column "connect_start" {
+ type = "Float64"
+ }
+ column "secure_connection_start" {
+ type = "Float64"
+ }
+ column "connect_end" {
+ type = "Float64"
+ }
+ column "request_start" {
+ type = "Float64"
+ }
+ column "response_start" {
+ type = "Float64"
+ }
+ column "response_end" {
+ type = "Float64"
+ }
+ column "decoded_body_size" {
+ type = "Int64"
+ }
+ column "encoded_body_size" {
+ type = "Int64"
+ }
+ column "initiator_type" {
+ type = "LowCardinality(String)"
+ }
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
+ }
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
+ }
+ column "response_status" {
+ type = "Int64"
+ }
+ column "transfer_size" {
+ type = "Int64"
+ }
+ column "largest_contentful_paint_element" {
+ type = "String"
+ }
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
+ type = "String"
+ }
+ column "largest_contentful_paint_url" {
+ type = "String"
+ }
+ column "dom_complete" {
+ type = "Float64"
+ }
+ column "dom_content_loaded_event" {
+ type = "Float64"
+ }
+ column "dom_interactive" {
+ type = "Float64"
+ }
+ column "load_event_end" {
+ type = "Float64"
+ }
+ column "load_event_start" {
+ type = "Float64"
+ }
+ column "redirect_count" {
+ type = "Int64"
+ }
+ column "navigation_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unload_event_end" {
+ type = "Float64"
+ }
+ column "unload_event_start" {
+ type = "Float64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_performance_events"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/data/common/shared_declarations.hcl b/posthog/clickhouse/hcl/roles/data/common/shared_declarations.hcl
new file mode 100644
index 000000000000..e17f74db1452
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/data/common/shared_declarations.hcl
@@ -0,0 +1,2187 @@
+# Objects more than one data layer used to declare. The declaration lives here,
+# in a layer every consumer composes; a cluster whose shape genuinely differs
+# restates it with override = true rather than declaring it a second time.
+database "posthog" {
+
+ table "clickhouse_cleanup_deleted_persons" {
+ partition_by = "run_id"
+ order_by = ["run_id", "team_id", "person_id"]
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "max_version" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_orphaned_distinct_ids" {
+ partition_by = "run_id"
+ order_by = ["run_id", "team_id", "distinct_id"]
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "own_tombstone" {
+ type = "UInt8"
+ }
+ column "max_version" {
+ type = "Int64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_distinct_ids" {
+ partition_by = "run_id"
+ order_by = ["run_id", "team_id", "distinct_id"]
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_persons" {
+ partition_by = "run_id"
+ order_by = ["run_id", "team_id", "person_id"]
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "distributed_events_recent" {
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "distributed" {
+ cluster_name = "posthog_primary_replica"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "partitioned_sharded_posthog_document_embeddings"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_system_processes" {
+ settings = {
+ skip_unavailable_shards = "1"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "user" {
+ type = "String"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "address" {
+ type = "IPv6"
+ }
+ column "port" {
+ type = "UInt16"
+ }
+ column "initial_user" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "initial_address" {
+ type = "IPv6"
+ }
+ column "initial_port" {
+ type = "UInt16"
+ }
+ column "interface" {
+ type = "UInt8"
+ }
+ column "os_user" {
+ type = "String"
+ }
+ column "client_hostname" {
+ type = "String"
+ }
+ column "client_name" {
+ type = "String"
+ }
+ column "client_agent" {
+ type = "LowCardinality(String)"
+ }
+ column "client_revision" {
+ type = "UInt64"
+ }
+ column "client_version_major" {
+ type = "UInt64"
+ }
+ column "client_version_minor" {
+ type = "UInt64"
+ }
+ column "client_version_patch" {
+ type = "UInt64"
+ }
+ column "client_agent" {
+ type = "LowCardinality(String)"
+ }
+ column "http_method" {
+ type = "UInt8"
+ }
+ column "http_user_agent" {
+ type = "String"
+ }
+ column "http_referer" {
+ type = "String"
+ }
+ column "forwarded_for" {
+ type = "String"
+ }
+ column "quota_key" {
+ type = "String"
+ }
+ column "distributed_depth" {
+ type = "UInt64"
+ }
+ column "elapsed" {
+ type = "Float64"
+ }
+ column "is_cancelled" {
+ type = "UInt8"
+ }
+ column "is_all_data_sent" {
+ type = "UInt8"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "total_rows_approx" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "Int64"
+ }
+ column "peak_memory_usage" {
+ type = "Int64"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "String"
+ }
+ column "thread_ids" {
+ type = "Array(UInt64)"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "ProfileEvents" {
+ type = "Map(LowCardinality(String), UInt64)"
+ }
+ column "Settings" {
+ type = "Map(LowCardinality(String), LowCardinality(String))"
+ }
+ column "current_database" {
+ type = "String"
+ }
+ column "is_internal" {
+ type = "UInt8"
+ }
+ column "ProfileEvents.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(ProfileEvents)"
+ }
+ column "ProfileEvents.Values" {
+ type = "Array(UInt64)"
+ alias = "mapValues(ProfileEvents)"
+ }
+ column "Settings.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(Settings)"
+ }
+ column "Settings.Values" {
+ type = "Array(String)"
+ alias = "mapValues(Settings)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "system"
+ remote_table = "processes"
+ }
+ }
+
+ view "events_batch_export" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ (events.timestamp >= ({interval_start: DateTime64} - toIntervalDay({lookback_days: Int32})))
+AND
+ (events.timestamp < ({interval_end: DateTime64} + toIntervalDay(1)))
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "events_batch_export_unbounded" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ table "events_dead_letter_queue" {
+ order_by = ["id", "event_uuid", "distinct_id", "team_id"]
+ ttl = "toDate(_timestamp) + toIntervalWeek(4)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "ip" {
+ type = "String"
+ }
+ column "site_url" {
+ type = "String"
+ }
+ column "now" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "raw_payload" {
+ type = "String"
+ }
+ column "error_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "error_location" {
+ type = "String"
+ }
+ column "error" {
+ type = "String"
+ }
+ column "tags" {
+ type = "Array(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_events_dead_letter_queue" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.events_dead_letter_queue"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "groups" {
+ order_by = ["team_id", "group_type_index", "group_key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "group_type_index" {
+ type = "UInt8"
+ }
+ column "group_key" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "group_properties" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "Bool"
+ }
+ index "is_deleted_idx" {
+ expr = "(is_deleted)"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.groups"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "ingestion_warnings" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_ingestion_warnings"
+ sharding_key = "rand()"
+ }
+ }
+
+ view "persons_batch_export" {
+ query = <<SQL
+WITH
+ new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING ((_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64}))),
+ new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING ((argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64}))),
+ all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
+SELECT
+ p.team_id AS team_id,
+ pd.distinct_id AS distinct_id,
+ toString(p.id) AS person_id,
+ p.properties AS properties,
+ pd.version AS person_distinct_id_version,
+ p.version AS person_version,
+ p.created_at AS created_at,
+ multiIf(
+ ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
+ pd._timestamp,
+ ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
+ p._timestamp,
+ least(p._timestamp, pd._timestamp)
+ ) AS _inserted_at
+FROM
+ posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((id, version) IN (all_new_persons))
+ORDER BY _inserted_at ASC
+SQL
+
+ }
+
+ table "plugin_log_entries" {
+ order_by = ["team_id", "plugin_id", "plugin_config_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalWeek(1)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "plugin_id" {
+ type = "Int64"
+ }
+ column "plugin_config_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "UUID"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.plugin_log_entries"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
+ query = file("sql/posthog_document_embeddings_text_embedding_3_large_3072_mv.sql")
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
+ query = file("sql/posthog_document_embeddings_text_embedding_3_small_1536_mv.sql")
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ table "property_definitions" {
+ order_by = ["team_id", "type", "coalesce(event, '')", "name", "coalesce(group_type_index, 255)"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt32"
+ }
+ column "project_id" {
+ type = "Nullable(UInt32)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "property_type" {
+ type = "Nullable(String)"
+ }
+ column "event" {
+ type = "Nullable(String)"
+ }
+ column "group_type_index" {
+ type = "Nullable(UInt8)"
+ }
+ column "type" {
+ type = "UInt8"
+ default = "1"
+ }
+ column "last_seen_at" {
+ type = "DateTime"
+ }
+ column "version" {
+ type = "UInt64"
+ materialized = "(bitShiftLeft(toUInt64(NOT isNull(property_type)), 48) + toUInt64(toUnixTimestamp(last_seen_at)))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.property_definitions"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "raw_sessions_v3" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), 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)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ view "raw_sessions_v3_v" {
+ query = <<SQL
+SELECT
+ session_id_v7,
+ session_timestamp,
+ team_id,
+ argMaxMerge(distinct_id) AS distinct_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,
+ 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,
+ 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_uniq_up_to) AS page_screen_uniq_up_to,
+ max(has_autocapture) AS has_autocapture,
+ groupUniqArrayMapMerge(flag_values) AS flag_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_events
+FROM posthog.raw_sessions_v3
+GROUP BY
+ session_id_v7, session_timestamp, team_id
+SQL
+
+ }
+
+ table "session_replay_events" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ view "sessions_v" {
+ query = <<SQL
+SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(exit_url) AS exit_url,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ argMinMerge(initial_epik) AS initial_epik,
+ argMinMerge(initial_qclid) AS initial_qclid,
+ argMinMerge(initial_sccid) AS initial_sccid,
+ sumMap(event_count_map) AS event_count_map,
+ sum(pageview_count) AS pageview_count,
+ sum(autocapture_count) AS autocapture_count
+FROM posthog.sessions
+GROUP BY
+ session_id, team_id
+SQL
+
+ }
+
+ table "sharded_raw_sessions_v3" {
+ order_by = ["team_id", "session_timestamp", "session_id_v7"]
+ partition_by = "toYYYYMM(session_timestamp)"
+ settings = {
+ index_granularity = "8192"
+ max_delay_to_insert = "10"
+ parts_to_delay_insert = "250"
+ parts_to_throw_insert = "1000"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ default = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), 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)"
+ }
+ index "event_names_bloom_filter" {
+ expr = "event_names"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ index "flag_keys_bloom_filter" {
+ expr = "flag_keys"
+ 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}"
+ }
+ }
+
+ table "sharded_session_replay_events" {
+ order_by = ["toDate(min_first_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(min_first_timestamp)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "tophog" {
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "metric" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ default = "'sum'"
+ }
+ column "key" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "0"
+ }
+ column "pipeline" {
+ type = "LowCardinality(String)"
+ }
+ column "lane" {
+ type = "LowCardinality(String)"
+ }
+ column "labels" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_tophog"
+ sharding_key = "cityHash64(toString(key))"
+ }
+ }
+
+ table "web_pre_aggregated_bounces" {
+ order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_loggedIn", "mat_metadata_backend"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "web_pre_aggregated_stats" {
+ order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_loggedIn", "mat_metadata_backend"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "writable_raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_epik" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_qclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_sccid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_raw_sessions_v3" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ default = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), 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)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_epik" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_qclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_sccid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/data/local/sql/posthog_document_embeddings_text_embedding_3_large_3072_mv.sql b/posthog/clickhouse/hcl/roles/data/common/sql/posthog_document_embeddings_text_embedding_3_large_3072_mv.sql
similarity index 100%
rename from posthog/clickhouse/hcl/roles/data/local/sql/posthog_document_embeddings_text_embedding_3_large_3072_mv.sql
rename to posthog/clickhouse/hcl/roles/data/common/sql/posthog_document_embeddings_text_embedding_3_large_3072_mv.sql
diff --git a/posthog/clickhouse/hcl/roles/data/local/sql/posthog_document_embeddings_text_embedding_3_small_1536_mv.sql b/posthog/clickhouse/hcl/roles/data/common/sql/posthog_document_embeddings_text_embedding_3_small_1536_mv.sql
similarity index 100%
rename from posthog/clickhouse/hcl/roles/data/local/sql/posthog_document_embeddings_text_embedding_3_small_1536_mv.sql
rename to posthog/clickhouse/hcl/roles/data/common/sql/posthog_document_embeddings_text_embedding_3_small_1536_mv.sql
diff --git a/posthog/clickhouse/hcl/roles/data/dev/tables.hcl b/posthog/clickhouse/hcl/roles/data/dev/tables.hcl
new file mode 100644
index 000000000000..e4f15e6145bb
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/data/dev/tables.hcl
@@ -0,0 +1,3986 @@
+# dev data cluster: objects only dev runs, and the deltas it applies to the cloud shape.
+database "posthog" {
+ table "app_metrics" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "plugin_config_id" {
+ type = "Int64"
+ }
+ column "category" {
+ type = "LowCardinality(String)"
+ }
+ column "job_id" {
+ type = "String"
+ }
+ column "successes" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "successes_on_retry" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "failures" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "error_uuid" {
+ type = "UUID"
+ }
+ column "error_type" {
+ type = "String"
+ }
+ column "error_details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_app_metrics"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "dmat_slot_assignments" {
+ order_by = ["team_id", "column_index"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "column_index" {
+ type = "UInt8"
+ }
+ column "property_name" {
+ type = "String"
+ }
+ column "version" {
+ type = "UInt32"
+ default = "toUnixTimestamp(now())"
+ }
+ engine "replacing_merge_tree" {
+ version_column = "version"
+ }
+ }
+
+ table "dummy" {
+ order_by = ["id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "String"
+ }
+ engine "merge_tree" {
+ }
+ }
+
+ table "dummy_privileges" {
+ order_by = ["id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "String"
+ }
+ engine "merge_tree" {
+ }
+ }
+
+ table "eni_inventory" {
+ order_by = ["eni_id", "ip_address"]
+ partition_by = "toYYYYMMDD(collected_at)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "collected_at" {
+ type = "DateTime"
+ }
+ column "eni_id" {
+ type = "String"
+ }
+ column "ip_address" {
+ type = "String"
+ }
+ column "owner_account" {
+ type = "String"
+ }
+ column "subnet_id" {
+ type = "String"
+ }
+ column "security_groups" {
+ type = "Array(JSON)"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "node_name" {
+ type = "String"
+ }
+ column "karpenter_nodeclaim" {
+ type = "String"
+ }
+ column "karpenter_ec2nodeclass" {
+ type = "String"
+ }
+ engine "replacing_merge_tree" {
+ version_column = "collected_at"
+ }
+ }
+
+ table "flow_logs_local" {
+ order_by = ["ts_start", "dstport", "dstaddr", "interface_id"]
+ partition_by = "toYYYYMMDD(ts_start)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "interface_id" {
+ type = "String"
+ }
+ column "srcaddr" {
+ type = "String"
+ }
+ column "dstaddr" {
+ type = "String"
+ }
+ column "srcport" {
+ type = "UInt16"
+ }
+ column "dstport" {
+ type = "UInt16"
+ }
+ column "protocol" {
+ type = "UInt8"
+ }
+ column "packets" {
+ type = "UInt32"
+ }
+ column "bytes" {
+ type = "UInt64"
+ }
+ column "ts_start" {
+ type = "DateTime"
+ }
+ column "ts_end" {
+ type = "DateTime"
+ }
+ column "action" {
+ type = "LowCardinality(String)"
+ }
+ column "log_status" {
+ type = "LowCardinality(String)"
+ }
+ engine "merge_tree" {
+ }
+ }
+
+ table "groups2" {
+ order_by = ["group_key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "group_key" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.groups2"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "k8s_node_inventory" {
+ order_by = ["nodepool", "instance_id"]
+ partition_by = "toYYYYMMDD(collected_at)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "collected_at" {
+ type = "DateTime"
+ }
+ column "node_name" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "region" {
+ type = "String"
+ }
+ column "nodeclaim" {
+ type = "String"
+ }
+ column "nodepool" {
+ type = "String"
+ }
+ column "ec2nodeclass" {
+ type = "String"
+ }
+ column "labels" {
+ type = "JSON"
+ }
+ column "enis" {
+ type = "Array(JSON)"
+ }
+ engine "replacing_merge_tree" {
+ version_column = "collected_at"
+ }
+ }
+
+ table "kafka_error_tracking_issue_fingerprint_overrides_ws" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "fingerprint" {
+ type = "String"
+ }
+ column "issue_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ engine "kafka" {
+ collection = "warpstream_shared"
+ topic_list = "clickhouse_error_tracking_issue_fingerprint"
+ group_name = "clickhouse_error_tracking_issue_fingerprint_overrides_ws"
+ format = "JSONEachRow"
+ }
+ }
+
+ table "materialized_test" {
+ order_by = ["id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UInt32"
+ }
+ column "properties" {
+ type = "String"
+ }
+ engine "merge_tree" {
+ }
+ }
+
+ table "person" {
+ override = true
+ order_by = ["team_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ default = "0"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "last_seen_at" {
+ type = "Nullable(DateTime64(3))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/am0005_20220705151225_noshard/posthog.person"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "poc_events" {
+ order_by = ["team_id", "toDate(timestamp)", "cityHash64(distinct_id)", "cityHash64(uuid)"]
+ partition_by = "toYYYYMM(timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ engine "merge_tree" {
+ }
+ }
+
+ table "posthog_document_embeddings" {
+ order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "model_name", "rendering", "cityHash64(document_id)"]
+ settings = {
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ index "kafka_timestamp_minmax_posthog_document_embeddings" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.posthog_document_embeddings"
+ replica_name = "{replica}-{shard}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "precalculated_events" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "condition" {
+ type = "String"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_precalculated_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "precalculated_person_properties" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "condition" {
+ type = "String"
+ }
+ column "matches" {
+ type = "Bool"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_precalculated_person_properties"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "rds_inventory" {
+ order_by = ["region", "instance_name"]
+ partition_by = "toYYYYMMDD(collected_at)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "collected_at" {
+ type = "DateTime"
+ }
+ column "region" {
+ type = "String"
+ }
+ column "instance_name" {
+ type = "String"
+ }
+ column "cluster_name" {
+ type = "String"
+ }
+ column "endpoint" {
+ type = "String"
+ }
+ column "ip_address" {
+ type = "String"
+ }
+ engine "replacing_merge_tree" {
+ version_column = "collected_at"
+ }
+ }
+
+ table "session_recording_events" {
+ override = true
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "has_full_snapshot" {
+ type = "Int8"
+ comment = "column_materializer::has_full_snapshot"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "events_summary" {
+ type = "Array(String)"
+ comment = "column_materializer::events_summary"
+ }
+ column "click_count" {
+ type = "Int8"
+ comment = "column_materializer::click_count"
+ }
+ column "keypress_count" {
+ type = "Int8"
+ comment = "column_materializer::keypress_count"
+ }
+ column "timestamps_summary" {
+ type = "Array(DateTime64(6, 'UTC'))"
+ comment = "column_materializer::timestamps_summary"
+ }
+ column "first_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::first_event_timestamp"
+ }
+ column "last_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::last_event_timestamp"
+ }
+ column "urls" {
+ type = "Array(String)"
+ comment = "column_materializer::urls"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_recording_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "sharded_app_metrics" {
+ override = true
+ order_by = ["team_id", "plugin_config_id", "job_id", "category", "toStartOfHour(timestamp)", "error_type", "error_uuid"]
+ partition_by = "toYYYYMM(timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "plugin_config_id" {
+ type = "Int64"
+ }
+ column "category" {
+ type = "LowCardinality(String)"
+ }
+ column "job_id" {
+ type = "String"
+ }
+ column "successes" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "successes_on_retry" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "failures" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "error_uuid" {
+ type = "UUID"
+ }
+ column "error_type" {
+ type = "String"
+ }
+ column "error_details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_app_metrics"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_billing_usage_records" {
+ override = true
+ order_by = ["team_id", "toDate(timestamp)", "producer_id", "usage_key", "record_id"]
+ partition_by = "toYYYYMM(timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "schema_version" {
+ type = "UInt8"
+ }
+ column "record_id" {
+ type = "String"
+ }
+ column "producer_id" {
+ type = "LowCardinality(String)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "organization_id" {
+ type = "UUID"
+ }
+ column "usage_key" {
+ type = "LowCardinality(String)"
+ }
+ column "unit" {
+ type = "LowCardinality(String)"
+ }
+ column "quantity" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_billing_usage_records"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ table "sharded_events_codec_test" {
+ order_by = ["team_id", "toDate(timestamp)", "event", "cityHash64(distinct_id)", "cityHash64(uuid)"]
+ partition_by = "toYYYYMM(timestamp)"
+ sample_by = "cityHash64(distinct_id)"
+ settings = {
+ default_compression_codec = "ZSTD(3)"
+ 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_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 "$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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "person_created_at" {
+ type = "DateTime64(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 "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"
+ 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 "elements_chain_ids" {
+ type = "Array(String)"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
+ }
+ 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'))), 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 "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_map_ephemeral" {
+ type = "Map(String, String)"
+ }
+ column "person_properties_map_ephemeral" {
+ type = "Map(String, 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_trace_id" {
+ type = "Nullable(String)"
+ materialized = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
+ }
+ column "mat_historical_migration" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, 'historical_migration', '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 "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)"
+ 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_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 "replacing_merge_tree" {
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_precalculated_events" {
+ override = true
+ order_by = ["team_id", "condition", "date", "distinct_id", "uuid"]
+ partition_by = "toYYYYMM(date)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "date" {
+ type = "Date"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "condition" {
+ type = "String"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_precalculated_events"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_precalculated_person_properties" {
+ override = true
+ order_by = ["team_id", "condition", "distinct_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "condition" {
+ type = "String"
+ }
+ column "matches" {
+ type = "Bool"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_precalculated_person_properties"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_raw_sessions" {
+ override = true
+ order_by = ["team_id", "toStartOfHour(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)))", "cityHash64(session_id_v7)", "session_id_v7"]
+ partition_by = "toYYYYMM(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)))"
+ sample_by = "cityHash64(session_id_v7)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_raw_sessions_v3" {
+ override = true
+ order_by = ["team_id", "session_timestamp", "session_id_v7"]
+ partition_by = "toYYYYMM(session_timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ index "event_names_bloom_filter" {
+ expr = "event_names"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ index "flag_keys_bloom_filter" {
+ expr = "flag_keys"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions_v3"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_sessions" {
+ override = true
+ order_by = ["toStartOfDay(min_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(min_timestamp)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sessions"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "writable_events" {
+ override = 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 "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "person_created_at" {
+ type = "DateTime64(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 "consumer_breadcrumbs" {
+ type = "Array(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)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_buffer" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_buffer"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ patch_table "events" {
+ column "elements_chain" {
+ type = "String"
+ after = "distinct_id"
+ }
+ column "person_id" {
+ type = "UUID"
+ after = "created_at"
+ }
+ column "person_properties" {
+ type = "String"
+ after = "person_id"
+ }
+ column "group0_properties" {
+ type = "String"
+ after = "person_properties"
+ }
+ column "group1_properties" {
+ type = "String"
+ after = "group0_properties"
+ }
+ column "group2_properties" {
+ type = "String"
+ after = "group1_properties"
+ }
+ column "group3_properties" {
+ type = "String"
+ after = "group2_properties"
+ }
+ column "group4_properties" {
+ type = "String"
+ after = "group3_properties"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ after = "$session_id"
+ }
+ column "_offset" {
+ type = "UInt64"
+ after = "_timestamp"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ after = "_offset"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ after = "person_created_at"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ after = "group0_created_at"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ after = "group1_created_at"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ after = "group2_created_at"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ after = "group3_created_at"
+ }
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_trace_id"
+ after = "properties_group_ai"
+ }
+ }
+
+ patch_table "sharded_events" {
+ column "elements_chain" {
+ type = "String"
+ after = "distinct_id"
+ }
+ column "person_id" {
+ type = "UUID"
+ after = "created_at"
+ }
+ column "person_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "person_id"
+ }
+ column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "person_properties"
+ }
+ column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group0_properties"
+ }
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group1_properties"
+ }
+ column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group2_properties"
+ }
+ column "group4_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group3_properties"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ after = "$session_id"
+ }
+ column "_offset" {
+ type = "UInt64"
+ after = "_timestamp"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ after = "_offset"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ after = "person_created_at"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ after = "group0_created_at"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ after = "group1_created_at"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ after = "group2_created_at"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ after = "group3_created_at"
+ }
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ materialized = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
+ after = "properties_group_ai"
+ }
+ settings = {
+ replicated_fetches_min_part_level = "1"
+ replicated_fetches_min_part_level_timeout_seconds = "300"
+ }
+ }
+
+ patch_table "sharded_session_replay_events" {
+ settings = {
+ ttl_only_drop_parts = "1"
+ }
+ }
+
+ table "billing_usage_records" {
+ override = true
+ column "schema_version" {
+ type = "UInt8"
+ }
+ column "record_id" {
+ type = "String"
+ }
+ column "producer_id" {
+ type = "LowCardinality(String)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "organization_id" {
+ type = "UUID"
+ }
+ column "usage_key" {
+ type = "LowCardinality(String)"
+ }
+ column "unit" {
+ type = "LowCardinality(String)"
+ }
+ column "quantity" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_billing_usage_records"
+ sharding_key = "cityHash64(team_id)"
+ }
+ }
+
+ table "clickhouse_cleanup_deleted_persons" {
+ override = true
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "max_version" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_orphaned_distinct_ids" {
+ override = true
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "own_tombstone" {
+ type = "UInt8"
+ }
+ column "max_version" {
+ type = "Int64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_distinct_ids" {
+ override = true
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_persons" {
+ override = true
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "distributed_events_recent" {
+ override = true
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ column "_timestamp_ms" {
+ type = "DateTime64(3)"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_system_processes" {
+ override = true
+ settings = {
+ skip_unavailable_shards = "1"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "user" {
+ type = "String"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "address" {
+ type = "IPv6"
+ }
+ column "port" {
+ type = "UInt16"
+ }
+ column "initial_user" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "initial_address" {
+ type = "IPv6"
+ }
+ column "initial_port" {
+ type = "UInt16"
+ }
+ column "interface" {
+ type = "UInt8"
+ }
+ column "os_user" {
+ type = "String"
+ }
+ column "client_hostname" {
+ type = "String"
+ }
+ column "client_name" {
+ type = "String"
+ }
+ column "client_revision" {
+ type = "UInt64"
+ }
+ column "client_version_major" {
+ type = "UInt64"
+ }
+ column "client_version_minor" {
+ type = "UInt64"
+ }
+ column "client_version_patch" {
+ type = "UInt64"
+ }
+ column "http_method" {
+ type = "UInt8"
+ }
+ column "http_user_agent" {
+ type = "String"
+ }
+ column "http_referer" {
+ type = "String"
+ }
+ column "forwarded_for" {
+ type = "String"
+ }
+ column "quota_key" {
+ type = "String"
+ }
+ column "distributed_depth" {
+ type = "UInt64"
+ }
+ column "elapsed" {
+ type = "Float64"
+ }
+ column "is_cancelled" {
+ type = "UInt8"
+ }
+ column "is_all_data_sent" {
+ type = "UInt8"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "total_rows_approx" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "Int64"
+ }
+ column "peak_memory_usage" {
+ type = "Int64"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "query_kind" {
+ type = "String"
+ }
+ column "thread_ids" {
+ type = "Array(UInt64)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "Settings" {
+ type = "Map(String, String)"
+ }
+ column "current_database" {
+ type = "String"
+ }
+ column "ProfileEvents.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(ProfileEvents)"
+ }
+ column "ProfileEvents.Values" {
+ type = "Array(UInt64)"
+ alias = "mapValues(ProfileEvents)"
+ }
+ column "Settings.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(Settings)"
+ }
+ column "Settings.Values" {
+ type = "Array(String)"
+ alias = "mapValues(Settings)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "system"
+ remote_table = "processes"
+ }
+ }
+
+ view "events_batch_export" {
+ override = true
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (events.inserted_at >= {interval_start: DateTime64}) AND (events.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ (events.timestamp >= ({interval_start: DateTime64} - toIntervalDay({lookback_days: Int32})))
+AND
+ (events.timestamp < ({interval_end: DateTime64} + toIntervalDay(1)))
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "events_batch_export_unbounded" {
+ override = true
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (events.inserted_at >= {interval_start: DateTime64}) AND (events.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ table "events_dead_letter_queue" {
+ override = true
+ order_by = ["id", "event_uuid", "distinct_id", "team_id"]
+ ttl = "toDate(_timestamp) + toIntervalWeek(4)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "ip" {
+ type = "String"
+ }
+ column "site_url" {
+ type = "String"
+ }
+ column "now" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "raw_payload" {
+ type = "String"
+ }
+ column "error_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "error_location" {
+ type = "String"
+ }
+ column "error" {
+ type = "String"
+ }
+ column "tags" {
+ type = "Array(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.events_dead_letter_queue"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "groups" {
+ override = true
+ order_by = ["team_id", "group_type_index", "group_key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "group_type_index" {
+ type = "UInt8"
+ }
+ column "group_key" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "group_properties" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "Bool"
+ }
+ index "is_deleted_idx" {
+ expr = "is_deleted"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.groups"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "ingestion_warnings" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "details" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_ingestion_warnings"
+ sharding_key = "rand()"
+ }
+ }
+
+ view "persons_batch_export" {
+ override = true
+ query = <<SQL
+WITH
+ new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
+ new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
+ all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
+SELECT
+ p.team_id AS team_id,
+ pd.distinct_id AS distinct_id,
+ toString(p.id) AS person_id,
+ p.properties AS properties,
+ pd.version AS person_distinct_id_version,
+ p.version AS person_version,
+ p.created_at AS created_at,
+ multiIf(
+ ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
+ pd._timestamp,
+ ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
+ p._timestamp,
+ least(p._timestamp, pd._timestamp)
+ ) AS _inserted_at
+FROM
+ posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((id, version) IN (all_new_persons))
+ORDER BY _inserted_at ASC
+SQL
+
+ }
+
+ table "plugin_log_entries" {
+ override = true
+ order_by = ["team_id", "id"]
+ partition_by = "plugin_id"
+ ttl = "toDate(timestamp) + toIntervalWeek(1)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "plugin_id" {
+ type = "Int64"
+ }
+ column "plugin_config_id" {
+ type = "Int64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "UUID"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.plugin_log_entries"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
+ override = true
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-large-3072'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
+ override = true
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-small-1536'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ table "property_definitions" {
+ override = true
+ order_by = ["team_id", "type", "coalesce(event, '')", "name", "coalesce(group_type_index, 255)"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt32"
+ }
+ column "project_id" {
+ type = "Nullable(UInt32)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "property_type" {
+ type = "Nullable(String)"
+ }
+ column "event" {
+ type = "Nullable(String)"
+ }
+ column "group_type_index" {
+ type = "Nullable(UInt8)"
+ }
+ column "type" {
+ type = "UInt8"
+ default = "1"
+ }
+ column "last_seen_at" {
+ type = "DateTime"
+ }
+ column "version" {
+ type = "UInt64"
+ materialized = "bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.property_definitions"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "raw_sessions_v3" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ 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
+
+ }
+
+ table "session_replay_events" {
+ override = true
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ view "sessions_v" {
+ override = true
+ query = <<SQL
+SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(exit_url) AS exit_url,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ sumMap(event_count_map) AS event_count_map,
+ sum(pageview_count) AS pageview_count,
+ sum(autocapture_count) AS autocapture_count
+FROM posthog.sessions
+GROUP BY
+ session_id, team_id
+SQL
+
+ }
+
+ table "tophog" {
+ override = true
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "metric" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ default = "'sum'"
+ }
+ column "key" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "0"
+ }
+ column "pipeline" {
+ type = "LowCardinality(String)"
+ }
+ column "lane" {
+ type = "LowCardinality(String)"
+ }
+ column "labels" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_tophog"
+ sharding_key = "cityHash64(toString(key))"
+ }
+ }
+
+ table "web_pre_aggregated_bounces" {
+ override = true
+ order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "web_pre_aggregated_stats" {
+ override = true
+ order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "writable_raw_sessions" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_raw_sessions_v3" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_sessions" {
+ override = true
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "sharded_session_recording_events" {
+ order_by = ["team_id", "toHour(timestamp)", "session_id", "timestamp", "uuid"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(created_at) + toIntervalWeek(3)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "has_full_snapshot" {
+ type = "Int8"
+ materialized = "JSONExtractBool(snapshot_data, 'has_full_snapshot')"
+ comment = "column_materializer::has_full_snapshot"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "events_summary" {
+ type = "Array(String)"
+ materialized = "JSONExtract(JSON_QUERY(snapshot_data, '$.events_summary[*]'), 'Array(String)')"
+ }
+ column "click_count" {
+ type = "Int8"
+ materialized = "length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 2) AND (JSONExtractInt(x, 'data', 'source') = 2)), events_summary))"
+ }
+ column "keypress_count" {
+ type = "Int8"
+ materialized = "length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 5)), events_summary))"
+ }
+ column "timestamps_summary" {
+ type = "Array(DateTime64(6, 'UTC'))"
+ materialized = "arraySort(arrayMap(x -> toDateTime(JSONExtractInt(x, 'timestamp') / 1000), events_summary))"
+ }
+ column "first_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ materialized = "arrayReduce('min', timestamps_summary)"
+ }
+ column "last_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ materialized = "arrayReduce('max', timestamps_summary)"
+ }
+ column "urls" {
+ type = "Array(String)"
+ materialized = "arrayFilter(x -> (x != ''), arrayMap(x -> JSONExtractString(x, 'data', 'href'), events_summary))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_recording_events"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "writable_events_dead_letter_queue" {
+ override = true
+ column "id" {
+ type = "UUID"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "ip" {
+ type = "String"
+ }
+ column "site_url" {
+ type = "String"
+ }
+ column "now" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "raw_payload" {
+ type = "String"
+ }
+ column "error_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "error_location" {
+ type = "String"
+ }
+ column "error" {
+ type = "String"
+ }
+ column "tags" {
+ type = "Array(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog_single_shard"
+ remote_database = "posthog"
+ remote_table = "events_dead_letter_queue"
+ }
+ }
+
+ # dev dropped this index; both prod clusters still carry it.
+ patch_table "sharded_events" {
+ drop_indexes = ["bloom_filter_$session_id"]
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/data/local/patches.hcl b/posthog/clickhouse/hcl/roles/data/local/patches.hcl
index fbfe6664881b..847b4343df46 100644
--- a/posthog/clickhouse/hcl/roles/data/local/patches.hcl
+++ b/posthog/clickhouse/hcl/roles/data/local/patches.hcl
@@ -123,6 +123,18 @@ database "posthog" {
}
}
+ patch_table "sharded_ingestion_warnings" {
+ partition_by = "toYYYYMMDD(timestamp)"
+ modify_column "details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_ingestion_warnings"
+ replica_name = "{replica}"
+ }
+ }
+
patch_table "events_recent" {
modify_column "properties" {
type = "String"
@@ -167,16 +179,4 @@ database "posthog" {
sharding_key = "sipHash64(distinct_id)"
}
}
-
- patch_table "sharded_ingestion_warnings" {
- partition_by = "toYYYYMMDD(timestamp)"
- modify_column "details" {
- type = "String"
- codec = "ZSTD(3)"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_ingestion_warnings"
- replica_name = "{replica}"
- }
- }
}
diff --git a/posthog/clickhouse/hcl/roles/data/local/tables.hcl b/posthog/clickhouse/hcl/roles/data/local/tables.hcl
index ca33db3df45e..ad11c8d4ebf2 100644
--- a/posthog/clickhouse/hcl/roles/data/local/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/data/local/tables.hcl
@@ -1,68 +1,29 @@
database "posthog" {
- table "adhoc_events_deletion" {
- order_by = ["team_id", "uuid"]
- ttl = "deleted_at + toIntervalMonth(3) WHERE is_deleted = 1"
- settings = {
- index_granularity = "8192"
- }
- column "team_id" {
- type = "Int64"
- }
+ table "events_json" {
column "uuid" {
type = "UUID"
}
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- column "deleted_at" {
- type = "DateTime"
- }
- column "is_deleted" {
- type = "UInt8"
- default = "0"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.adhoc_events_deletion"
- replica_name = "{replica}-{shard}"
- version_column = "deleted_at"
- is_deleted_column = "is_deleted"
+ column "event" {
+ type = "String"
}
- }
- table "app_metrics" {
- column "team_id" {
- type = "Int64"
+ column "properties" {
+ type = "JSON(max_dynamic_types=8, max_dynamic_paths=256, `$active_feature_flags` Array(String), `$ai_experiment_id` Nullable(String), `$ai_http_status` Nullable(String), `$ai_is_error` Nullable(String), `$ai_model` Nullable(String), `$ai_parent_id` Nullable(String), `$ai_prompt_name` Nullable(String), `$ai_provider` Nullable(String), `$ai_session_id` Nullable(String), `$ai_span_id` Nullable(String), `$ai_total_cost_usd` Nullable(String), `$ai_trace_id` Nullable(String), `$anon_distinct_id` Nullable(String), `$app_build` Nullable(String), `$app_namespace` Nullable(String), `$app_version` Nullable(String), `$browser` Nullable(String), `$browser_version` Nullable(String), `$current_url` Nullable(String), `$device` Nullable(String), `$device_id` Nullable(String), `$device_model` Nullable(String), `$device_type` Nullable(String), `$el_text` Nullable(String), `$event_type` Nullable(String), `$exception_fingerprint` Nullable(String), `$exception_functions` Array(String), `$exception_issue_id` Nullable(String), `$exception_sources` Array(String), `$exception_types` Array(String), `$exception_values` Array(String), `$feature_flag` Nullable(String), `$feature_flag_payloads` Nullable(String), `$feature_flag_response` Nullable(String), `$geoip_city_name` Nullable(String), `$geoip_country_code` Nullable(String), `$geoip_country_name` Nullable(String), `$geoip_subdivision_1_code` Nullable(String), `$group_0` Nullable(String), `$group_1` Nullable(String), `$group_2` Nullable(String), `$group_3` Nullable(String), `$group_4` Nullable(String), `$groups` Nullable(String), `$host` Nullable(String), `$initial_pathname` Nullable(String), `$initial_referrer` Nullable(String), `$initial_referring_domain` Nullable(String), `$ip` Nullable(String), `$is_identified` Nullable(String), `$lib` Nullable(String), `$lib_custom_api_host` Nullable(String), `$lib_version` Nullable(String), `$lib_version__minor` Nullable(String), `$os` Nullable(String), `$os_name` Nullable(String), `$os_version` Nullable(String), `$pathname` Nullable(String), `$prev_pageview_max_content_percentage` Nullable(String), `$prev_pageview_max_scroll_percentage` Nullable(String), `$prev_pageview_pathname` Nullable(String), `$process_person_profile` Nullable(String), `$referrer` Nullable(String), `$referring_domain` Nullable(String), `$screen_height` Nullable(String), `$screen_name` Nullable(String), `$screen_width` Nullable(String), `$sent_at` Nullable(String), `$session_id` Nullable(String), `$survey_id` Nullable(String), `$survey_response` Nullable(String), `$survey_response_1` Nullable(String), `$time` Nullable(String), `$user_id` Nullable(String), `$viewport_height` Nullable(String), `$viewport_width` Nullable(String), `$web_vitals_CLS_value` Nullable(String), `$web_vitals_FCP_value` Nullable(String), `$web_vitals_INP_value` Nullable(String), `$web_vitals_LCP_value` Nullable(String), `$window_id` Nullable(String))"
}
column "timestamp" {
type = "DateTime64(6, 'UTC')"
}
- column "plugin_config_id" {
+ column "team_id" {
type = "Int64"
}
- column "category" {
- type = "LowCardinality(String)"
- }
- column "job_id" {
+ column "distinct_id" {
type = "String"
}
- column "successes" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "successes_on_retry" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "failures" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "error_uuid" {
- type = "UUID"
- }
- column "error_type" {
+ column "elements_hash" {
type = "String"
+ default = "''"
}
- column "error_details" {
- type = "String"
- codec = "ZSTD(3)"
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
}
column "_timestamp" {
type = "DateTime"
@@ -70,305 +31,191 @@ database "posthog" {
column "_offset" {
type = "UInt64"
}
- column "_partition" {
- type = "UInt64"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_app_metrics"
- sharding_key = "rand()"
- }
- }
- table "app_metrics2" {
- column "team_id" {
- type = "Int64"
+ column "elements_chain" {
+ type = "String"
}
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
+ column "person_id" {
+ type = "UUID"
}
- column "app_source" {
- type = "LowCardinality(String)"
+ column "person_properties" {
+ type = "JSON(max_dynamic_types=6, max_dynamic_paths=32, `$app_version` Nullable(String), `$browser` Nullable(String), `$current_url` Nullable(String), `$geoip_continent_name` Nullable(String), `$geoip_country_code` Nullable(String), `$geoip_country_name` Nullable(String), `$initial_current_url` Nullable(String), `$initial_fbclid` Nullable(String), `$initial_gad_source` Nullable(String), `$initial_gbraid` Nullable(String), `$initial_gclid` Nullable(String), `$initial_msclkid` Nullable(String), `$initial_pathname` Nullable(String), `$initial_referring_domain` Nullable(String), `$initial_utm_campaign` Nullable(String), `$initial_utm_content` Nullable(String), `$initial_utm_medium` Nullable(String), `$initial_utm_source` Nullable(String), `$initial_utm_term` Nullable(String), `$initial_wbraid` Nullable(String), `$os_name` Nullable(String), `$referring_domain` Nullable(String))"
}
- column "app_source_id" {
+ column "group0_properties" {
type = "String"
+ codec = "ZSTD(3)"
}
- column "instance_id" {
+ column "group1_properties" {
type = "String"
+ codec = "ZSTD(3)"
}
- column "metric_kind" {
- type = "LowCardinality(String)"
- }
- column "metric_name" {
- type = "LowCardinality(String)"
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "count" {
- type = "SimpleAggregateFunction(sum, Int64)"
+ 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 "person_created_at" {
+ type = "DateTime64(3)"
}
- column "_partition" {
- type = "UInt64"
+ column "group0_created_at" {
+ type = "DateTime64(3)"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_app_metrics2"
- sharding_key = "rand()"
+ column "group1_created_at" {
+ type = "DateTime64(3)"
}
- }
- table "channel_definition" {
- order_by = ["domain", "kind"]
- settings = {
- index_granularity = "8192"
+ column "group2_created_at" {
+ type = "DateTime64(3)"
}
- column "domain" {
- type = "String"
+ column "group3_created_at" {
+ type = "DateTime64(3)"
}
- column "kind" {
- type = "String"
+ column "group4_created_at" {
+ type = "DateTime64(3)"
}
- column "domain_type" {
- type = "Nullable(String)"
+ column "inserted_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ default = "now64()"
}
- column "type_if_paid" {
- type = "Nullable(String)"
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
}
- column "type_if_organic" {
- type = "Nullable(String)"
+ column "is_deleted" {
+ type = "Bool"
+ default = "false"
}
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.channel_definition"
- replica_name = "{replica}-{shard}"
+ column "consumer_breadcrumbs" {
+ type = "Array(String)"
}
- }
- table "clickhouse_cleanup_deleted_persons" {
- partition_by = "run_id"
- order_by = ["run_id", "team_id", "person_id"]
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
+ column "historical_migration" {
+ type = "Bool"
+ default = "false"
}
- column "run_id" {
+ column "$group_0" {
type = "String"
}
- column "team_id" {
- type = "Int64"
- }
- column "person_id" {
- type = "UUID"
+ column "$group_1" {
+ type = "String"
}
- column "max_version" {
- type = "UInt64"
+ column "$group_2" {
+ type = "String"
}
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
+ column "$group_3" {
+ type = "String"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
+ column "$group_4" {
+ type = "String"
}
- }
- table "clickhouse_cleanup_orphaned_distinct_ids" {
- partition_by = "run_id"
- order_by = ["run_id", "team_id", "distinct_id"]
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
+ column "$window_id" {
+ type = "String"
}
- column "run_id" {
+ column "$session_id" {
type = "String"
}
- column "team_id" {
- type = "Int64"
+ column "$session_id_uuid" {
+ type = "Nullable(UInt128)"
}
- column "distinct_id" {
+ column "elements_chain_href" {
type = "String"
}
- column "person_id" {
- type = "UUID"
- }
- column "own_tombstone" {
- type = "UInt8"
+ column "elements_chain_texts" {
+ type = "Array(String)"
}
- column "max_version" {
- type = "Int64"
+ column "elements_chain_ids" {
+ type = "Array(String)"
}
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
+ column "elements_chain_elements" {
+ type = "Array(Enum8('a'=1, 'button'=2, 'form'=3, 'input'=4, 'select'=5, 'textarea'=6, 'label'=7))"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events_json"
+ sharding_key = "sipHash64(distinct_id)"
}
}
- table "clickhouse_cleanup_revived_distinct_ids" {
- partition_by = "run_id"
- order_by = ["run_id", "team_id", "distinct_id"]
- ttl = "created_at + toIntervalDay(14)"
+ table "sharded_events_json" {
+ order_by = ["team_id", "toDate(timestamp)", "event", "timestamp", "cityHash64(distinct_id)", "distinct_id", "uuid"]
+ partition_by = "toYYYYMM(timestamp)"
+ primary_key = ["team_id", "toDate(timestamp)", "event", "timestamp", "cityHash64(distinct_id)"]
+ sample_by = "cityHash64(distinct_id)"
settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
+ index_granularity = "8192"
+ merge_max_block_size = "131072"
+ merge_max_block_size_bytes = "67108864"
+ object_serialization_version = "v3"
+ object_shared_data_serialization_version = "map_with_buckets"
+ object_shared_data_serialization_version_for_zero_level_parts = "map"
+ vertical_merge_algorithm_min_rows_to_activate = "0"
+ }
+ column "uuid" {
+ type = "UUID"
}
- column "run_id" {
+ column "event" {
type = "String"
}
+ column "properties" {
+ type = "JSON(max_dynamic_types=8, max_dynamic_paths=256, `$active_feature_flags` Array(String), `$ai_experiment_id` Nullable(String), `$ai_http_status` Nullable(String), `$ai_is_error` Nullable(String), `$ai_model` Nullable(String), `$ai_parent_id` Nullable(String), `$ai_prompt_name` Nullable(String), `$ai_provider` Nullable(String), `$ai_session_id` Nullable(String), `$ai_span_id` Nullable(String), `$ai_total_cost_usd` Nullable(String), `$ai_trace_id` Nullable(String), `$anon_distinct_id` Nullable(String), `$app_build` Nullable(String), `$app_namespace` Nullable(String), `$app_version` Nullable(String), `$browser` Nullable(String), `$browser_version` Nullable(String), `$current_url` Nullable(String), `$device` Nullable(String), `$device_id` Nullable(String), `$device_model` Nullable(String), `$device_type` Nullable(String), `$el_text` Nullable(String), `$event_type` Nullable(String), `$exception_fingerprint` Nullable(String), `$exception_functions` Array(String), `$exception_issue_id` Nullable(String), `$exception_sources` Array(String), `$exception_types` Array(String), `$exception_values` Array(String), `$feature_flag` Nullable(String), `$feature_flag_payloads` Nullable(String), `$feature_flag_response` Nullable(String), `$geoip_city_name` Nullable(String), `$geoip_country_code` Nullable(String), `$geoip_country_name` Nullable(String), `$geoip_subdivision_1_code` Nullable(String), `$group_0` Nullable(String), `$group_1` Nullable(String), `$group_2` Nullable(String), `$group_3` Nullable(String), `$group_4` Nullable(String), `$groups` Nullable(String), `$host` Nullable(String), `$initial_pathname` Nullable(String), `$initial_referrer` Nullable(String), `$initial_referring_domain` Nullable(String), `$ip` Nullable(String), `$is_identified` Nullable(String), `$lib` Nullable(String), `$lib_custom_api_host` Nullable(String), `$lib_version` Nullable(String), `$lib_version__minor` Nullable(String), `$os` Nullable(String), `$os_name` Nullable(String), `$os_version` Nullable(String), `$pathname` Nullable(String), `$prev_pageview_max_content_percentage` Nullable(String), `$prev_pageview_max_scroll_percentage` Nullable(String), `$prev_pageview_pathname` Nullable(String), `$process_person_profile` Nullable(String), `$referrer` Nullable(String), `$referring_domain` Nullable(String), `$screen_height` Nullable(String), `$screen_name` Nullable(String), `$screen_width` Nullable(String), `$sent_at` Nullable(String), `$session_id` Nullable(String), `$survey_id` Nullable(String), `$survey_response` Nullable(String), `$survey_response_1` Nullable(String), `$time` Nullable(String), `$user_id` Nullable(String), `$viewport_height` Nullable(String), `$viewport_width` Nullable(String), `$web_vitals_CLS_value` Nullable(String), `$web_vitals_FCP_value` Nullable(String), `$web_vitals_INP_value` Nullable(String), `$web_vitals_LCP_value` Nullable(String), `$window_id` Nullable(String))"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
column "team_id" {
type = "Int64"
}
column "distinct_id" {
type = "String"
}
+ column "elements_hash" {
+ type = "String"
+ default = "''"
+ }
column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
+ type = "DateTime64(6, 'UTC')"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
+ column "_timestamp" {
+ type = "DateTime"
}
- }
- table "clickhouse_cleanup_revived_persons" {
- partition_by = "run_id"
- order_by = ["run_id", "team_id", "person_id"]
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
+ column "_offset" {
+ type = "UInt64"
}
- column "run_id" {
+ column "elements_chain" {
type = "String"
}
- column "team_id" {
- type = "Int64"
- }
column "person_id" {
type = "UUID"
}
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
+ column "person_properties" {
+ type = "JSON(max_dynamic_types=6, max_dynamic_paths=32, `$app_version` Nullable(String), `$browser` Nullable(String), `$current_url` Nullable(String), `$geoip_continent_name` Nullable(String), `$geoip_country_code` Nullable(String), `$geoip_country_name` Nullable(String), `$initial_current_url` Nullable(String), `$initial_fbclid` Nullable(String), `$initial_gad_source` Nullable(String), `$initial_gbraid` Nullable(String), `$initial_gclid` Nullable(String), `$initial_msclkid` Nullable(String), `$initial_pathname` Nullable(String), `$initial_referring_domain` Nullable(String), `$initial_utm_campaign` Nullable(String), `$initial_utm_content` Nullable(String), `$initial_utm_medium` Nullable(String), `$initial_utm_source` Nullable(String), `$initial_utm_term` Nullable(String), `$initial_wbraid` Nullable(String), `$os_name` Nullable(String), `$referring_domain` Nullable(String))"
}
- }
- table "cohort_membership" {
- order_by = ["team_id", "cohort_id", "person_id"]
- settings = {
- index_granularity = "8192"
+ column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "team_id" {
- type = "Int64"
+ column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "cohort_id" {
- type = "Int64"
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "person_id" {
- type = "UUID"
+ column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "status" {
- type = "Enum8('entered'=1, 'left'=2)"
- }
- column "last_updated" {
- type = "DateTime64(6)"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.cohort_membership"
- replica_name = "{replica}-{shard}"
- version_column = "last_updated"
- }
- }
- table "distinct_id_usage" {
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "minute" {
- type = "DateTime"
- }
- column "event_count" {
- type = "UInt64"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_distinct_id_usage"
- sharding_key = "sipHash64(distinct_id)"
- }
- }
- table "distributed_events_recent" {
- column "uuid" {
- type = "UUID"
- }
- column "event" {
+ column "group4_properties" {
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)"
}
@@ -384,452 +231,535 @@ database "posthog" {
column "group4_created_at" {
type = "DateTime64(3)"
}
+ column "inserted_at" {
+ type = "Nullable(DateTime64(6, 'UTC'))"
+ default = "now64()"
+ }
column "person_mode" {
type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
}
- column "historical_migration" {
+ column "is_deleted" {
type = "Bool"
+ default = "false"
}
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "inserted_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
+ column "consumer_breadcrumbs" {
+ type = "Array(String)"
}
- engine "distributed" {
- cluster_name = "posthog_primary_replica"
- remote_database = "posthog"
- remote_table = "sharded_events_recent"
- sharding_key = "sipHash64(distinct_id)"
+ column "historical_migration" {
+ type = "Bool"
+ default = "false"
}
- }
- table "distributed_posthog_document_embeddings" {
- column "team_id" {
- type = "Int64"
+ column "$group_0" {
+ type = "String"
+ alias = "ifNull(properties.`$group_0`, '')"
}
- column "product" {
- type = "LowCardinality(String)"
+ column "$group_1" {
+ type = "String"
+ alias = "ifNull(properties.`$group_1`, '')"
}
- column "document_type" {
- type = "LowCardinality(String)"
+ column "$group_2" {
+ type = "String"
+ alias = "ifNull(properties.`$group_2`, '')"
}
- column "model_name" {
- type = "LowCardinality(String)"
+ column "$group_3" {
+ type = "String"
+ alias = "ifNull(properties.`$group_3`, '')"
}
- column "rendering" {
- type = "LowCardinality(String)"
+ column "$group_4" {
+ type = "String"
+ alias = "ifNull(properties.`$group_4`, '')"
}
- column "document_id" {
+ column "$window_id" {
type = "String"
+ alias = "ifNull(properties.`$window_id`, '')"
}
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
+ column "$session_id" {
+ type = "String"
+ alias = "ifNull(properties.`$session_id`, '')"
}
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
+ column "$session_id_uuid" {
+ type = "Nullable(UInt128)"
+ alias = "toUInt128(toUUIDOrNull(properties.`$session_id`))"
}
- column "content" {
- type = "String"
- default = "''"
+ column "elements_chain_href" {
+ type = "String"
+ materialized = "EXTRACT(elements_chain, '(?::|\")href=\"(.*?)\"')"
}
- column "metadata" {
- type = "String"
- default = "'{}'"
+ column "elements_chain_texts" {
+ type = "Array(String)"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")text=\"(.*?)\"'))"
}
- column "embedding" {
- type = "Array(Float64)"
+ column "elements_chain_ids" {
+ type = "Array(String)"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
}
- column "_timestamp" {
- type = "DateTime"
+ 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 "_offset" {
- type = "UInt64"
+ index "kafka_timestamp_minmax_sharded_events" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
}
- column "_partition" {
- type = "UInt64"
+ index "minmax_$group_0" {
+ expr = "properties.`$group_0`"
+ type = "minmax"
+ granularity = 1
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "partitioned_sharded_posthog_document_embeddings"
- sharding_key = "cityHash64(document_id)"
+ index "minmax_$group_1" {
+ expr = "properties.`$group_1`"
+ type = "minmax"
+ granularity = 1
}
- }
- table "distributed_posthog_document_embeddings_text_embedding_3_large_3072" {
- column "team_id" {
- type = "Int64"
+ index "minmax_$group_2" {
+ expr = "properties.`$group_2`"
+ type = "minmax"
+ granularity = 1
}
- column "product" {
- type = "LowCardinality(String)"
+ index "minmax_$group_3" {
+ expr = "properties.`$group_3`"
+ type = "minmax"
+ granularity = 1
}
- column "document_type" {
- type = "LowCardinality(String)"
+ index "minmax_$group_4" {
+ expr = "properties.`$group_4`"
+ type = "minmax"
+ granularity = 1
}
- column "rendering" {
- type = "LowCardinality(String)"
+ index "minmax_$window_id" {
+ expr = "properties.`$window_id`"
+ type = "minmax"
+ granularity = 1
}
- column "document_id" {
- type = "String"
+ index "minmax_$session_id" {
+ expr = "properties.`$session_id`"
+ type = "minmax"
+ granularity = 1
}
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
+ index "minmax_mat_$sent_at" {
+ expr = "properties.`$sent_at`"
+ type = "minmax"
+ granularity = 1
}
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
+ index "minmax_mat_$initial_pathname" {
+ expr = "properties.`$initial_pathname`"
+ type = "minmax"
+ granularity = 1
}
- column "content" {
- type = "String"
- default = "''"
+ index "minmax_mat_$lib_version" {
+ expr = "properties.`$lib_version`"
+ type = "minmax"
+ granularity = 1
}
- column "metadata" {
- type = "String"
- default = "'{}'"
+ index "minmax_mat_pp_$initial_utm_campaign" {
+ expr = "person_properties.`$initial_utm_campaign`"
+ type = "minmax"
+ granularity = 1
}
- column "embedding" {
- type = "Array(Float64)"
+ index "minmax_mat_pp_$initial_utm_medium" {
+ expr = "person_properties.`$initial_utm_medium`"
+ type = "minmax"
+ granularity = 1
}
- column "_timestamp" {
- type = "DateTime"
+ index "minmax_mat_pp_$initial_gclid" {
+ expr = "person_properties.`$initial_gclid`"
+ type = "minmax"
+ granularity = 1
}
- column "_offset" {
- type = "UInt64"
+ index "minmax_mat_pp_$initial_gad_source" {
+ expr = "person_properties.`$initial_gad_source`"
+ type = "minmax"
+ granularity = 1
}
- column "_partition" {
- type = "UInt64"
+ index "minmax_mat_pp_$initial_utm_source" {
+ expr = "person_properties.`$initial_utm_source`"
+ type = "minmax"
+ granularity = 1
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_posthog_document_embeddings_text_embedding_3_large_3072"
- sharding_key = "cityHash64(document_id)"
- }
- }
- table "distributed_posthog_document_embeddings_text_embedding_3_small_1536" {
- column "team_id" {
- type = "Int64"
+ index "minmax_mat_pp_$initial_referring_domain" {
+ expr = "person_properties.`$initial_referring_domain`"
+ type = "minmax"
+ granularity = 1
}
- column "product" {
- type = "LowCardinality(String)"
+ index "minmax_mat_pp_$initial_utm_term" {
+ expr = "person_properties.`$initial_utm_term`"
+ type = "minmax"
+ granularity = 1
}
- column "document_type" {
- type = "LowCardinality(String)"
+ index "minmax_mat_pp_$initial_utm_content" {
+ expr = "person_properties.`$initial_utm_content`"
+ type = "minmax"
+ granularity = 1
}
- column "rendering" {
- type = "LowCardinality(String)"
+ index "minmax_mat_pp_$initial_gbraid" {
+ expr = "person_properties.`$initial_gbraid`"
+ type = "minmax"
+ granularity = 1
}
- column "document_id" {
- type = "String"
+ index "minmax_mat_pp_$initial_wbraid" {
+ expr = "person_properties.`$initial_wbraid`"
+ type = "minmax"
+ granularity = 1
}
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
+ index "minmax_mat_pp_$initial_msclkid" {
+ expr = "person_properties.`$initial_msclkid`"
+ type = "minmax"
+ granularity = 1
}
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
+ index "minmax_mat_pp_$initial_fbclid" {
+ expr = "person_properties.`$initial_fbclid`"
+ type = "minmax"
+ granularity = 1
}
- column "content" {
- type = "String"
- default = "''"
+ index "minmax_mat_$geoip_subdivision_1_code" {
+ expr = "properties.`$geoip_subdivision_1_code`"
+ type = "minmax"
+ granularity = 1
}
- column "metadata" {
- type = "String"
- default = "'{}'"
+ index "minmax_mat_$prev_pageview_max_scroll_percentage" {
+ expr = "properties.`$prev_pageview_max_scroll_percentage`"
+ type = "minmax"
+ granularity = 1
}
- column "embedding" {
- type = "Array(Float64)"
+ index "minmax_mat_$prev_pageview_max_content_percentage" {
+ expr = "properties.`$prev_pageview_max_content_percentage`"
+ type = "minmax"
+ granularity = 1
}
- column "_timestamp" {
- type = "DateTime"
+ index "minmax_mat_$prev_pageview_pathname" {
+ expr = "properties.`$prev_pageview_pathname`"
+ type = "minmax"
+ granularity = 1
}
- column "_offset" {
- type = "UInt64"
+ index "minmax_mat_pp_$initial_pathname" {
+ expr = "person_properties.`$initial_pathname`"
+ type = "minmax"
+ granularity = 1
}
- column "_partition" {
- type = "UInt64"
+ index "minmax_mat_pp_$geoip_country_code" {
+ expr = "person_properties.`$geoip_country_code`"
+ type = "minmax"
+ granularity = 1
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_posthog_document_embeddings_text_embedding_3_small_1536"
- sharding_key = "cityHash64(document_id)"
+ index "minmax_mat_$browser_version" {
+ expr = "properties.`$browser_version`"
+ type = "minmax"
+ granularity = 1
}
- }
- table "distributed_system_processes" {
- settings = {
- skip_unavailable_shards = "1"
+ index "minmax_mat_pp_$initial_current_url" {
+ expr = "person_properties.`$initial_current_url`"
+ type = "minmax"
+ granularity = 1
}
- column "is_initial_query" {
- type = "UInt8"
+ index "minmax_mat_pp_$current_url" {
+ expr = "person_properties.`$current_url`"
+ type = "minmax"
+ granularity = 1
}
- column "user" {
- type = "String"
+ index "minmax_mat_$app_namespace" {
+ expr = "properties.`$app_namespace`"
+ type = "minmax"
+ granularity = 1
}
- column "query_id" {
- type = "String"
+ index "minmax_mat_$os_name" {
+ expr = "properties.`$os_name`"
+ type = "minmax"
+ granularity = 1
}
- column "address" {
- type = "IPv6"
+ index "minmax_mat_pp_$os_name" {
+ expr = "person_properties.`$os_name`"
+ type = "minmax"
+ granularity = 1
}
- column "port" {
- type = "UInt16"
+ index "minmax_mat_pp_$app_version" {
+ expr = "person_properties.`$app_version`"
+ type = "minmax"
+ granularity = 1
}
- column "initial_user" {
- type = "String"
+ index "minmax_mat_$screen_height" {
+ expr = "properties.`$screen_height`"
+ type = "minmax"
+ granularity = 1
}
- column "initial_query_id" {
- type = "String"
+ index "minmax_mat_$screen_width" {
+ expr = "properties.`$screen_width`"
+ type = "minmax"
+ granularity = 1
}
- column "initial_address" {
- type = "IPv6"
+ index "minmax_mat_$app_build" {
+ expr = "properties.`$app_build`"
+ type = "minmax"
+ granularity = 1
}
- column "initial_port" {
- type = "UInt16"
+ index "minmax_mat_$geoip_country_code" {
+ expr = "properties.`$geoip_country_code`"
+ type = "minmax"
+ granularity = 1
}
- column "interface" {
- type = "UInt8"
+ index "minmax_mat_$survey_id" {
+ expr = "properties.`$survey_id`"
+ type = "minmax"
+ granularity = 1
}
- column "os_user" {
- type = "String"
+ index "minmax_mat_$survey_response_1" {
+ expr = "properties.`$survey_response_1`"
+ type = "minmax"
+ granularity = 1
}
- column "client_hostname" {
- type = "String"
+ index "minmax_mat_$survey_response" {
+ expr = "properties.`$survey_response`"
+ type = "minmax"
+ granularity = 1
}
- column "client_name" {
- type = "String"
+ index "minmax_mat_$el_text" {
+ expr = "properties.`$el_text`"
+ type = "minmax"
+ granularity = 1
}
- column "client_agent" {
- type = "LowCardinality(String)"
+ index "minmax_mat_$os_version" {
+ expr = "properties.`$os_version`"
+ type = "minmax"
+ granularity = 1
}
- column "client_revision" {
- type = "UInt64"
+ index "minmax_mat_$feature_flag_payloads" {
+ expr = "properties.`$feature_flag_payloads`"
+ type = "minmax"
+ granularity = 1
}
- column "client_version_major" {
- type = "UInt64"
+ index "minmax_mat_$groups" {
+ expr = "properties.`$groups`"
+ type = "minmax"
+ granularity = 1
}
- column "client_version_minor" {
- type = "UInt64"
+ index "minmax_mat_$feature_flag" {
+ expr = "properties.`$feature_flag`"
+ type = "minmax"
+ granularity = 1
}
- column "client_version_patch" {
- type = "UInt64"
+ index "bf_active_feature_flags" {
+ expr = "properties.`$active_feature_flags`"
+ type = "bloom_filter(0.01)"
+ granularity = 1
}
- column "client_agent" {
- type = "LowCardinality(String)"
+ index "minmax_mat_$device_id" {
+ expr = "properties.`$device_id`"
+ type = "minmax"
+ granularity = 1
}
- column "http_method" {
- type = "UInt8"
+ index "minmax_mat_pp_$geoip_continent_name" {
+ expr = "person_properties.`$geoip_continent_name`"
+ type = "minmax"
+ granularity = 1
}
- column "http_user_agent" {
- type = "String"
+ index "minmax_mat_$feature_flag_response" {
+ expr = "properties.`$feature_flag_response`"
+ type = "minmax"
+ granularity = 1
}
- column "http_referer" {
- type = "String"
+ index "minmax_mat_pp_$referring_domain" {
+ expr = "person_properties.`$referring_domain`"
+ type = "minmax"
+ granularity = 1
}
- column "forwarded_for" {
- type = "String"
+ index "minmax_mat_$lib_version__minor" {
+ expr = "properties.`$lib_version__minor`"
+ type = "minmax"
+ granularity = 1
}
- column "quota_key" {
- type = "String"
+ index "minmax_inserted_at" {
+ expr = "coalesce(inserted_at, _timestamp)"
+ type = "minmax"
+ granularity = 1
}
- column "distributed_depth" {
- type = "UInt64"
+ index "minmax_mat_$lib_custom_api_host" {
+ expr = "properties.`$lib_custom_api_host`"
+ type = "minmax"
+ granularity = 1
}
- column "elapsed" {
- type = "Float64"
+ index "minmax_mat_pp_$geoip_country_name" {
+ expr = "person_properties.`$geoip_country_name`"
+ type = "minmax"
+ granularity = 1
}
- column "is_cancelled" {
- type = "UInt8"
+ index "is_deleted_idx" {
+ expr = "is_deleted"
+ type = "minmax"
+ granularity = 1
}
- column "is_all_data_sent" {
- type = "UInt8"
+ index "minmax_mat_$device" {
+ expr = "properties.`$device`"
+ type = "minmax"
+ granularity = 1
}
- column "read_rows" {
- type = "UInt64"
+ index "minmax_mat_$exception_issue_id" {
+ expr = "properties.`$exception_issue_id`"
+ type = "minmax"
+ granularity = 1
}
- column "read_bytes" {
- type = "UInt64"
+ index "minmax_mat_$exception_fingerprint" {
+ expr = "properties.`$exception_fingerprint`"
+ type = "minmax"
+ granularity = 1
}
- column "total_rows_approx" {
- type = "UInt64"
+ index "minmax_mat_$web_vitals_LCP_value" {
+ expr = "properties.`$web_vitals_LCP_value`"
+ type = "minmax"
+ granularity = 1
}
- column "written_rows" {
- type = "UInt64"
- }
- column "written_bytes" {
- type = "UInt64"
- }
- column "memory_usage" {
- type = "Int64"
- }
- column "peak_memory_usage" {
- type = "Int64"
- }
- column "query" {
- type = "String"
- }
- column "normalized_query_hash" {
- type = "UInt64"
- }
- column "query_kind" {
- type = "String"
- }
- column "thread_ids" {
- type = "Array(UInt64)"
- }
- column "peak_threads_usage" {
- type = "UInt64"
- }
- column "ProfileEvents" {
- type = "Map(LowCardinality(String), UInt64)"
- }
- column "Settings" {
- type = "Map(LowCardinality(String), LowCardinality(String))"
- }
- column "current_database" {
- type = "String"
- }
- column "is_internal" {
- type = "UInt8"
- }
- column "ProfileEvents.Names" {
- type = "Array(String)"
- alias = "mapKeys(ProfileEvents)"
- }
- column "ProfileEvents.Values" {
- type = "Array(UInt64)"
- alias = "mapValues(ProfileEvents)"
- }
- column "Settings.Names" {
- type = "Array(String)"
- alias = "mapKeys(Settings)"
- }
- column "Settings.Values" {
- type = "Array(String)"
- alias = "mapValues(Settings)"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "system"
- remote_table = "processes"
- }
- }
- table "duplicate_events" {
- order_by = ["team_id", "distinct_id", "event", "inserted_at"]
- partition_by = "toYYYYMMDD(inserted_at)"
- ttl = "inserted_at + toIntervalDay(7)"
- settings = {
- index_granularity = "512"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
+ index "minmax_mat_$web_vitals_FCP_value" {
+ expr = "properties.`$web_vitals_FCP_value`"
+ type = "minmax"
+ granularity = 1
}
- column "event" {
- type = "String"
+ index "minmax_mat_$web_vitals_CLS_value" {
+ expr = "properties.`$web_vitals_CLS_value`"
+ type = "minmax"
+ granularity = 1
}
- column "source_uuid" {
- type = "UUID"
+ index "minmax_mat_$web_vitals_INP_value" {
+ expr = "properties.`$web_vitals_INP_value`"
+ type = "minmax"
+ granularity = 1
}
- column "duplicate_uuid" {
- type = "UUID"
+ index "minmax_mat_$viewport_width" {
+ expr = "properties.`$viewport_width`"
+ type = "minmax"
+ granularity = 1
}
- column "similarity_score" {
- type = "Float64"
+ index "minmax_mat_$viewport_height" {
+ expr = "properties.`$viewport_height`"
+ type = "minmax"
+ granularity = 1
}
- column "dedup_type" {
- type = "LowCardinality(String)"
+ index "minmax_mat_$anon_distinct_id" {
+ expr = "properties.`$anon_distinct_id`"
+ type = "minmax"
+ granularity = 1
}
- column "is_confirmed" {
- type = "UInt8"
+ index "minmax_mat_$ai_trace_id" {
+ expr = "properties.`$ai_trace_id`"
+ type = "minmax"
+ granularity = 1
}
- column "reason" {
- type = "Nullable(String)"
+ index "minmax_mat_$ai_model" {
+ expr = "properties.`$ai_model`"
+ type = "minmax"
+ granularity = 1
}
- column "version" {
- type = "String"
+ index "minmax_mat_$ai_provider" {
+ expr = "properties.`$ai_provider`"
+ type = "minmax"
+ granularity = 1
}
- column "different_property_count" {
- type = "UInt32"
+ index "minmax_mat_$ai_parent_id" {
+ expr = "properties.`$ai_parent_id`"
+ type = "minmax"
+ granularity = 1
}
- column "properties_similarity" {
- type = "Float64"
+ index "minmax_mat_$ai_span_id" {
+ expr = "properties.`$ai_span_id`"
+ type = "minmax"
+ granularity = 1
}
- column "source_message" {
- type = "String"
+ index "minmax_mat_$ai_http_status" {
+ expr = "properties.`$ai_http_status`"
+ type = "minmax"
+ granularity = 1
}
- column "duplicate_message" {
- type = "String"
+ index "minmax_mat_$process_person_profile" {
+ expr = "properties.`$process_person_profile`"
+ type = "minmax"
+ granularity = 1
}
- column "distinct_fields" {
- type = "Array(Tuple(field_name String, original_value String, new_value String))"
+ index "minmax_mat_$app_version" {
+ expr = "properties.`$app_version`"
+ type = "minmax"
+ granularity = 1
}
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
+ index "bloom_mat_$is_identified" {
+ expr = "properties.`$is_identified`"
+ type = "bloom_filter"
+ granularity = 1
}
- column "_timestamp" {
- type = "DateTime"
+ index "minmax_$session_id_uuid" {
+ expr = "toUInt128(toUUIDOrNull(properties.`$session_id`))"
+ type = "minmax"
+ granularity = 1
}
- column "_offset" {
- type = "UInt64"
+ index "bloom_filter_$ai_trace_id" {
+ expr = "properties.`$ai_trace_id`"
+ type = "bloom_filter(0.001)"
+ granularity = 2
}
- column "_partition" {
- type = "UInt64"
+ index "bloom_filter_$ai_session_id" {
+ expr = "properties.`$ai_session_id`"
+ type = "bloom_filter"
+ granularity = 1
}
- index "kafka_timestamp_minmax_duplicate_events" {
- expr = "_timestamp"
+ index "minmax_$ai_session_id" {
+ expr = "properties.`$ai_session_id`"
type = "minmax"
- granularity = 3
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.duplicate_events"
- replica_name = "{replica}-{shard}"
+ granularity = 1
}
- }
- table "error_tracking_issue_fingerprint_overrides" {
- order_by = ["team_id", "fingerprint"]
- settings = {
- index_granularity = "512"
+ index "set_$ai_is_error" {
+ expr = "properties.`$ai_is_error`"
+ type = "set(7)"
+ granularity = 1
}
- column "team_id" {
- type = "Int64"
+ index "minmax_mat_$ai_total_cost_usd" {
+ expr = "properties.`$ai_total_cost_usd`"
+ type = "minmax"
+ granularity = 1
}
- column "fingerprint" {
- type = "String"
+ index "bloom_filter_distinct_id" {
+ expr = "distinct_id"
+ type = "bloom_filter"
+ granularity = 1
}
- column "issue_id" {
- type = "UUID"
+ index "minmax_sharded_events_timestamp" {
+ expr = "timestamp"
+ type = "minmax"
+ granularity = 1
}
- column "is_deleted" {
- type = "Int8"
+ index "minmax_historical_migration" {
+ expr = "historical_migration"
+ type = "minmax"
+ granularity = 1
}
- column "version" {
- type = "Int64"
+ index "bloom_mat_$feature_flag" {
+ expr = "properties.`$feature_flag`"
+ type = "bloom_filter"
+ granularity = 1
}
- column "_timestamp" {
- type = "DateTime"
+ index "bloom_filter_$ai_prompt_name" {
+ expr = "properties.`$ai_prompt_name`"
+ type = "bloom_filter"
+ granularity = 1
}
- column "_offset" {
- type = "UInt64"
+ index "minmax_$ai_prompt_name" {
+ expr = "properties.`$ai_prompt_name`"
+ type = "minmax"
+ granularity = 1
}
- column "_partition" {
- type = "UInt64"
+ index "bloom_filter_$ai_experiment_id" {
+ expr = "properties.`$ai_experiment_id`"
+ type = "bloom_filter"
+ granularity = 1
}
- index "kafka_timestamp_minmax_error_tracking_issue_fingerprint_overrides" {
- expr = "_timestamp"
+ index "minmax_$ai_experiment_id" {
+ expr = "properties.`$ai_experiment_id`"
type = "minmax"
- granularity = 3
+ granularity = 1
}
engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.error_tracking_issue_fingerprint_overrides"
- replica_name = "{replica}-{shard}"
- version_column = "version"
+ zoo_path = "/clickhouse/tables/{shard}/posthog.events_json"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
}
}
- table "events_json" {
+
+ table "kafka_events_json" {
column "uuid" {
type = "UUID"
}
@@ -837,7 +767,8 @@ database "posthog" {
type = "String"
}
column "properties" {
- type = "JSON(max_dynamic_types=8, max_dynamic_paths=256, `$active_feature_flags` Array(String), `$ai_experiment_id` Nullable(String), `$ai_http_status` Nullable(String), `$ai_is_error` Nullable(String), `$ai_model` Nullable(String), `$ai_parent_id` Nullable(String), `$ai_prompt_name` Nullable(String), `$ai_provider` Nullable(String), `$ai_session_id` Nullable(String), `$ai_span_id` Nullable(String), `$ai_total_cost_usd` Nullable(String), `$ai_trace_id` Nullable(String), `$anon_distinct_id` Nullable(String), `$app_build` Nullable(String), `$app_namespace` Nullable(String), `$app_version` Nullable(String), `$browser` Nullable(String), `$browser_version` Nullable(String), `$current_url` Nullable(String), `$device` Nullable(String), `$device_id` Nullable(String), `$device_model` Nullable(String), `$device_type` Nullable(String), `$el_text` Nullable(String), `$event_type` Nullable(String), `$exception_fingerprint` Nullable(String), `$exception_functions` Array(String), `$exception_issue_id` Nullable(String), `$exception_sources` Array(String), `$exception_types` Array(String), `$exception_values` Array(String), `$feature_flag` Nullable(String), `$feature_flag_payloads` Nullable(String), `$feature_flag_response` Nullable(String), `$geoip_city_name` Nullable(String), `$geoip_country_code` Nullable(String), `$geoip_country_name` Nullable(String), `$geoip_subdivision_1_code` Nullable(String), `$group_0` Nullable(String), `$group_1` Nullable(String), `$group_2` Nullable(String), `$group_3` Nullable(String), `$group_4` Nullable(String), `$groups` Nullable(String), `$host` Nullable(String), `$initial_pathname` Nullable(String), `$initial_referrer` Nullable(String), `$initial_referring_domain` Nullable(String), `$ip` Nullable(String), `$is_identified` Nullable(String), `$lib` Nullable(String), `$lib_custom_api_host` Nullable(String), `$lib_version` Nullable(String), `$lib_version__minor` Nullable(String), `$os` Nullable(String), `$os_name` Nullable(String), `$os_version` Nullable(String), `$pathname` Nullable(String), `$prev_pageview_max_content_percentage` Nullable(String), `$prev_pageview_max_scroll_percentage` Nullable(String), `$prev_pageview_pathname` Nullable(String), `$process_person_profile` Nullable(String), `$referrer` Nullable(String), `$referring_domain` Nullable(String), `$screen_height` Nullable(String), `$screen_name` Nullable(String), `$screen_width` Nullable(String), `$sent_at` Nullable(String), `$session_id` Nullable(String), `$survey_id` Nullable(String), `$survey_response` Nullable(String), `$survey_response_1` Nullable(String), `$time` Nullable(String), `$user_id` Nullable(String), `$viewport_height` Nullable(String), `$viewport_width` Nullable(String), `$web_vitals_CLS_value` Nullable(String), `$web_vitals_FCP_value` Nullable(String), `$web_vitals_INP_value` Nullable(String), `$web_vitals_LCP_value` Nullable(String), `$window_id` Nullable(String))"
+ type = "String"
+ codec = "ZSTD(3)"
}
column "timestamp" {
type = "DateTime64(6, 'UTC')"
@@ -848,51 +779,42 @@ database "posthog" {
column "distinct_id" {
type = "String"
}
- column "elements_hash" {
+ column "elements_chain" {
type = "String"
- default = "''"
}
column "created_at" {
type = "DateTime64(6, 'UTC')"
}
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "elements_chain" {
- type = "String"
- }
column "person_id" {
type = "UUID"
}
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ }
column "person_properties" {
- type = "JSON(max_dynamic_types=6, max_dynamic_paths=32, `$app_version` Nullable(String), `$browser` Nullable(String), `$current_url` Nullable(String), `$geoip_continent_name` Nullable(String), `$geoip_country_code` Nullable(String), `$geoip_country_name` Nullable(String), `$initial_current_url` Nullable(String), `$initial_fbclid` Nullable(String), `$initial_gad_source` Nullable(String), `$initial_gbraid` Nullable(String), `$initial_gclid` Nullable(String), `$initial_msclkid` Nullable(String), `$initial_pathname` Nullable(String), `$initial_referring_domain` Nullable(String), `$initial_utm_campaign` Nullable(String), `$initial_utm_content` Nullable(String), `$initial_utm_medium` Nullable(String), `$initial_utm_source` Nullable(String), `$initial_utm_term` Nullable(String), `$initial_wbraid` Nullable(String), `$os_name` Nullable(String), `$referring_domain` Nullable(String))"
+ type = "String"
+ codec = "ZSTD(3)"
}
column "group0_properties" {
- type = "String"
+ type = "String"
codec = "ZSTD(3)"
}
column "group1_properties" {
- type = "String"
+ type = "String"
codec = "ZSTD(3)"
}
column "group2_properties" {
- type = "String"
+ type = "String"
codec = "ZSTD(3)"
}
column "group3_properties" {
- type = "String"
+ type = "String"
codec = "ZSTD(3)"
}
column "group4_properties" {
- type = "String"
+ type = "String"
codec = "ZSTD(3)"
}
- column "person_created_at" {
- type = "DateTime64(3)"
- }
column "group0_created_at" {
type = "DateTime64(3)"
}
@@ -908,952 +830,891 @@ database "posthog" {
column "group4_created_at" {
type = "DateTime64(3)"
}
- column "inserted_at" {
- type = "Nullable(DateTime64(6, 'UTC'))"
- default = "now64()"
- }
column "person_mode" {
type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
}
- column "is_deleted" {
+ column "historical_migration" {
type = "Bool"
- default = "false"
}
- column "consumer_breadcrumbs" {
- type = "Array(String)"
+ column "dmat_string_0" {
+ type = "Nullable(String)"
}
- column "historical_migration" {
- type = "Bool"
- default = "false"
- }
- column "$group_0" {
- type = "String"
- }
- column "$group_1" {
- type = "String"
- }
- column "$group_2" {
- type = "String"
- }
- column "$group_3" {
- type = "String"
+ column "dmat_string_1" {
+ type = "Nullable(String)"
}
- column "$group_4" {
- type = "String"
+ column "dmat_string_2" {
+ type = "Nullable(String)"
}
- column "$window_id" {
- type = "String"
+ column "dmat_string_3" {
+ type = "Nullable(String)"
}
- column "$session_id" {
- type = "String"
+ column "dmat_string_4" {
+ type = "Nullable(String)"
}
- column "$session_id_uuid" {
- type = "Nullable(UInt128)"
+ column "dmat_string_5" {
+ type = "Nullable(String)"
}
- column "elements_chain_href" {
- type = "String"
+ column "dmat_string_6" {
+ type = "Nullable(String)"
}
- column "elements_chain_texts" {
- type = "Array(String)"
+ column "dmat_string_7" {
+ type = "Nullable(String)"
}
- column "elements_chain_ids" {
- type = "Array(String)"
+ column "dmat_string_8" {
+ type = "Nullable(String)"
}
- column "elements_chain_elements" {
- type = "Array(Enum8('a'=1, 'button'=2, 'form'=3, 'input'=4, 'select'=5, 'textarea'=6, 'label'=7))"
+ column "dmat_string_9" {
+ type = "Nullable(String)"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_events_json"
- sharding_key = "sipHash64(distinct_id)"
+ engine "kafka" {
+ collection = "msk_cluster"
+ topic_list = "clickhouse_events_json"
+ group_name = "group1"
+ format = "JSONEachRow"
+ skip_broken_messages = 100
}
}
- table "sharded_events_json" {
- order_by = ["team_id", "toDate(timestamp)", "event", "timestamp", "cityHash64(distinct_id)", "distinct_id", "uuid"]
- partition_by = "toYYYYMM(timestamp)"
- primary_key = ["team_id", "toDate(timestamp)", "event", "timestamp", "cityHash64(distinct_id)"]
- sample_by = "cityHash64(distinct_id)"
- settings = {
- index_granularity = "8192"
- merge_max_block_size = "131072"
- merge_max_block_size_bytes = "67108864"
- object_serialization_version = "v3"
- object_shared_data_serialization_version = "map_with_buckets"
- object_shared_data_serialization_version_for_zero_level_parts = "map"
- vertical_merge_algorithm_min_rows_to_activate = "0"
- }
+ table "kafka_performance_events" {
column "uuid" {
type = "UUID"
}
- column "event" {
+ column "session_id" {
type = "String"
}
- column "properties" {
- type = "JSON(max_dynamic_types=8, max_dynamic_paths=256, `$active_feature_flags` Array(String), `$ai_experiment_id` Nullable(String), `$ai_http_status` Nullable(String), `$ai_is_error` Nullable(String), `$ai_model` Nullable(String), `$ai_parent_id` Nullable(String), `$ai_prompt_name` Nullable(String), `$ai_provider` Nullable(String), `$ai_session_id` Nullable(String), `$ai_span_id` Nullable(String), `$ai_total_cost_usd` Nullable(String), `$ai_trace_id` Nullable(String), `$anon_distinct_id` Nullable(String), `$app_build` Nullable(String), `$app_namespace` Nullable(String), `$app_version` Nullable(String), `$browser` Nullable(String), `$browser_version` Nullable(String), `$current_url` Nullable(String), `$device` Nullable(String), `$device_id` Nullable(String), `$device_model` Nullable(String), `$device_type` Nullable(String), `$el_text` Nullable(String), `$event_type` Nullable(String), `$exception_fingerprint` Nullable(String), `$exception_functions` Array(String), `$exception_issue_id` Nullable(String), `$exception_sources` Array(String), `$exception_types` Array(String), `$exception_values` Array(String), `$feature_flag` Nullable(String), `$feature_flag_payloads` Nullable(String), `$feature_flag_response` Nullable(String), `$geoip_city_name` Nullable(String), `$geoip_country_code` Nullable(String), `$geoip_country_name` Nullable(String), `$geoip_subdivision_1_code` Nullable(String), `$group_0` Nullable(String), `$group_1` Nullable(String), `$group_2` Nullable(String), `$group_3` Nullable(String), `$group_4` Nullable(String), `$groups` Nullable(String), `$host` Nullable(String), `$initial_pathname` Nullable(String), `$initial_referrer` Nullable(String), `$initial_referring_domain` Nullable(String), `$ip` Nullable(String), `$is_identified` Nullable(String), `$lib` Nullable(String), `$lib_custom_api_host` Nullable(String), `$lib_version` Nullable(String), `$lib_version__minor` Nullable(String), `$os` Nullable(String), `$os_name` Nullable(String), `$os_version` Nullable(String), `$pathname` Nullable(String), `$prev_pageview_max_content_percentage` Nullable(String), `$prev_pageview_max_scroll_percentage` Nullable(String), `$prev_pageview_pathname` Nullable(String), `$process_person_profile` Nullable(String), `$referrer` Nullable(String), `$referring_domain` Nullable(String), `$screen_height` Nullable(String), `$screen_name` Nullable(String), `$screen_width` Nullable(String), `$sent_at` Nullable(String), `$session_id` Nullable(String), `$survey_id` Nullable(String), `$survey_response` Nullable(String), `$survey_response_1` Nullable(String), `$time` Nullable(String), `$user_id` Nullable(String), `$viewport_height` Nullable(String), `$viewport_width` Nullable(String), `$web_vitals_CLS_value` Nullable(String), `$web_vitals_FCP_value` Nullable(String), `$web_vitals_INP_value` Nullable(String), `$web_vitals_LCP_value` Nullable(String), `$window_id` Nullable(String))"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
+ column "window_id" {
+ type = "String"
}
- column "team_id" {
- type = "Int64"
+ column "pageview_id" {
+ type = "String"
}
column "distinct_id" {
type = "String"
}
- column "elements_hash" {
- type = "String"
- default = "''"
+ column "timestamp" {
+ type = "DateTime64(3)"
}
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
+ column "time_origin" {
+ type = "DateTime64(3, 'UTC')"
}
- column "_timestamp" {
- type = "DateTime"
+ column "entry_type" {
+ type = "LowCardinality(String)"
}
- column "_offset" {
- type = "UInt64"
+ column "name" {
+ type = "String"
}
- column "elements_chain" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "current_url" {
type = "String"
}
- column "person_id" {
- type = "UUID"
+ column "start_time" {
+ type = "Float64"
}
- column "person_properties" {
- type = "JSON(max_dynamic_types=6, max_dynamic_paths=32, `$app_version` Nullable(String), `$browser` Nullable(String), `$current_url` Nullable(String), `$geoip_continent_name` Nullable(String), `$geoip_country_code` Nullable(String), `$geoip_country_name` Nullable(String), `$initial_current_url` Nullable(String), `$initial_fbclid` Nullable(String), `$initial_gad_source` Nullable(String), `$initial_gbraid` Nullable(String), `$initial_gclid` Nullable(String), `$initial_msclkid` Nullable(String), `$initial_pathname` Nullable(String), `$initial_referring_domain` Nullable(String), `$initial_utm_campaign` Nullable(String), `$initial_utm_content` Nullable(String), `$initial_utm_medium` Nullable(String), `$initial_utm_source` Nullable(String), `$initial_utm_term` Nullable(String), `$initial_wbraid` Nullable(String), `$os_name` Nullable(String), `$referring_domain` Nullable(String))"
+ column "duration" {
+ type = "Float64"
}
- column "group0_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "redirect_start" {
+ type = "Float64"
}
- column "group1_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "redirect_end" {
+ type = "Float64"
}
- column "group2_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "worker_start" {
+ type = "Float64"
}
- column "group3_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "fetch_start" {
+ type = "Float64"
}
- column "group4_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "domain_lookup_start" {
+ type = "Float64"
}
- column "person_created_at" {
- type = "DateTime64(3)"
+ column "domain_lookup_end" {
+ type = "Float64"
}
- column "group0_created_at" {
- type = "DateTime64(3)"
+ column "connect_start" {
+ type = "Float64"
}
- column "group1_created_at" {
- type = "DateTime64(3)"
+ column "secure_connection_start" {
+ type = "Float64"
}
- column "group2_created_at" {
- type = "DateTime64(3)"
+ column "connect_end" {
+ type = "Float64"
}
- column "group3_created_at" {
- type = "DateTime64(3)"
+ column "request_start" {
+ type = "Float64"
}
- column "group4_created_at" {
- type = "DateTime64(3)"
+ column "response_start" {
+ type = "Float64"
}
- column "inserted_at" {
- type = "Nullable(DateTime64(6, 'UTC'))"
- default = "now64()"
+ column "response_end" {
+ type = "Float64"
}
- column "person_mode" {
- type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ column "decoded_body_size" {
+ type = "Int64"
}
- column "is_deleted" {
- type = "Bool"
- default = "false"
+ column "encoded_body_size" {
+ type = "Int64"
}
- column "consumer_breadcrumbs" {
- type = "Array(String)"
+ column "initiator_type" {
+ type = "LowCardinality(String)"
}
- column "historical_migration" {
- type = "Bool"
- default = "false"
+ column "next_hop_protocol" {
+ type = "LowCardinality(String)"
}
- column "$group_0" {
- type = "String"
- alias = "ifNull(properties.`$group_0`, '')"
+ column "render_blocking_status" {
+ type = "LowCardinality(String)"
}
- column "$group_1" {
- type = "String"
- alias = "ifNull(properties.`$group_1`, '')"
+ column "response_status" {
+ type = "Int64"
}
- column "$group_2" {
- type = "String"
- alias = "ifNull(properties.`$group_2`, '')"
+ column "transfer_size" {
+ type = "Int64"
}
- column "$group_3" {
+ column "largest_contentful_paint_element" {
type = "String"
- alias = "ifNull(properties.`$group_3`, '')"
}
- column "$group_4" {
- type = "String"
- alias = "ifNull(properties.`$group_4`, '')"
+ column "largest_contentful_paint_render_time" {
+ type = "Float64"
}
- column "$window_id" {
+ column "largest_contentful_paint_load_time" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_size" {
+ type = "Float64"
+ }
+ column "largest_contentful_paint_id" {
type = "String"
- alias = "ifNull(properties.`$window_id`, '')"
}
- column "$session_id" {
+ column "largest_contentful_paint_url" {
type = "String"
- alias = "ifNull(properties.`$session_id`, '')"
}
- column "$session_id_uuid" {
- type = "Nullable(UInt128)"
- alias = "toUInt128(toUUIDOrNull(properties.`$session_id`))"
+ column "dom_complete" {
+ type = "Float64"
}
- column "elements_chain_href" {
- type = "String"
- materialized = "EXTRACT(elements_chain, '(?::|\")href=\"(.*?)\"')"
+ column "dom_content_loaded_event" {
+ type = "Float64"
}
- column "elements_chain_texts" {
- type = "Array(String)"
- materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")text=\"(.*?)\"'))"
+ column "dom_interactive" {
+ type = "Float64"
}
- column "elements_chain_ids" {
- type = "Array(String)"
- materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
+ column "load_event_end" {
+ type = "Float64"
}
- 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 "load_event_start" {
+ type = "Float64"
}
- index "kafka_timestamp_minmax_sharded_events" {
- expr = "_timestamp"
- type = "minmax"
- granularity = 3
+ column "redirect_count" {
+ type = "Int64"
}
- index "minmax_$group_0" {
- expr = "properties.`$group_0`"
- type = "minmax"
- granularity = 1
+ column "navigation_type" {
+ type = "LowCardinality(String)"
}
- index "minmax_$group_1" {
- expr = "properties.`$group_1`"
- type = "minmax"
- granularity = 1
+ column "unload_event_end" {
+ type = "Float64"
}
- index "minmax_$group_2" {
- expr = "properties.`$group_2`"
- type = "minmax"
- granularity = 1
+ column "unload_event_start" {
+ type = "Float64"
}
- index "minmax_$group_3" {
- expr = "properties.`$group_3`"
- type = "minmax"
- granularity = 1
+ engine "kafka" {
+ collection = "msk_cluster"
+ topic_list = "clickhouse_performance_events"
+ group_name = "group1"
+ format = "JSONEachRow"
}
- index "minmax_$group_4" {
- expr = "properties.`$group_4`"
- type = "minmax"
- granularity = 1
+ }
+ table "kafka_person_distinct_id" {
+ column "distinct_id" {
+ type = "String"
}
- index "minmax_$window_id" {
- expr = "properties.`$window_id`"
- type = "minmax"
- granularity = 1
+ column "person_id" {
+ type = "UUID"
}
- index "minmax_$session_id" {
- expr = "properties.`$session_id`"
- type = "minmax"
- granularity = 1
+ column "team_id" {
+ type = "Int64"
}
- index "minmax_mat_$sent_at" {
- expr = "properties.`$sent_at`"
- type = "minmax"
- granularity = 1
+ column "_sign" {
+ type = "Nullable(Int8)"
}
- index "minmax_mat_$initial_pathname" {
- expr = "properties.`$initial_pathname`"
- type = "minmax"
- granularity = 1
+ column "is_deleted" {
+ type = "Nullable(Int8)"
}
- index "minmax_mat_$lib_version" {
- expr = "properties.`$lib_version`"
- type = "minmax"
- granularity = 1
+ engine "kafka" {
+ collection = "msk_cluster"
+ topic_list = "clickhouse_person_unique_id"
+ group_name = "group1"
+ format = "JSONEachRow"
}
- index "minmax_mat_pp_$initial_utm_campaign" {
- expr = "person_properties.`$initial_utm_campaign`"
- type = "minmax"
- granularity = 1
+ }
+ table "kafka_person_overrides" {
+ column "team_id" {
+ type = "Int32"
}
- index "minmax_mat_pp_$initial_utm_medium" {
- expr = "person_properties.`$initial_utm_medium`"
- type = "minmax"
- granularity = 1
+ column "old_person_id" {
+ type = "UUID"
}
- index "minmax_mat_pp_$initial_gclid" {
- expr = "person_properties.`$initial_gclid`"
- type = "minmax"
- granularity = 1
+ column "override_person_id" {
+ type = "UUID"
}
- index "minmax_mat_pp_$initial_gad_source" {
- expr = "person_properties.`$initial_gad_source`"
- type = "minmax"
- granularity = 1
+ column "merged_at" {
+ type = "DateTime64(6, 'UTC')"
}
- index "minmax_mat_pp_$initial_utm_source" {
- expr = "person_properties.`$initial_utm_source`"
- type = "minmax"
- granularity = 1
+ column "oldest_event" {
+ type = "DateTime64(6, 'UTC')"
}
- index "minmax_mat_pp_$initial_referring_domain" {
- expr = "person_properties.`$initial_referring_domain`"
- type = "minmax"
- granularity = 1
+ column "version" {
+ type = "Int32"
}
- index "minmax_mat_pp_$initial_utm_term" {
- expr = "person_properties.`$initial_utm_term`"
- type = "minmax"
- granularity = 1
+ engine "kafka" {
+ broker_list = "kafka:9092"
+ topic_list = "clickhouse_person_override"
+ group_name = "clickhouse-person-overrides"
+ format = "JSONEachRow"
}
- index "minmax_mat_pp_$initial_utm_content" {
- expr = "person_properties.`$initial_utm_content`"
- type = "minmax"
- granularity = 1
+ }
+ table "partitioned_sharded_posthog_document_embeddings" {
+ order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "model_name", "rendering", "cityHash64(document_id)"]
+ partition_by = "toMonday(timestamp)"
+ ttl = "timestamp + toIntervalMonth(3)"
+ settings = {
+ index_granularity = "512"
+ ttl_only_drop_parts = "1"
}
- index "minmax_mat_pp_$initial_gbraid" {
- expr = "person_properties.`$initial_gbraid`"
- type = "minmax"
- granularity = 1
+ column "team_id" {
+ type = "Int64"
}
- index "minmax_mat_pp_$initial_wbraid" {
- expr = "person_properties.`$initial_wbraid`"
- type = "minmax"
- granularity = 1
+ column "product" {
+ type = "LowCardinality(String)"
}
- index "minmax_mat_pp_$initial_msclkid" {
- expr = "person_properties.`$initial_msclkid`"
- type = "minmax"
- granularity = 1
+ column "document_type" {
+ type = "LowCardinality(String)"
}
- index "minmax_mat_pp_$initial_fbclid" {
- expr = "person_properties.`$initial_fbclid`"
- type = "minmax"
- granularity = 1
+ column "model_name" {
+ type = "LowCardinality(String)"
}
- index "minmax_mat_$geoip_subdivision_1_code" {
- expr = "properties.`$geoip_subdivision_1_code`"
- type = "minmax"
- granularity = 1
+ column "rendering" {
+ type = "LowCardinality(String)"
}
- index "minmax_mat_$prev_pageview_max_scroll_percentage" {
- expr = "properties.`$prev_pageview_max_scroll_percentage`"
- type = "minmax"
- granularity = 1
+ column "document_id" {
+ type = "String"
}
- index "minmax_mat_$prev_pageview_max_content_percentage" {
- expr = "properties.`$prev_pageview_max_content_percentage`"
- type = "minmax"
- granularity = 1
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
}
- index "minmax_mat_$prev_pageview_pathname" {
- expr = "properties.`$prev_pageview_pathname`"
- type = "minmax"
- granularity = 1
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
}
- index "minmax_mat_pp_$initial_pathname" {
- expr = "person_properties.`$initial_pathname`"
- type = "minmax"
- granularity = 1
+ column "content" {
+ type = "String"
+ default = "''"
}
- index "minmax_mat_pp_$geoip_country_code" {
- expr = "person_properties.`$geoip_country_code`"
- type = "minmax"
- granularity = 1
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
}
- index "minmax_mat_$browser_version" {
- expr = "properties.`$browser_version`"
- type = "minmax"
- granularity = 1
+ column "embedding" {
+ type = "Array(Float64)"
}
- index "minmax_mat_pp_$initial_current_url" {
- expr = "person_properties.`$initial_current_url`"
- type = "minmax"
- granularity = 1
+ column "_timestamp" {
+ type = "DateTime"
}
- index "minmax_mat_pp_$current_url" {
- expr = "person_properties.`$current_url`"
- type = "minmax"
- granularity = 1
+ column "_offset" {
+ type = "UInt64"
}
- index "minmax_mat_$app_namespace" {
- expr = "properties.`$app_namespace`"
- type = "minmax"
- granularity = 1
+ column "_partition" {
+ type = "UInt64"
}
- index "minmax_mat_$os_name" {
- expr = "properties.`$os_name`"
+ index "kafka_timestamp_minmax_partitioned_sharded_posthog_document_embeddings" {
+ expr = "_timestamp"
type = "minmax"
- granularity = 1
+ granularity = 3
}
- index "minmax_mat_pp_$os_name" {
- expr = "person_properties.`$os_name`"
- type = "minmax"
- granularity = 1
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.partitioned_sharded_posthog_document_embeddings"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
}
- index "minmax_mat_pp_$app_version" {
- expr = "person_properties.`$app_version`"
- type = "minmax"
- granularity = 1
+ }
+ table "query_log_archive_v2" {
+ order_by = ["team_id", "event_date", "event_time", "query_id"]
+ partition_by = "toYYYYMM(event_date)"
+ settings = {
+ index_granularity = "8192"
}
- index "minmax_mat_$screen_height" {
- expr = "properties.`$screen_height`"
- type = "minmax"
- granularity = 1
+ column "hostname" {
+ type = "LowCardinality(String)"
}
- index "minmax_mat_$screen_width" {
- expr = "properties.`$screen_width`"
- type = "minmax"
- granularity = 1
+ column "user" {
+ type = "LowCardinality(String)"
}
- index "minmax_mat_$app_build" {
- expr = "properties.`$app_build`"
- type = "minmax"
- granularity = 1
+ column "query_id" {
+ type = "String"
}
- index "minmax_mat_$geoip_country_code" {
- expr = "properties.`$geoip_country_code`"
- type = "minmax"
- granularity = 1
+ column "initial_query_id" {
+ type = "String"
}
- index "minmax_mat_$survey_id" {
- expr = "properties.`$survey_id`"
- type = "minmax"
- granularity = 1
+ column "is_initial_query" {
+ type = "UInt8"
}
- index "minmax_mat_$survey_response_1" {
- expr = "properties.`$survey_response_1`"
- type = "minmax"
- granularity = 1
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
}
- index "minmax_mat_$survey_response" {
- expr = "properties.`$survey_response`"
- type = "minmax"
- granularity = 1
+ column "event_date" {
+ type = "Date"
}
- index "minmax_mat_$el_text" {
- expr = "properties.`$el_text`"
- type = "minmax"
- granularity = 1
+ column "event_time" {
+ type = "DateTime"
}
- index "minmax_mat_$os_version" {
- expr = "properties.`$os_version`"
- type = "minmax"
- granularity = 1
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
}
- index "minmax_mat_$feature_flag_payloads" {
- expr = "properties.`$feature_flag_payloads`"
- type = "minmax"
- granularity = 1
+ column "query_start_time" {
+ type = "DateTime"
}
- index "minmax_mat_$groups" {
- expr = "properties.`$groups`"
- type = "minmax"
- granularity = 1
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
}
- index "minmax_mat_$feature_flag" {
- expr = "properties.`$feature_flag`"
- type = "minmax"
- granularity = 1
+ column "query_duration_ms" {
+ type = "UInt64"
}
- index "bf_active_feature_flags" {
- expr = "properties.`$active_feature_flags`"
- type = "bloom_filter(0.01)"
- granularity = 1
+ column "read_rows" {
+ type = "UInt64"
}
- index "minmax_mat_$device_id" {
- expr = "properties.`$device_id`"
- type = "minmax"
- granularity = 1
+ column "read_bytes" {
+ type = "UInt64"
}
- index "minmax_mat_pp_$geoip_continent_name" {
- expr = "person_properties.`$geoip_continent_name`"
- type = "minmax"
- granularity = 1
+ column "written_rows" {
+ type = "UInt64"
}
- index "minmax_mat_$feature_flag_response" {
- expr = "properties.`$feature_flag_response`"
- type = "minmax"
- granularity = 1
+ column "written_bytes" {
+ type = "UInt64"
}
- index "minmax_mat_pp_$referring_domain" {
- expr = "person_properties.`$referring_domain`"
- type = "minmax"
- granularity = 1
+ column "result_rows" {
+ type = "UInt64"
}
- index "minmax_mat_$lib_version__minor" {
- expr = "properties.`$lib_version__minor`"
- type = "minmax"
- granularity = 1
+ column "result_bytes" {
+ type = "UInt64"
}
- index "minmax_inserted_at" {
- expr = "coalesce(inserted_at, _timestamp)"
- type = "minmax"
- granularity = 1
+ column "memory_usage" {
+ type = "UInt64"
}
- index "minmax_mat_$lib_custom_api_host" {
- expr = "properties.`$lib_custom_api_host`"
- type = "minmax"
- granularity = 1
+ column "peak_threads_usage" {
+ type = "UInt64"
}
- index "minmax_mat_pp_$geoip_country_name" {
- expr = "person_properties.`$geoip_country_name`"
- type = "minmax"
- granularity = 1
+ column "current_database" {
+ type = "LowCardinality(String)"
}
- index "is_deleted_idx" {
- expr = "is_deleted"
- type = "minmax"
- granularity = 1
+ column "query" {
+ type = "String"
}
- index "minmax_mat_$device" {
- expr = "properties.`$device`"
- type = "minmax"
- granularity = 1
+ column "formatted_query" {
+ type = "String"
}
- index "minmax_mat_$exception_issue_id" {
- expr = "properties.`$exception_issue_id`"
- type = "minmax"
- granularity = 1
+ column "normalized_query_hash" {
+ type = "UInt64"
}
- index "minmax_mat_$exception_fingerprint" {
- expr = "properties.`$exception_fingerprint`"
- type = "minmax"
- granularity = 1
+ column "query_kind" {
+ type = "LowCardinality(String)"
}
- index "minmax_mat_$web_vitals_LCP_value" {
- expr = "properties.`$web_vitals_LCP_value`"
- type = "minmax"
- granularity = 1
+ column "exception_code" {
+ type = "Int32"
}
- index "minmax_mat_$web_vitals_FCP_value" {
- expr = "properties.`$web_vitals_FCP_value`"
- type = "minmax"
- granularity = 1
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
}
- index "minmax_mat_$web_vitals_CLS_value" {
- expr = "properties.`$web_vitals_CLS_value`"
- type = "minmax"
- granularity = 1
+ column "exception" {
+ type = "String"
}
- index "minmax_mat_$web_vitals_INP_value" {
- expr = "properties.`$web_vitals_INP_value`"
- type = "minmax"
- granularity = 1
+ column "stack_trace" {
+ type = "String"
}
- index "minmax_mat_$viewport_width" {
- expr = "properties.`$viewport_width`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
}
- index "minmax_mat_$viewport_height" {
- expr = "properties.`$viewport_height`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
}
- index "minmax_mat_$anon_distinct_id" {
- expr = "properties.`$anon_distinct_id`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
}
- index "minmax_mat_$ai_trace_id" {
- expr = "properties.`$ai_trace_id`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
}
- index "minmax_mat_$ai_model" {
- expr = "properties.`$ai_model`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
}
- index "minmax_mat_$ai_provider" {
- expr = "properties.`$ai_provider`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
}
- index "minmax_mat_$ai_parent_id" {
- expr = "properties.`$ai_parent_id`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
}
- index "minmax_mat_$ai_span_id" {
- expr = "properties.`$ai_span_id`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
}
- index "minmax_mat_$ai_http_status" {
- expr = "properties.`$ai_http_status`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
}
- index "minmax_mat_$process_person_profile" {
- expr = "properties.`$process_person_profile`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
}
- index "minmax_mat_$app_version" {
- expr = "properties.`$app_version`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
}
- index "bloom_mat_$is_identified" {
- expr = "properties.`$is_identified`"
- type = "bloom_filter"
- granularity = 1
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
}
- index "minmax_$session_id_uuid" {
- expr = "toUInt128(toUUIDOrNull(properties.`$session_id`))"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
}
- index "bloom_filter_$ai_trace_id" {
- expr = "properties.`$ai_trace_id`"
- type = "bloom_filter(0.001)"
- granularity = 2
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
}
- index "bloom_filter_$ai_session_id" {
- expr = "properties.`$ai_session_id`"
- type = "bloom_filter"
- granularity = 1
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
}
- index "minmax_$ai_session_id" {
- expr = "properties.`$ai_session_id`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
}
- index "set_$ai_is_error" {
- expr = "properties.`$ai_is_error`"
- type = "set(7)"
- granularity = 1
- }
- index "minmax_mat_$ai_total_cost_usd" {
- expr = "properties.`$ai_total_cost_usd`"
- type = "minmax"
- granularity = 1
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
}
- index "bloom_filter_distinct_id" {
- expr = "distinct_id"
- type = "bloom_filter"
- granularity = 1
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
}
- index "minmax_sharded_events_timestamp" {
- expr = "timestamp"
- type = "minmax"
- granularity = 1
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
}
- index "minmax_historical_migration" {
- expr = "historical_migration"
- type = "minmax"
- granularity = 1
+ column "lc_kind" {
+ type = "LowCardinality(String)"
}
- index "bloom_mat_$feature_flag" {
- expr = "properties.`$feature_flag`"
- type = "bloom_filter"
- granularity = 1
+ column "lc_id" {
+ type = "String"
}
- index "bloom_filter_$ai_prompt_name" {
- expr = "properties.`$ai_prompt_name`"
- type = "bloom_filter"
- granularity = 1
+ column "lc_route_id" {
+ type = "String"
}
- index "minmax_$ai_prompt_name" {
- expr = "properties.`$ai_prompt_name`"
- type = "minmax"
- granularity = 1
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
}
- index "bloom_filter_$ai_experiment_id" {
- expr = "properties.`$ai_experiment_id`"
- type = "bloom_filter"
- granularity = 1
+ column "lc_api_key_label" {
+ type = "String"
}
- index "minmax_$ai_experiment_id" {
- expr = "properties.`$ai_experiment_id`"
- type = "minmax"
- granularity = 1
+ column "lc_api_key_mask" {
+ type = "String"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.events_json"
- replica_name = "{replica}"
- version_column = "_timestamp"
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
}
- }
-
- table "events_dead_letter_queue" {
- order_by = ["id", "event_uuid", "distinct_id", "team_id"]
- ttl = "toDate(_timestamp) + toIntervalWeek(4)"
- settings = {
- index_granularity = "512"
+ column "lc_product" {
+ type = "LowCardinality(String)"
}
- column "id" {
- type = "UUID"
+ column "lc_chargeable" {
+ type = "Bool"
}
- column "event_uuid" {
- type = "UUID"
+ column "lc_name" {
+ type = "String"
}
- column "event" {
+ column "lc_request_name" {
type = "String"
}
- column "properties" {
+ column "lc_client_query_id" {
type = "String"
}
- column "distinct_id" {
+ column "lc_org_id" {
type = "String"
}
column "team_id" {
type = "Int64"
}
- column "elements_chain" {
- type = "String"
+ column "lc_user_id" {
+ type = "Int64"
}
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
+ column "lc_is_impersonated" {
+ type = "Bool"
}
- column "ip" {
+ column "lc_session_id" {
type = "String"
}
- column "site_url" {
- type = "String"
+ column "lc_dashboard_id" {
+ type = "Int64"
}
- column "now" {
- type = "DateTime64(6, 'UTC')"
+ column "lc_insight_id" {
+ type = "Int64"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
}
- column "raw_payload" {
+ column "lc_batch_export_id" {
type = "String"
}
- column "error_timestamp" {
- type = "DateTime64(6, 'UTC')"
+ column "lc_experiment_id" {
+ type = "Int64"
}
- column "error_location" {
+ column "lc_experiment_feature_flag_key" {
type = "String"
}
- column "error" {
+ column "lc_alert_config_id" {
type = "String"
}
- column "tags" {
- type = "Array(String)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
+ column "lc_feature" {
+ type = "LowCardinality(String)"
}
- index "kafka_timestamp_minmax_events_dead_letter_queue" {
- expr = "_timestamp"
- type = "minmax"
- granularity = 3
+ column "lc_table_id" {
+ type = "String"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.events_dead_letter_queue"
- replica_name = "{replica}-{shard}"
- version_column = "_timestamp"
+ column "lc_warehouse_query" {
+ type = "Bool"
}
- }
- table "exchange_rate" {
- order_by = ["date", "currency"]
- settings = {
- index_granularity = "8192"
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
}
- column "currency" {
+ column "lc_service_name" {
type = "String"
}
- column "date" {
- type = "Date"
+ column "lc_workload" {
+ type = "LowCardinality(String)"
}
- column "rate" {
- type = "Decimal(18, 10)"
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
}
- column "version" {
- type = "UInt32"
- default = "toUnixTimestamp(now())"
+ column "lc_query__query" {
+ type = "String"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.exchange_rate"
- replica_name = "{replica}-{shard}"
- version_column = "version"
+ column "lc_query" {
+ type = "String"
}
- }
- table "experiment_exposures_preaggregated" {
- column "team_id" {
- type = "Int64"
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
}
- column "job_id" {
- type = "UUID"
+ column "lc_temporal__workflow_type" {
+ type = "String"
}
- column "entity_id" {
+ column "lc_temporal__workflow_id" {
type = "String"
}
- column "variant" {
+ column "lc_temporal__workflow_run_id" {
type = "String"
}
- column "first_exposure_time" {
- type = "DateTime64(6, 'UTC')"
+ column "lc_temporal__activity_type" {
+ type = "String"
}
- column "last_exposure_time" {
- type = "DateTime64(6, 'UTC')"
+ column "lc_temporal__activity_id" {
+ type = "String"
}
- column "exposure_event_uuid" {
- type = "UUID"
+ column "lc_temporal__attempt" {
+ type = "Int64"
}
- column "exposure_session_id" {
+ column "lc_dagster__job_name" {
type = "String"
}
- column "breakdown_value" {
- type = "Array(String)"
+ column "lc_dagster__run_id" {
+ type = "String"
}
- column "computed_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now()"
+ column "lc_dagster__owner" {
+ type = "String"
}
- column "expires_at" {
- type = "Date"
- default = "today() + toIntervalDay(7)"
+ column "lc_modifiers" {
+ type = "String"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_experiment_exposures_preaggregated"
- sharding_key = "cityHash64(entity_id)"
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.query_log_archive_new"
+ replica_name = "{replica}-{shard}"
}
}
- table "groups" {
- order_by = ["team_id", "group_type_index", "group_key"]
+ table "sharded_query_log_archive_old" {
+ order_by = ["team_id", "event_date", "event_time", "query_id"]
+ partition_by = "toYYYYMM(event_date)"
settings = {
index_granularity = "8192"
}
- column "group_type_index" {
- type = "UInt8"
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
}
- column "group_key" {
+ column "query_id" {
type = "String"
}
- column "created_at" {
- type = "DateTime64(3)"
+ column "initial_query_id" {
+ type = "String"
}
- column "team_id" {
- type = "Int64"
+ column "is_initial_query" {
+ type = "UInt8"
}
- column "group_properties" {
- type = "String"
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
}
- column "_timestamp" {
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
type = "DateTime"
}
- column "_offset" {
- type = "UInt64"
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
}
- column "is_deleted" {
- type = "Bool"
+ column "query_start_time" {
+ type = "DateTime"
}
- index "is_deleted_idx" {
- expr = "(is_deleted)"
- type = "minmax"
- granularity = 1
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.groups"
- replica_name = "{replica}-{shard}"
- version_column = "_timestamp"
+ column "query_duration_ms" {
+ type = "UInt64"
}
- }
- table "heatmaps" {
- column "session_id" {
- type = "String"
+ column "read_rows" {
+ type = "UInt64"
}
- column "team_id" {
- type = "Int64"
+ column "read_bytes" {
+ type = "UInt64"
}
- column "distinct_id" {
- type = "String"
+ column "written_rows" {
+ type = "UInt64"
}
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
+ column "written_bytes" {
+ type = "UInt64"
}
- column "x" {
- type = "Int16"
+ column "result_rows" {
+ type = "UInt64"
}
- column "y" {
- type = "Int16"
+ column "result_bytes" {
+ type = "UInt64"
}
- column "scale_factor" {
- type = "Int16"
+ column "memory_usage" {
+ type = "UInt64"
}
- column "viewport_width" {
- type = "Int16"
+ column "peak_threads_usage" {
+ type = "UInt64"
}
- column "viewport_height" {
- type = "Int16"
+ column "current_database" {
+ type = "LowCardinality(String)"
}
- column "pointer_target_fixed" {
- type = "Bool"
+ column "query" {
+ type = "String"
}
- column "current_url" {
+ column "formatted_query" {
type = "String"
}
- column "type" {
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
type = "LowCardinality(String)"
}
- column "_timestamp" {
- type = "DateTime"
+ column "exception_code" {
+ type = "Int32"
}
- column "_offset" {
- type = "UInt64"
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
}
- column "_partition" {
- type = "UInt64"
+ column "exception" {
+ type = "String"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_heatmaps"
- sharding_key = "cityHash64(concat(toString(team_id), '-', session_id, '-', toString(toDate(timestamp))))"
+ column "stack_trace" {
+ type = "String"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "lc_id" {
+ type = "String"
+ }
+ column "lc_route_id" {
+ type = "String"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ }
+ column "lc_name" {
+ type = "String"
+ }
+ column "lc_request_name" {
+ type = "String"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ }
+ column "lc_org_id" {
+ type = "String"
}
- }
- table "ingestion_warnings" {
column "team_id" {
type = "Int64"
}
- column "source" {
+ column "lc_user_id" {
+ type = "Int64"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ }
+ column "lc_session_id" {
+ type = "String"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ }
+ column "lc_feature" {
type = "LowCardinality(String)"
}
- column "type" {
+ column "lc_table_id" {
type = "String"
}
- column "details" {
- type = "String"
- codec = "ZSTD(3)"
+ column "lc_warehouse_query" {
+ type = "Bool"
}
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
}
- column "_timestamp" {
- type = "DateTime"
+ column "lc_service_name" {
+ type = "String"
}
- column "_offset" {
- type = "UInt64"
+ column "lc_workload" {
+ type = "LowCardinality(String)"
}
- column "_partition" {
- type = "UInt64"
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_ingestion_warnings"
- sharding_key = "rand()"
+ column "lc_query__query" {
+ type = "String"
+ }
+ column "lc_query" {
+ type = "String"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_query_log_archive"
+ replica_name = "{replica}"
}
}
- table "kafka_events_json" {
+ materialized_view "events_json_mv" {
+ to_table = "posthog.writable_events"
+ query = file("sql/events_json_mv.sql")
+
column "uuid" {
type = "UUID"
}
@@ -1861,8 +1722,7 @@ database "posthog" {
type = "String"
}
column "properties" {
- type = "String"
- codec = "ZSTD(3)"
+ type = "String"
}
column "timestamp" {
type = "DateTime64(6, 'UTC')"
@@ -1886,28 +1746,22 @@ database "posthog" {
type = "DateTime64(3)"
}
column "person_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ type = "String"
}
column "group0_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ type = "String"
}
column "group1_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ type = "String"
}
column "group2_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ type = "String"
}
column "group3_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ type = "String"
}
column "group4_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ type = "String"
}
column "group0_created_at" {
type = "DateTime64(3)"
@@ -1960,15 +1814,97 @@ database "posthog" {
column "dmat_string_9" {
type = "Nullable(String)"
}
- engine "kafka" {
- collection = "msk_cluster"
- topic_list = "clickhouse_events_json"
- group_name = "group1"
- format = "JSONEachRow"
- skip_broken_messages = 100
+ column "_timestamp" {
+ type = "Nullable(DateTime)"
}
- }
- table "kafka_performance_events" {
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "consumer_breadcrumbs" {
+ type = "Array(String)"
+ }
+ }
+ materialized_view "events_recent_json_mv" {
+ to_table = "posthog.writable_events_recent"
+ query = file("sql/events_recent_json_mv.sql")
+
+ 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 "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"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ }
+ materialized_view "performance_events_mv" {
+ to_table = "posthog.writeable_performance_events"
+ query = file("sql/performance_events_mv.sql")
+
column "uuid" {
type = "UUID"
}
@@ -2110,14 +2046,20 @@ database "posthog" {
column "unload_event_start" {
type = "Float64"
}
- engine "kafka" {
- collection = "msk_cluster"
- topic_list = "clickhouse_performance_events"
- group_name = "group1"
- format = "JSONEachRow"
+ column "_timestamp" {
+ type = "Nullable(DateTime)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
}
}
- table "kafka_person_distinct_id" {
+ materialized_view "person_distinct_id_mv" {
+ to_table = "posthog.person_distinct_id"
+ query = file("sql/person_distinct_id_mv.sql")
+
column "distinct_id" {
type = "String"
}
@@ -2128,19 +2070,19 @@ database "posthog" {
type = "Int64"
}
column "_sign" {
- type = "Nullable(Int8)"
+ type = "Int16"
}
- column "is_deleted" {
- type = "Nullable(Int8)"
+ column "_timestamp" {
+ type = "Nullable(DateTime)"
}
- engine "kafka" {
- collection = "msk_cluster"
- topic_list = "clickhouse_person_unique_id"
- group_name = "group1"
- format = "JSONEachRow"
+ column "_offset" {
+ type = "UInt64"
}
}
- table "kafka_person_overrides" {
+ materialized_view "person_overrides_mv" {
+ to_table = "posthog.person_overrides"
+ query = file("sql/person_overrides_mv.sql")
+
column "team_id" {
type = "Int32"
}
@@ -2159,887 +2101,941 @@ database "posthog" {
column "version" {
type = "Int32"
}
- engine "kafka" {
- broker_list = "kafka:9092"
- topic_list = "clickhouse_person_override"
- group_name = "clickhouse-person-overrides"
- format = "JSONEachRow"
- }
}
- table "llma_metrics_daily" {
- order_by = ["team_id", "date", "metric_name"]
- partition_by = "toYYYYMM(date)"
- settings = {
- index_granularity = "8192"
- }
- column "date" {
- type = "Date"
- }
+ materialized_view "raw_sessions_mv" {
+ to_table = "posthog.writable_raw_sessions"
+ query = file("sql/raw_sessions_mv.sql")
+
column "team_id" {
- type = "UInt64"
+ type = "Int64"
}
- column "metric_name" {
- type = "String"
+ column "session_id_v7" {
+ type = "UInt128"
}
- column "metric_value" {
- type = "Float64"
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
}
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.llma_metrics_daily"
- replica_name = "{replica}-{shard}"
+ column "min_timestamp" {
+ type = "DateTime64(6, 'UTC')"
}
- }
- table "log_entries" {
- column "team_id" {
- type = "UInt64"
+ column "max_timestamp" {
+ type = "DateTime64(6, 'UTC')"
}
- column "log_source" {
- type = "LowCardinality(String)"
+ column "max_inserted_at" {
+ type = "DateTime64(6, 'UTC')"
}
- column "log_source_id" {
- type = "String"
+ column "urls" {
+ type = "Array(String)"
}
- column "instance_id" {
- type = "String"
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
}
- column "level" {
- type = "LowCardinality(String)"
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
}
- column "message" {
- type = "String"
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "_timestamp" {
- type = "DateTime"
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "_offset" {
- type = "UInt64"
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_log_entries"
- sharding_key = "rand()"
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- }
- table "partitioned_sharded_posthog_document_embeddings" {
- order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "model_name", "rendering", "cityHash64(document_id)"]
- partition_by = "toMonday(timestamp)"
- ttl = "timestamp + toIntervalMonth(3)"
- settings = {
- index_granularity = "512"
- ttl_only_drop_parts = "1"
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "team_id" {
- type = "Int64"
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
}
- column "product" {
- type = "LowCardinality(String)"
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
}
- column "document_type" {
- type = "LowCardinality(String)"
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "model_name" {
- type = "LowCardinality(String)"
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "rendering" {
- type = "LowCardinality(String)"
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "document_id" {
- type = "String"
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "content" {
- type = "String"
- default = "''"
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "metadata" {
- type = "String"
- default = "'{}'"
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "embedding" {
- type = "Array(Float64)"
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "_timestamp" {
- type = "DateTime"
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "_offset" {
- type = "UInt64"
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "_partition" {
- type = "UInt64"
- }
- index "kafka_timestamp_minmax_partitioned_sharded_posthog_document_embeddings" {
- expr = "_timestamp"
- type = "minmax"
- granularity = 3
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.partitioned_sharded_posthog_document_embeddings"
- replica_name = "{replica}"
- version_column = "inserted_at"
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- }
- table "performance_events" {
- column "uuid" {
- type = "UUID"
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "session_id" {
- type = "String"
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "window_id" {
- type = "String"
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "pageview_id" {
- type = "String"
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "distinct_id" {
- type = "String"
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "timestamp" {
- type = "DateTime64(3)"
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "time_origin" {
- type = "DateTime64(3, 'UTC')"
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_type" {
- type = "LowCardinality(String)"
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "name" {
- type = "String"
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "team_id" {
- type = "Int64"
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "current_url" {
- type = "String"
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "start_time" {
- type = "Float64"
+ column "initial_epik" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "duration" {
- type = "Float64"
+ column "initial_qclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "redirect_start" {
- type = "Float64"
+ column "initial_sccid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "redirect_end" {
- type = "Float64"
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "worker_start" {
- type = "Float64"
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "fetch_start" {
- type = "Float64"
+ column "pageview_count" {
+ type = "UInt64"
}
- column "domain_lookup_start" {
- type = "Float64"
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
}
- column "domain_lookup_end" {
- type = "Float64"
+ column "autocapture_count" {
+ type = "UInt64"
}
- column "connect_start" {
- type = "Float64"
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
}
- column "secure_connection_start" {
- type = "Float64"
+ column "screen_count" {
+ type = "UInt64"
}
- column "connect_end" {
- type = "Float64"
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
}
- column "request_start" {
- type = "Float64"
+ column "maybe_has_session_replay" {
+ type = "Bool"
}
- column "response_start" {
- type = "Float64"
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
}
- column "response_end" {
- type = "Float64"
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
}
- column "decoded_body_size" {
- type = "Int64"
+ }
+ materialized_view "sessions_mv" {
+ to_table = "posthog.writable_sessions"
+ query = file("sql/sessions_mv.sql")
+
+ column "session_id" {
+ type = "String"
}
- column "encoded_body_size" {
+ column "team_id" {
type = "Int64"
}
- column "initiator_type" {
- type = "LowCardinality(String)"
- }
- column "next_hop_protocol" {
- type = "LowCardinality(String)"
- }
- column "render_blocking_status" {
- type = "LowCardinality(String)"
+ column "distinct_id" {
+ type = "String"
}
- column "response_status" {
- type = "Int64"
+ column "min_timestamp" {
+ type = "DateTime64(6, 'UTC')"
}
- column "transfer_size" {
- type = "Int64"
+ column "max_timestamp" {
+ type = "DateTime64(6, 'UTC')"
}
- column "largest_contentful_paint_element" {
- type = "String"
+ column "urls" {
+ type = "Array(String)"
}
- column "largest_contentful_paint_render_time" {
- type = "Float64"
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "largest_contentful_paint_load_time" {
- type = "Float64"
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
}
- column "largest_contentful_paint_size" {
- type = "Float64"
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "largest_contentful_paint_id" {
- type = "String"
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "largest_contentful_paint_url" {
- type = "String"
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "dom_complete" {
- type = "Float64"
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "dom_content_loaded_event" {
- type = "Float64"
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "dom_interactive" {
- type = "Float64"
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "load_event_end" {
- type = "Float64"
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "load_event_start" {
- type = "Float64"
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "redirect_count" {
- type = "Int64"
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "navigation_type" {
- type = "LowCardinality(String)"
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "unload_event_end" {
- type = "Float64"
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "unload_event_start" {
- type = "Float64"
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "_timestamp" {
- type = "DateTime"
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "_offset" {
- type = "UInt64"
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "_partition" {
- type = "UInt64"
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_performance_events"
- sharding_key = "sipHash64(session_id)"
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- }
- table "person_distinct_id" {
- order_by = ["team_id", "distinct_id", "person_id"]
- settings = {
- index_granularity = "8192"
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "distinct_id" {
- type = "String"
- comment = "skip_0003_fill_person_distinct_id2"
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "person_id" {
- type = "UUID"
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "team_id" {
- type = "Int64"
+ column "initial_epik" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "_sign" {
- type = "Int8"
- default = "1"
+ column "initial_qclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "is_deleted" {
- type = "Int8"
- alias = "if(_sign = -1, 1, 0)"
+ column "initial_sccid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "_timestamp" {
- type = "DateTime"
+ column "event_count_map" {
+ type = "Map(String, UInt64)"
}
- column "_offset" {
+ column "pageview_count" {
type = "UInt64"
}
- engine "replicated_collapsing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id"
- replica_name = "{replica}-{shard}"
- sign_column = "_sign"
+ column "autocapture_count" {
+ type = "UInt64"
}
}
- table "person_overrides" {
- order_by = ["team_id", "old_person_id"]
- partition_by = "toYYYYMM(oldest_event)"
- settings = {
- index_granularity = "8192"
- }
- column "team_id" {
- type = "Int32"
+ dictionary "exchange_rate_dict" {
+ primary_key = ["currency"]
+ lifetime {
+ min = 3000
+ max = 3600
}
- column "old_person_id" {
- type = "UUID"
+ range {
+ min = "start_date"
+ max = "end_date"
}
- column "override_person_id" {
- type = "UUID"
+ attribute "currency" {
+ type = "String"
}
- column "merged_at" {
- type = "DateTime64(6, 'UTC')"
+ attribute "start_date" {
+ type = "Date"
}
- column "oldest_event" {
- type = "DateTime64(6, 'UTC')"
+ attribute "end_date" {
+ type = "Nullable(Date)"
}
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now()"
+ attribute "rate" {
+ type = "Decimal64(10)"
}
- column "version" {
- type = "Int32"
+ source "clickhouse" {
+ user = "default"
+ query = "SELECT currency, date AS start_date, leadInFrame(date::Nullable(Date), 1, NULL::Nullable(Date)) OVER w AS end_date, argMax(rate, version) AS rate FROM `posthog`.`exchange_rate` GROUP BY date, currency WINDOW w AS ( PARTITION BY currency ORDER BY date ASC ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING )"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.person_overrides"
- replica_name = "{replica}-{shard}"
- version_column = "version"
+ layout "complex_key_range_hashed" {
+ range_lookup_strategy = "max"
}
}
- table "pg_embeddings" {
- order_by = ["team_id", "domain", "id"]
- settings = {
- index_granularity = "512"
- }
- column "domain" {
- type = "String"
+ dictionary "person_distinct_id_overrides_dict" {
+ primary_key = ["team_id", "distinct_id"]
+ lifetime {
+ min = 3600
+ max = 18000
}
- column "team_id" {
+ attribute "team_id" {
type = "Int64"
}
- column "id" {
- type = "String"
- }
- column "vector" {
- type = "Array(Float32)"
- }
- column "text" {
+ attribute "distinct_id" {
type = "String"
}
- column "properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- default = "now('UTC')"
- }
- column "is_deleted" {
- type = "UInt8"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.pg_embeddings"
- replica_name = "{replica}-{shard}"
- version_column = "timestamp"
- is_deleted_column = "is_deleted"
- }
- }
- table "plugin_log_entries" {
- order_by = ["team_id", "plugin_id", "plugin_config_id", "timestamp"]
- partition_by = "toYYYYMMDD(timestamp)"
- ttl = "toDate(timestamp) + toIntervalWeek(1)"
- settings = {
- index_granularity = "512"
- }
- column "id" {
+ attribute "person_id" {
type = "UUID"
}
- column "team_id" {
- type = "Int64"
- }
- column "plugin_id" {
- type = "Int64"
- }
- column "plugin_config_id" {
- type = "Int64"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
+ source "clickhouse" {
+ user = "default"
+ query = "SELECT team_id, distinct_id, argMax(person_id, version) AS person_id FROM posthog.person_distinct_id_overrides GROUP BY team_id, distinct_id"
}
- column "source" {
- type = "String"
+ layout "complex_key_hashed" {
}
- column "type" {
- type = "String"
+ }
+ dictionary "person_overrides_dict" {
+ primary_key = ["team_id", "old_person_id"]
+ lifetime {
+ min = 5
+ max = 10
}
- column "message" {
- type = "String"
+ attribute "team_id" {
+ type = "INT"
}
- column "instance_id" {
+ attribute "old_person_id" {
type = "UUID"
}
- column "_timestamp" {
- type = "DateTime"
+ attribute "override_person_id" {
+ type = "UUID"
}
- column "_offset" {
- type = "UInt64"
+ source "clickhouse" {
+ user = "default"
+ query = "\\nSELECT\\n team_id,\\n old_person_id,\\n argMax(override_person_id, version)\\nFROM\\n `posthog`.`person_overrides` AS overrides\\nGROUP BY\\n team_id,\\n old_person_id\\n"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.plugin_log_entries"
- replica_name = "{replica}-{shard}"
- version_column = "_timestamp"
+ layout "complex_key_hashed" {
+ preallocate = 1
}
}
- table "preaggregation_results" {
- column "team_id" {
- type = "Int64"
- }
- column "job_id" {
- type = "UUID"
+ patch_table "sharded_events" {
+ modify_column "$group_0" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_0"
}
- column "time_window_start" {
- type = "DateTime64(6, 'UTC')"
+ modify_column "$group_1" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_1"
}
- column "expires_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now() + toIntervalDay(7)"
+ modify_column "$group_2" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_2"
}
- column "breakdown_value" {
- type = "Array(String)"
+ modify_column "$group_3" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_3"
}
- column "uniq_exact_state" {
- type = "AggregateFunction(uniqExact, UUID)"
+ modify_column "$group_4" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_4"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_preaggregation_results"
- sharding_key = "sipHash64(job_id)"
+ modify_column "$window_id" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$window_id"
}
- }
- table "precalculated_events" {
- column "team_id" {
- type = "Int64"
+ modify_column "$session_id" {
+ type = "String"
+ materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
+ comment = "column_materializer::$session_id"
}
- column "date" {
- type = "Date"
+ 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)"
}
- column "distinct_id" {
+ drop_columns = ["mat_historical_migration"]
+ column "elements_chain" {
type = "String"
}
column "person_id" {
type = "UUID"
}
- column "condition" {
- type = "String"
- }
- column "uuid" {
- type = "UUID"
+ column "person_created_at" {
+ type = "DateTime64(3)"
}
- column "source" {
- type = "String"
+ column "person_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "_timestamp" {
- type = "DateTime64(6)"
+ column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "_partition" {
- type = "UInt64"
+ column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "_offset" {
- type = "UInt64"
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_precalculated_events"
- sharding_key = "sipHash64(distinct_id)"
+ column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- }
- table "precalculated_person_properties" {
- column "team_id" {
- type = "Int64"
+ column "group4_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "distinct_id" {
- type = "String"
+ column "group0_created_at" {
+ type = "DateTime64(3)"
}
- column "person_id" {
- type = "UUID"
+ column "group1_created_at" {
+ type = "DateTime64(3)"
}
- column "condition" {
- type = "String"
+ column "group2_created_at" {
+ type = "DateTime64(3)"
}
- column "matches" {
- type = "Bool"
+ column "group3_created_at" {
+ type = "DateTime64(3)"
}
- column "source" {
- type = "String"
+ column "group4_created_at" {
+ type = "DateTime64(3)"
}
column "_timestamp" {
- type = "DateTime64(6)"
+ type = "DateTime"
}
column "_offset" {
type = "UInt64"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_precalculated_person_properties"
- sharding_key = "sipHash64(distinct_id)"
- }
- }
- table "property_definitions" {
- order_by = ["team_id", "type", "coalesce(event, '')", "name", "coalesce(group_type_index, 255)"]
- settings = {
- index_granularity = "8192"
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ materialized = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
}
- column "team_id" {
- type = "UInt32"
+ drop_indexes = ["minmax_mat_historical_migration", "is_deleted_idx", "minmax_historical_migration"]
+ index "minmax_$group_0" {
+ expr = "`$group_0`"
+ type = "minmax"
+ granularity = 1
}
- column "project_id" {
- type = "Nullable(UInt32)"
+ index "minmax_$group_1" {
+ expr = "`$group_1`"
+ type = "minmax"
+ granularity = 1
}
- column "name" {
- type = "String"
+ index "minmax_$group_2" {
+ expr = "`$group_2`"
+ type = "minmax"
+ granularity = 1
}
- column "property_type" {
- type = "Nullable(String)"
+ index "minmax_$group_3" {
+ expr = "`$group_3`"
+ type = "minmax"
+ granularity = 1
}
- column "event" {
- type = "Nullable(String)"
+ index "minmax_$group_4" {
+ expr = "`$group_4`"
+ type = "minmax"
+ granularity = 1
}
- column "group_type_index" {
- type = "Nullable(UInt8)"
+ index "minmax_$window_id" {
+ expr = "`$window_id`"
+ type = "minmax"
+ granularity = 1
}
- column "type" {
- type = "UInt8"
- default = "1"
+ index "minmax_$session_id" {
+ expr = "`$session_id`"
+ type = "minmax"
+ granularity = 1
}
- column "last_seen_at" {
- type = "DateTime"
+ index "kafka_timestamp_minmax_sharded_events" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
}
- column "version" {
- type = "UInt64"
- materialized = "(bitShiftLeft(toUInt64(NOT isNull(property_type)), 48) + toUInt64(toUnixTimestamp(last_seen_at)))"
+ index "is_deleted_idx" {
+ expr = "(is_deleted)"
+ type = "minmax"
+ granularity = 1
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.property_definitions"
- replica_name = "{replica}-{shard}"
- version_column = "version"
+ index "minmax_historical_migration" {
+ expr = "(historical_migration)"
+ type = "minmax"
+ granularity = 1
}
}
- table "query_log_archive_v2" {
- order_by = ["team_id", "event_date", "event_time", "query_id"]
- partition_by = "toYYYYMM(event_date)"
- settings = {
- index_granularity = "8192"
+
+ patch_table "events" {
+ modify_column "properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "hostname" {
- type = "LowCardinality(String)"
+ drop_columns = ["mat_historical_migration"]
+ column "elements_chain" {
+ type = "String"
}
- column "user" {
- type = "LowCardinality(String)"
+ column "person_id" {
+ type = "UUID"
}
- column "query_id" {
- type = "String"
+ column "person_created_at" {
+ type = "DateTime64(3)"
}
- column "initial_query_id" {
- type = "String"
+ column "person_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "is_initial_query" {
- type = "UInt8"
+ column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "type" {
- type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "event_date" {
- type = "Date"
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "event_time" {
- type = "DateTime"
+ column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "event_time_microseconds" {
- type = "DateTime64(6)"
+ column "group4_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "query_start_time" {
- type = "DateTime"
+ column "group0_created_at" {
+ type = "DateTime64(3)"
}
- column "query_start_time_microseconds" {
- type = "DateTime64(6)"
+ column "group1_created_at" {
+ type = "DateTime64(3)"
}
- column "query_duration_ms" {
- type = "UInt64"
+ column "group2_created_at" {
+ type = "DateTime64(3)"
}
- column "read_rows" {
- type = "UInt64"
+ column "group3_created_at" {
+ type = "DateTime64(3)"
}
- column "read_bytes" {
- type = "UInt64"
+ column "group4_created_at" {
+ type = "DateTime64(3)"
}
- column "written_rows" {
- type = "UInt64"
+ column "_timestamp" {
+ type = "DateTime"
}
- column "written_bytes" {
+ column "_offset" {
type = "UInt64"
}
- column "result_rows" {
- type = "UInt64"
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_trace_id"
}
- column "result_bytes" {
- type = "UInt64"
+ column "mat_$ai_experiment_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_experiment_id"
}
- column "memory_usage" {
- type = "UInt64"
+ }
+ table "billing_usage_records" {
+ column "schema_version" { type = "UInt8" }
+ column "record_id" { type = "String" }
+ column "producer_id" { type = "LowCardinality(String)" }
+ column "team_id" { type = "Int64" }
+ column "organization_id" { type = "UUID" }
+ column "usage_key" { type = "LowCardinality(String)" }
+ column "unit" { type = "LowCardinality(String)" }
+ column "quantity" { type = "Int64" }
+ column "timestamp" { type = "DateTime64(6, 'UTC')" }
+ column "inserted_at" { type = "DateTime64(6, 'UTC')" }
+ column "_timestamp" { type = "DateTime" }
+ column "_offset" { type = "UInt64" }
+ column "_partition" { type = "UInt64" }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_billing_usage_records"
+ sharding_key = "cityHash64(team_id)"
}
- column "peak_threads_usage" {
- type = "UInt64"
+ }
+
+ view "events_batch_export_backfill" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ timestamp AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ (events.timestamp >= {interval_start: DateTime64})
+AND
+ (events.timestamp < {interval_end: DateTime64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ view "persons_batch_export_backfill" {
+ query = <<SQL
+SELECT
+ pd.team_id AS team_id,
+ pd.distinct_id AS distinct_id,
+ toString(p.id) AS person_id,
+ p.properties AS properties,
+ pd.version AS person_distinct_id_version,
+ p.version AS person_version,
+ p.created_at AS created_at,
+ multiIf(
+ (pd._timestamp < {interval_end: DateTime64})
+ AND (NOT (p._timestamp < {interval_end: DateTime64})),
+ pd._timestamp,
+ (p._timestamp < {interval_end: DateTime64})
+ AND (NOT (pd._timestamp < {interval_end: DateTime64})),
+ p._timestamp,
+ least(p._timestamp, pd._timestamp)
+ ) AS _inserted_at
+FROM
+ (SELECT team_id, distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 PREWHERE team_id = {team_id: Int64} GROUP BY team_id, distinct_id) AS pd INNER JOIN (SELECT team_id, id, max(version) AS version, argMax(properties, person.version) AS properties, argMax(created_at, person.version) AS created_at, argMax(_timestamp, person.version) AS _timestamp FROM posthog.person PREWHERE team_id = {team_id: Int64} GROUP BY team_id, id) AS p ON (p.id = pd.person_id) AND (p.team_id = pd.team_id)
+WHERE
+ (pd.team_id = {team_id: Int64})
+AND
+ (p.team_id = {team_id: Int64})
+AND
+ ((pd._timestamp < {interval_end: DateTime64}) OR (p._timestamp < {interval_end: DateTime64}))
+ORDER BY _inserted_at ASC
+SQL
+
+ }
+
+ table "app_metrics" {
+ column "team_id" {
+ type = "Int64"
}
- column "current_database" {
- type = "LowCardinality(String)"
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
}
- column "query" {
- type = "String"
+ column "plugin_config_id" {
+ type = "Int64"
}
- column "formatted_query" {
+ column "category" {
+ type = "LowCardinality(String)"
+ }
+ column "job_id" {
type = "String"
}
- column "normalized_query_hash" {
- type = "UInt64"
+ column "successes" {
+ type = "SimpleAggregateFunction(sum, Int64)"
}
- column "query_kind" {
- type = "LowCardinality(String)"
+ column "successes_on_retry" {
+ type = "SimpleAggregateFunction(sum, Int64)"
}
- column "exception_code" {
- type = "Int32"
+ column "failures" {
+ type = "SimpleAggregateFunction(sum, Int64)"
}
- column "exception_name" {
- type = "String"
- alias = "errorCodeToName(exception_code)"
+ column "error_uuid" {
+ type = "UUID"
}
- column "exception" {
+ column "error_type" {
type = "String"
}
- column "stack_trace" {
- type = "String"
+ column "error_details" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "ProfileEvents_RealTimeMicroseconds" {
- type = "Int64"
+ column "_timestamp" {
+ type = "DateTime"
}
- column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
- type = "Int64"
- }
- column "ProfileEvents_S3Clients" {
- type = "Int64"
+ column "_offset" {
+ type = "UInt64"
}
- column "ProfileEvents_S3DeleteObjects" {
- type = "Int64"
+ column "_partition" {
+ type = "UInt64"
}
- column "ProfileEvents_S3CopyObject" {
- type = "Int64"
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_app_metrics"
+ sharding_key = "rand()"
}
- column "ProfileEvents_S3ListObjects" {
+ }
+
+ table "precalculated_events" {
+ column "team_id" {
type = "Int64"
}
- column "ProfileEvents_S3HeadObject" {
- type = "Int64"
+ column "date" {
+ type = "Date"
}
- column "ProfileEvents_S3GetObjectAttributes" {
- type = "Int64"
+ column "distinct_id" {
+ type = "String"
}
- column "ProfileEvents_S3CreateMultipartUpload" {
- type = "Int64"
+ column "person_id" {
+ type = "UUID"
}
- column "ProfileEvents_S3UploadPartCopy" {
- type = "Int64"
+ column "condition" {
+ type = "String"
}
- column "ProfileEvents_S3UploadPart" {
- type = "Int64"
+ column "uuid" {
+ type = "UUID"
}
- column "ProfileEvents_S3AbortMultipartUpload" {
- type = "Int64"
+ column "source" {
+ type = "String"
}
- column "ProfileEvents_S3CompleteMultipartUpload" {
- type = "Int64"
+ column "_timestamp" {
+ type = "DateTime64(6)"
}
- column "ProfileEvents_S3PutObject" {
- type = "Int64"
+ column "_partition" {
+ type = "UInt64"
}
- column "ProfileEvents_S3GetObject" {
- type = "Int64"
+ column "_offset" {
+ type = "UInt64"
}
- column "ProfileEvents_ReadBufferFromS3Bytes" {
- type = "Int64"
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_precalculated_events"
+ sharding_key = "sipHash64(distinct_id)"
}
- column "ProfileEvents_WriteBufferFromS3Bytes" {
+ }
+
+ table "precalculated_person_properties" {
+ column "team_id" {
type = "Int64"
}
- column "ProfileEvents" {
- type = "Map(String, UInt64)"
- }
- column "lc_workflow" {
- type = "LowCardinality(String)"
- }
- column "lc_kind" {
- type = "LowCardinality(String)"
- }
- column "lc_id" {
- type = "String"
- }
- column "lc_route_id" {
+ column "distinct_id" {
type = "String"
}
- column "lc_access_method" {
- type = "LowCardinality(String)"
- }
- column "lc_api_key_label" {
- type = "String"
+ column "person_id" {
+ type = "UUID"
}
- column "lc_api_key_mask" {
+ column "condition" {
type = "String"
}
- column "lc_query_type" {
- type = "LowCardinality(String)"
- }
- column "lc_product" {
- type = "LowCardinality(String)"
- }
- column "lc_chargeable" {
+ column "matches" {
type = "Bool"
}
- column "lc_name" {
+ column "source" {
type = "String"
}
- column "lc_request_name" {
- type = "String"
+ column "_timestamp" {
+ type = "DateTime64(6)"
}
- column "lc_client_query_id" {
- type = "String"
+ column "_offset" {
+ type = "UInt64"
}
- column "lc_org_id" {
- type = "String"
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_precalculated_person_properties"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "sharded_app_metrics" {
+ order_by = ["team_id", "plugin_config_id", "job_id", "category", "toStartOfHour(timestamp)", "error_type", "error_uuid"]
+ partition_by = "toYYYYMM(timestamp)"
+ settings = {
+ index_granularity = "8192"
}
column "team_id" {
type = "Int64"
}
- column "lc_user_id" {
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "plugin_config_id" {
type = "Int64"
}
- column "lc_is_impersonated" {
- type = "Bool"
+ column "category" {
+ type = "LowCardinality(String)"
}
- column "lc_session_id" {
+ column "job_id" {
type = "String"
}
- column "lc_dashboard_id" {
- type = "Int64"
- }
- column "lc_insight_id" {
- type = "Int64"
+ column "successes" {
+ type = "SimpleAggregateFunction(sum, Int64)"
}
- column "lc_cohort_id" {
- type = "Int64"
+ column "successes_on_retry" {
+ type = "SimpleAggregateFunction(sum, Int64)"
}
- column "lc_batch_export_id" {
- type = "String"
+ column "failures" {
+ type = "SimpleAggregateFunction(sum, Int64)"
}
- column "lc_experiment_id" {
- type = "Int64"
+ column "error_uuid" {
+ type = "UUID"
}
- column "lc_experiment_feature_flag_key" {
+ column "error_type" {
type = "String"
}
- column "lc_alert_config_id" {
- type = "String"
+ column "error_details" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "lc_feature" {
- type = "LowCardinality(String)"
+ column "_timestamp" {
+ type = "DateTime"
}
- column "lc_table_id" {
- type = "String"
+ column "_offset" {
+ type = "UInt64"
}
- column "lc_warehouse_query" {
- type = "Bool"
+ column "_partition" {
+ type = "UInt64"
}
- column "lc_person_on_events_mode" {
- type = "LowCardinality(String)"
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_app_metrics"
+ replica_name = "{replica}"
}
- column "lc_service_name" {
- type = "String"
+ }
+
+ table "sharded_precalculated_events" {
+ order_by = ["team_id", "condition", "date", "distinct_id", "uuid"]
+ partition_by = "toYYYYMM(date)"
+ settings = {
+ index_granularity = "8192"
}
- column "lc_workload" {
- type = "LowCardinality(String)"
+ column "team_id" {
+ type = "Int64"
}
- column "lc_query__kind" {
- type = "LowCardinality(String)"
+ column "date" {
+ type = "Date"
}
- column "lc_query__query" {
+ column "distinct_id" {
type = "String"
}
- column "lc_query" {
- type = "String"
+ column "person_id" {
+ type = "UUID"
}
- column "lc_temporal__workflow_namespace" {
+ column "condition" {
type = "String"
}
- column "lc_temporal__workflow_type" {
- type = "String"
+ column "uuid" {
+ type = "UUID"
}
- column "lc_temporal__workflow_id" {
+ column "source" {
type = "String"
}
- column "lc_temporal__workflow_run_id" {
- type = "String"
+ column "_timestamp" {
+ type = "DateTime64(6)"
}
- column "lc_temporal__activity_type" {
- type = "String"
+ column "_partition" {
+ type = "UInt64"
}
- column "lc_temporal__activity_id" {
- type = "String"
+ column "_offset" {
+ type = "UInt64"
}
- column "lc_temporal__attempt" {
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_precalculated_events"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_precalculated_person_properties" {
+ order_by = ["team_id", "condition", "distinct_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
type = "Int64"
}
- column "lc_dagster__job_name" {
+ column "distinct_id" {
type = "String"
}
- column "lc_dagster__run_id" {
- type = "String"
+ column "person_id" {
+ type = "UUID"
}
- column "lc_dagster__owner" {
+ column "condition" {
type = "String"
}
- column "lc_modifiers" {
+ column "matches" {
+ type = "Bool"
+ }
+ column "source" {
type = "String"
}
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.query_log_archive_new"
- replica_name = "{replica}-{shard}"
+ column "_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_precalculated_person_properties"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
}
}
- table "raw_sessions_v3" {
+
+ table "sharded_raw_sessions" {
+ order_by = ["team_id", "toStartOfHour(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)))", "cityHash64(session_id_v7)", "session_id_v7"]
+ partition_by = "toYYYYMM(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)))"
+ sample_by = "cityHash64(session_id_v7)"
+ settings = {
+ index_granularity = "8192"
+ }
column "team_id" {
type = "Int64"
}
column "session_id_v7" {
type = "UInt128"
}
- column "session_timestamp" {
- type = "DateTime64(3)"
- materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
- }
column "distinct_id" {
type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
}
- column "distinct_ids" {
- type = "AggregateFunction(groupUniqArray, String)"
- }
column "min_timestamp" {
type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
}
@@ -3050,163 +3046,164 @@ database "posthog" {
type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
}
column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
}
column "entry_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
column "end_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
}
column "last_external_click_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
}
- column "browser" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "browser_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "os" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "os_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "device_type" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "viewport_width" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
}
- column "viewport_height" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
}
- column "geoip_country_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "geoip_subdivision_1_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "geoip_subdivision_1_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "geoip_subdivision_city_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "geoip_time_zone" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_referring_domain" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_utm_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_utm_campaign" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_utm_medium" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_utm_term" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_utm_content" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_gclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_gad_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_fbclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_has_gclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_has_fbclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_ad_ids_map" {
- type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_ad_ids_set" {
- type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "entry_channel_type_properties" {
- type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "pageview_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "autocapture_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "screen_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "page_screen_uniq_up_to" {
- type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "has_autocapture" {
- type = "SimpleAggregateFunction(max, Bool)"
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "flag_values" {
- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ column "initial_epik" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "flag_keys" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ column "initial_qclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "event_names" {
- type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ column "initial_sccid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "hosts" {
- type = "SimpleAggregateFunction(groupUniqArrayArray(100), Array(String))"
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "emails" {
- type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(String))"
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "has_replay_events" {
- type = "SimpleAggregateFunction(max, Bool)"
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_raw_sessions_v3"
- sharding_key = "cityHash64(session_id_v7)"
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
}
- }
- table "session_replay_embeddings" {
- column "session_id" {
- type = "String"
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
}
- column "team_id" {
- type = "Int64"
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
}
- column "embeddings" {
- type = "Array(Float32)"
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
}
- column "generation_timestamp" {
- type = "DateTime64(6, 'UTC')"
- default = "now('UTC')"
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
}
- column "source_type" {
- type = "LowCardinality(String)"
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
}
- column "input" {
- type = "String"
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_session_replay_embeddings"
- sharding_key = "sipHash64(session_id)"
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions"
+ replica_name = "{replica}"
}
}
- table "session_replay_events" {
+
+ table "sharded_sessions" {
+ order_by = ["toStartOfDay(min_timestamp)", "team_id", "session_id"]
+ partition_by = "toYYYYMM(min_timestamp)"
+ settings = {
+ index_granularity = "512"
+ }
column "session_id" {
type = "String"
}
@@ -3214,311 +3211,210 @@ database "posthog" {
type = "Int64"
}
column "distinct_id" {
- type = "String"
+ type = "SimpleAggregateFunction(any, String)"
}
- column "min_first_timestamp" {
+ column "min_timestamp" {
type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
}
- column "max_last_timestamp" {
+ column "max_timestamp" {
type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
}
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "first_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "all_urls" {
+ column "urls" {
type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
}
- column "click_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "keypress_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "mouse_activity_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
}
- column "active_milliseconds" {
- type = "SimpleAggregateFunction(sum, Int64)"
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "console_log_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "console_warn_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "console_error_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "size" {
- type = "SimpleAggregateFunction(sum, Int64)"
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "message_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "event_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "snapshot_source" {
- type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "snapshot_library" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "is_deleted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "ai_tags_fixed" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "ai_tags_freeform" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "ai_highlighted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "surfacing_score" {
- type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_session_replay_events"
- sharding_key = "sipHash64(distinct_id)"
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- }
- table "sharded_app_metrics" {
- order_by = ["team_id", "plugin_config_id", "job_id", "category", "toStartOfHour(timestamp)", "error_type", "error_uuid"]
- partition_by = "toYYYYMM(timestamp)"
- settings = {
- index_granularity = "8192"
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "team_id" {
- type = "Int64"
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
+ column "initial_epik" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "plugin_config_id" {
- type = "Int64"
+ column "initial_qclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "category" {
- type = "LowCardinality(String)"
+ column "initial_sccid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
}
- column "job_id" {
- type = "String"
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
}
- column "successes" {
+ column "pageview_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
- column "successes_on_retry" {
+ column "autocapture_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
- column "failures" {
- type = "SimpleAggregateFunction(sum, Int64)"
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sessions"
+ replica_name = "{replica}"
}
- column "error_uuid" {
+ }
+
+ table "writable_events" {
+ column "uuid" {
type = "UUID"
}
- column "error_type" {
+ column "event" {
type = "String"
}
- column "error_details" {
+ column "properties" {
type = "String"
codec = "ZSTD(3)"
}
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- engine "replicated_aggregating_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_app_metrics"
- replica_name = "{replica}"
- }
- }
- table "sharded_app_metrics2" {
- order_by = ["team_id", "app_source", "app_source_id", "instance_id", "toStartOfHour(timestamp)", "metric_kind", "metric_name"]
- partition_by = "toYYYYMM(timestamp)"
- ttl = "toDate(timestamp) + toIntervalDay(90)"
- settings = {
- index_granularity = "8192"
- }
- column "team_id" {
- type = "Int64"
- }
column "timestamp" {
type = "DateTime64(6, 'UTC')"
}
- column "app_source" {
- type = "LowCardinality(String)"
- }
- column "app_source_id" {
- type = "String"
- }
- column "instance_id" {
- type = "String"
- }
- column "metric_kind" {
- type = "LowCardinality(String)"
- }
- column "metric_name" {
- type = "LowCardinality(String)"
- }
- column "count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- 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_experiment_exposures_preaggregated" {
- order_by = ["team_id", "job_id", "entity_id", "breakdown_value"]
- partition_by = "toYYYYMMDD(expires_at)"
- ttl = "expires_at"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
+ column "elements_chain" {
+ type = "String"
}
- column "team_id" {
- type = "Int64"
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
}
- column "job_id" {
+ column "person_id" {
type = "UUID"
}
- column "entity_id" {
- type = "String"
+ column "person_created_at" {
+ type = "DateTime64(3)"
}
- column "variant" {
- type = "String"
+ column "person_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "first_exposure_time" {
- type = "DateTime64(6, 'UTC')"
+ column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "last_exposure_time" {
- type = "DateTime64(6, 'UTC')"
+ column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "exposure_event_uuid" {
- type = "UUID"
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "exposure_session_id" {
- type = "String"
+ column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "breakdown_value" {
- type = "Array(String)"
+ column "group4_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
}
- column "computed_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now()"
+ column "group0_created_at" {
+ type = "DateTime64(3)"
}
- column "expires_at" {
- type = "Date"
- default = "today() + toIntervalDay(7)"
+ column "group1_created_at" {
+ type = "DateTime64(3)"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.experiment_exposures_preaggregated"
- replica_name = "{replica}"
- version_column = "computed_at"
+ column "group2_created_at" {
+ type = "DateTime64(3)"
}
- }
- table "sharded_heatmaps" {
- order_by = ["type", "team_id", "toDate(timestamp)", "current_url", "viewport_width"]
- partition_by = "toYYYYMM(timestamp)"
- ttl = "toDate(timestamp) + toIntervalDay(90)"
- settings = {
- index_granularity = "8192"
+ column "group3_created_at" {
+ type = "DateTime64(3)"
}
- column "session_id" {
- type = "String"
+ column "group4_created_at" {
+ type = "DateTime64(3)"
}
- column "team_id" {
- type = "Int64"
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
}
- column "distinct_id" {
- type = "String"
+ column "historical_migration" {
+ type = "Bool"
}
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
+ column "dmat_string_0" {
+ type = "Nullable(String)"
}
- column "x" {
- type = "Int16"
+ column "dmat_string_1" {
+ type = "Nullable(String)"
}
- column "y" {
- type = "Int16"
+ column "dmat_string_2" {
+ type = "Nullable(String)"
}
- column "scale_factor" {
- type = "Int16"
+ column "dmat_string_3" {
+ type = "Nullable(String)"
}
- column "viewport_width" {
- type = "Int16"
+ column "dmat_string_4" {
+ type = "Nullable(String)"
}
- column "viewport_height" {
- type = "Int16"
+ column "dmat_string_5" {
+ type = "Nullable(String)"
}
- column "pointer_target_fixed" {
- type = "Bool"
+ column "dmat_string_6" {
+ type = "Nullable(String)"
}
- column "current_url" {
- type = "String"
+ column "dmat_string_7" {
+ type = "Nullable(String)"
}
- column "type" {
- type = "LowCardinality(String)"
+ column "dmat_string_8" {
+ type = "Nullable(String)"
+ }
+ column "dmat_string_9" {
+ type = "Nullable(String)"
}
column "_timestamp" {
type = "DateTime"
@@ -3526,4310 +3422,218 @@ database "posthog" {
column "_offset" {
type = "UInt64"
}
- column "_partition" {
- type = "UInt64"
+ column "consumer_breadcrumbs" {
+ type = "Array(String)"
}
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.heatmaps"
- replica_name = "{replica}"
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events"
+ sharding_key = "sipHash64(distinct_id)"
}
}
- table "sharded_log_entries" {
- order_by = ["team_id", "log_source", "log_source_id", "instance_id", "timestamp"]
- partition_by = "toYYYYMMDD(timestamp)"
- ttl = "toDate(timestamp) + toIntervalDay(90)"
+
+ table "web_pre_aggregated_bounces_staging" {
+ order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_loggedIn", "mat_metadata_backend"]
+ partition_by = "toYYYYMMDD(period_bucket)"
settings = {
- index_granularity = "1024"
- ttl_only_drop_parts = "1"
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
}
column "team_id" {
type = "UInt64"
}
- column "log_source" {
- type = "LowCardinality(String)"
- }
- column "log_source_id" {
+ column "host" {
type = "String"
}
- column "instance_id" {
+ column "device_type" {
type = "String"
}
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "level" {
- type = "LowCardinality(String)"
- }
- column "message" {
+ column "entry_pathname" {
type = "String"
}
- column "_timestamp" {
- type = "DateTime"
+ column "end_pathname" {
+ type = "String"
}
- column "_offset" {
- type = "UInt64"
+ column "browser" {
+ type = "String"
}
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_log_entries"
- replica_name = "{replica}"
- version_column = "_timestamp"
+ column "os" {
+ type = "String"
}
- }
- table "sharded_performance_events" {
- order_by = ["team_id", "toDate(timestamp)", "session_id", "pageview_id", "timestamp"]
- partition_by = "toYYYYMM(timestamp)"
- ttl = "toDate(timestamp) + toIntervalWeek(3)"
- settings = {
- index_granularity = "8192"
+ column "viewport_width" {
+ type = "Int64"
}
- column "uuid" {
- type = "UUID"
+ column "viewport_height" {
+ type = "Int64"
}
- column "session_id" {
+ column "referring_domain" {
type = "String"
}
- column "window_id" {
+ column "utm_source" {
type = "String"
}
- column "pageview_id" {
+ column "utm_medium" {
type = "String"
}
- column "distinct_id" {
+ column "utm_campaign" {
type = "String"
}
- column "timestamp" {
- type = "DateTime64(3)"
- }
- column "time_origin" {
- type = "DateTime64(3, 'UTC')"
- }
- column "entry_type" {
- type = "LowCardinality(String)"
- }
- column "name" {
+ column "utm_term" {
type = "String"
}
- column "team_id" {
- type = "Int64"
- }
- column "current_url" {
+ column "utm_content" {
type = "String"
}
- column "start_time" {
- type = "Float64"
- }
- column "duration" {
- type = "Float64"
- }
- column "redirect_start" {
- type = "Float64"
- }
- column "redirect_end" {
- type = "Float64"
- }
- column "worker_start" {
- type = "Float64"
- }
- column "fetch_start" {
- type = "Float64"
- }
- column "domain_lookup_start" {
- type = "Float64"
- }
- column "domain_lookup_end" {
- type = "Float64"
- }
- column "connect_start" {
- type = "Float64"
- }
- column "secure_connection_start" {
- type = "Float64"
- }
- column "connect_end" {
- type = "Float64"
- }
- column "request_start" {
- type = "Float64"
- }
- column "response_start" {
- type = "Float64"
- }
- column "response_end" {
- type = "Float64"
- }
- column "decoded_body_size" {
- type = "Int64"
- }
- column "encoded_body_size" {
- type = "Int64"
- }
- column "initiator_type" {
- type = "LowCardinality(String)"
- }
- column "next_hop_protocol" {
- type = "LowCardinality(String)"
- }
- column "render_blocking_status" {
- type = "LowCardinality(String)"
- }
- column "response_status" {
- type = "Int64"
- }
- column "transfer_size" {
- type = "Int64"
- }
- column "largest_contentful_paint_element" {
- type = "String"
- }
- column "largest_contentful_paint_render_time" {
- type = "Float64"
- }
- column "largest_contentful_paint_load_time" {
- type = "Float64"
- }
- column "largest_contentful_paint_size" {
- type = "Float64"
- }
- column "largest_contentful_paint_id" {
- type = "String"
- }
- column "largest_contentful_paint_url" {
- type = "String"
- }
- column "dom_complete" {
- type = "Float64"
- }
- column "dom_content_loaded_event" {
- type = "Float64"
- }
- column "dom_interactive" {
- type = "Float64"
- }
- column "load_event_end" {
- type = "Float64"
- }
- column "load_event_start" {
- type = "Float64"
- }
- column "redirect_count" {
- type = "Int64"
- }
- column "navigation_type" {
- type = "LowCardinality(String)"
- }
- column "unload_event_end" {
- type = "Float64"
- }
- column "unload_event_start" {
- type = "Float64"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.performance_events"
- replica_name = "{replica}"
- }
- }
- table "sharded_posthog_document_embeddings_buffer" {
- order_by = ["inserted_at", "model_name", "cityHash64(document_id)"]
- partition_by = "toDate(inserted_at)"
- ttl = "inserted_at + toIntervalDay(1)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "model_name" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- default = "''"
- }
- column "metadata" {
- type = "String"
- default = "'{}'"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_buffer"
- replica_name = "{replica}"
- version_column = "inserted_at"
- }
- }
- table "sharded_posthog_document_embeddings_text_embedding_3_large_3072" {
- order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "rendering", "cityHash64(document_id)"]
- partition_by = "toMonday(timestamp)"
- ttl = "timestamp + toIntervalMonth(3)"
- settings = {
- index_granularity = "512"
- ttl_only_drop_parts = "1"
- }
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- default = "''"
- }
- column "metadata" {
- type = "String"
- default = "'{}'"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- index "kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_large_3072" {
- expr = "_timestamp"
- type = "minmax"
- granularity = 3
- }
- index "embedding_idx_l2" {
- expr = "embedding"
- type = "vector_similarity('hnsw', 'L2Distance', 3072)"
- granularity = 100000000
- }
- index "embedding_idx_cosine" {
- expr = "embedding"
- type = "vector_similarity('hnsw', 'cosineDistance', 3072)"
- granularity = 100000000
- }
- constraint "embedding_dimension_check" {
- check = "length(embedding) = 3072"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072"
- replica_name = "{replica}"
- version_column = "inserted_at"
- }
- }
- table "sharded_posthog_document_embeddings_text_embedding_3_small_1536" {
- order_by = ["team_id", "toDate(timestamp)", "product", "document_type", "rendering", "cityHash64(document_id)"]
- partition_by = "toMonday(timestamp)"
- ttl = "timestamp + toIntervalMonth(3)"
- settings = {
- index_granularity = "512"
- ttl_only_drop_parts = "1"
- }
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- default = "''"
- }
- column "metadata" {
- type = "String"
- default = "'{}'"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- index "kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_small_1536" {
- expr = "_timestamp"
- type = "minmax"
- granularity = 3
- }
- index "embedding_idx_l2" {
- expr = "embedding"
- type = "vector_similarity('hnsw', 'L2Distance', 1536)"
- granularity = 100000000
- }
- index "embedding_idx_cosine" {
- expr = "embedding"
- type = "vector_similarity('hnsw', 'cosineDistance', 1536)"
- granularity = 100000000
- }
- constraint "embedding_dimension_check" {
- check = "length(embedding) = 1536"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536"
- replica_name = "{replica}"
- version_column = "inserted_at"
- }
- }
- table "sharded_preaggregation_results" {
- order_by = ["team_id", "job_id", "time_window_start", "breakdown_value"]
- partition_by = "toYYYYMM(time_window_start)"
- ttl = "expires_at"
- settings = {
- index_granularity = "8192"
- }
- column "team_id" {
- type = "Int64"
- }
- column "job_id" {
- type = "UUID"
- }
- column "time_window_start" {
- type = "DateTime64(6, 'UTC')"
- }
- column "expires_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now() + toIntervalDay(7)"
- }
- column "breakdown_value" {
- type = "Array(String)"
- }
- column "uniq_exact_state" {
- type = "AggregateFunction(uniqExact, UUID)"
- }
- engine "replicated_aggregating_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.preaggregation_results"
- replica_name = "{replica}"
- }
- }
- table "sharded_precalculated_events" {
- order_by = ["team_id", "condition", "date", "distinct_id", "uuid"]
- partition_by = "toYYYYMM(date)"
- settings = {
- index_granularity = "8192"
- }
- column "team_id" {
- type = "Int64"
- }
- column "date" {
- type = "Date"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "condition" {
- type = "String"
- }
- column "uuid" {
- type = "UUID"
- }
- column "source" {
- type = "String"
- }
- column "_timestamp" {
- type = "DateTime64(6)"
- }
- column "_partition" {
- type = "UInt64"
- }
- column "_offset" {
- type = "UInt64"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_precalculated_events"
- replica_name = "{replica}"
- version_column = "_timestamp"
- }
- }
- table "sharded_precalculated_person_properties" {
- order_by = ["team_id", "condition", "distinct_id"]
- settings = {
- index_granularity = "8192"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "condition" {
- type = "String"
- }
- column "matches" {
- type = "Bool"
- }
- column "source" {
- type = "String"
- }
- column "_timestamp" {
- type = "DateTime64(6)"
- }
- column "_offset" {
- type = "UInt64"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_precalculated_person_properties"
- replica_name = "{replica}"
- version_column = "_timestamp"
- }
- }
- table "sharded_query_log_archive_old" {
- order_by = ["team_id", "event_date", "event_time", "query_id"]
- partition_by = "toYYYYMM(event_date)"
- settings = {
- index_granularity = "8192"
- }
- column "hostname" {
- type = "LowCardinality(String)"
- }
- column "user" {
- type = "LowCardinality(String)"
- }
- column "query_id" {
- type = "String"
- }
- column "initial_query_id" {
- type = "String"
- }
- column "is_initial_query" {
- type = "UInt8"
- }
- column "type" {
- type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
- }
- column "event_date" {
- type = "Date"
- }
- column "event_time" {
- type = "DateTime"
- }
- column "event_time_microseconds" {
- type = "DateTime64(6)"
- }
- column "query_start_time" {
- type = "DateTime"
- }
- column "query_start_time_microseconds" {
- type = "DateTime64(6)"
- }
- column "query_duration_ms" {
- type = "UInt64"
- }
- column "read_rows" {
- type = "UInt64"
- }
- column "read_bytes" {
- type = "UInt64"
- }
- column "written_rows" {
- type = "UInt64"
- }
- column "written_bytes" {
- type = "UInt64"
- }
- column "result_rows" {
- type = "UInt64"
- }
- column "result_bytes" {
- type = "UInt64"
- }
- column "memory_usage" {
- type = "UInt64"
- }
- column "peak_threads_usage" {
- type = "UInt64"
- }
- column "current_database" {
- type = "LowCardinality(String)"
- }
- column "query" {
- type = "String"
- }
- column "formatted_query" {
- type = "String"
- }
- column "normalized_query_hash" {
- type = "UInt64"
- }
- column "query_kind" {
- type = "LowCardinality(String)"
- }
- column "exception_code" {
- type = "Int32"
- }
- column "exception_name" {
- type = "String"
- alias = "errorCodeToName(exception_code)"
- }
- column "exception" {
- type = "String"
- }
- column "stack_trace" {
- type = "String"
- }
- column "ProfileEvents_RealTimeMicroseconds" {
- type = "Int64"
- }
- column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
- type = "Int64"
- }
- column "ProfileEvents_S3Clients" {
- type = "Int64"
- }
- column "ProfileEvents_S3DeleteObjects" {
- type = "Int64"
- }
- column "ProfileEvents_S3CopyObject" {
- type = "Int64"
- }
- column "ProfileEvents_S3ListObjects" {
- type = "Int64"
- }
- column "ProfileEvents_S3HeadObject" {
- type = "Int64"
- }
- column "ProfileEvents_S3GetObjectAttributes" {
- type = "Int64"
- }
- column "ProfileEvents_S3CreateMultipartUpload" {
- type = "Int64"
- }
- column "ProfileEvents_S3UploadPartCopy" {
- type = "Int64"
- }
- column "ProfileEvents_S3UploadPart" {
- type = "Int64"
- }
- column "ProfileEvents_S3AbortMultipartUpload" {
- type = "Int64"
- }
- column "ProfileEvents_S3CompleteMultipartUpload" {
- type = "Int64"
- }
- column "ProfileEvents_S3PutObject" {
- type = "Int64"
- }
- column "ProfileEvents_S3GetObject" {
- type = "Int64"
- }
- column "ProfileEvents_ReadBufferFromS3Bytes" {
- type = "Int64"
- }
- column "ProfileEvents_WriteBufferFromS3Bytes" {
- type = "Int64"
- }
- column "ProfileEvents" {
- type = "Map(String, UInt64)"
- }
- column "lc_workflow" {
- type = "LowCardinality(String)"
- }
- column "lc_kind" {
- type = "LowCardinality(String)"
- }
- column "lc_id" {
- type = "String"
- }
- column "lc_route_id" {
- type = "String"
- }
- column "lc_access_method" {
- type = "LowCardinality(String)"
- }
- column "lc_api_key_label" {
- type = "String"
- }
- column "lc_api_key_mask" {
- type = "String"
- }
- column "lc_query_type" {
- type = "LowCardinality(String)"
- }
- column "lc_product" {
- type = "LowCardinality(String)"
- }
- column "lc_chargeable" {
- type = "Bool"
- }
- column "lc_name" {
- type = "String"
- }
- column "lc_request_name" {
- type = "String"
- }
- column "lc_client_query_id" {
- type = "String"
- }
- column "lc_org_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "lc_user_id" {
- type = "Int64"
- }
- column "lc_is_impersonated" {
- type = "Bool"
- }
- column "lc_session_id" {
- type = "String"
- }
- column "lc_dashboard_id" {
- type = "Int64"
- }
- column "lc_insight_id" {
- type = "Int64"
- }
- column "lc_cohort_id" {
- type = "Int64"
- }
- column "lc_batch_export_id" {
- type = "String"
- }
- column "lc_experiment_id" {
- type = "Int64"
- }
- column "lc_experiment_feature_flag_key" {
- type = "String"
- }
- column "lc_alert_config_id" {
- type = "String"
- }
- column "lc_feature" {
- type = "LowCardinality(String)"
- }
- column "lc_table_id" {
- type = "String"
- }
- column "lc_warehouse_query" {
- type = "Bool"
- }
- column "lc_person_on_events_mode" {
- type = "LowCardinality(String)"
- }
- column "lc_service_name" {
- type = "String"
- }
- column "lc_workload" {
- type = "LowCardinality(String)"
- }
- column "lc_query__kind" {
- type = "LowCardinality(String)"
- }
- column "lc_query__query" {
- type = "String"
- }
- column "lc_query" {
- type = "String"
- }
- column "lc_temporal__workflow_namespace" {
- type = "String"
- }
- column "lc_temporal__workflow_type" {
- type = "String"
- }
- column "lc_temporal__workflow_id" {
- type = "String"
- }
- column "lc_temporal__workflow_run_id" {
- type = "String"
- }
- column "lc_temporal__activity_type" {
- type = "String"
- }
- column "lc_temporal__activity_id" {
- type = "String"
- }
- column "lc_temporal__attempt" {
- type = "Int64"
- }
- column "lc_dagster__job_name" {
- type = "String"
- }
- column "lc_dagster__run_id" {
- type = "String"
- }
- column "lc_dagster__owner" {
- type = "String"
- }
- column "lc_modifiers" {
- type = "String"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_query_log_archive"
- replica_name = "{replica}"
- }
- }
- table "sharded_raw_sessions" {
- order_by = ["team_id", "toStartOfHour(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)))", "cityHash64(session_id_v7)", "session_id_v7"]
- partition_by = "toYYYYMM(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)))"
- sample_by = "cityHash64(session_id_v7)"
- settings = {
- index_granularity = "8192"
- }
- column "team_id" {
- type = "Int64"
- }
- column "session_id_v7" {
- type = "UInt128"
- }
- column "distinct_id" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "max_inserted_at" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "end_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "last_external_click_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "initial_browser" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_browser_version" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_os" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_os_version" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_device_type" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_viewport_width" {
- type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
- }
- column "initial_viewport_height" {
- type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_country_code" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_1_code" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_1_name" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_city_name" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_time_zone" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_referring_domain" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_campaign" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_medium" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_term" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_content" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gad_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclsrc" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_dclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_wbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_fbclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_msclkid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_twclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_li_fat_id" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_mc_cid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_igshid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_ttclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_epik" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_qclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_sccid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial__kx" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_irclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "pageview_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "pageview_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "autocapture_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "autocapture_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "screen_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "screen_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "maybe_has_session_replay" {
- type = "SimpleAggregateFunction(max, Bool)"
- }
- column "page_screen_autocapture_uniq_up_to" {
- type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
- }
- column "vitals_lcp" {
- type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
- }
- engine "replicated_aggregating_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions"
- replica_name = "{replica}"
- }
- }
- table "sharded_raw_sessions_v3" {
- order_by = ["team_id", "session_timestamp", "session_id_v7"]
- partition_by = "toYYYYMM(session_timestamp)"
- settings = {
- index_granularity = "8192"
- max_delay_to_insert = "10"
- parts_to_delay_insert = "250"
- parts_to_throw_insert = "1000"
- }
- column "team_id" {
- type = "Int64"
- }
- column "session_id_v7" {
- type = "UInt128"
- }
- column "session_timestamp" {
- type = "DateTime64(3)"
- default = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
- }
- column "distinct_id" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "distinct_ids" {
- type = "AggregateFunction(groupUniqArray, String)"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "max_inserted_at" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "end_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "last_external_click_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "browser" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "browser_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "os" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "os_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "device_type" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "viewport_width" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
- }
- column "viewport_height" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
- }
- column "geoip_country_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_1_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_1_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_city_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_time_zone" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_referring_domain" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_campaign" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_medium" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_term" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_content" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_gclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_gad_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_fbclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_has_gclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
- }
- column "entry_has_fbclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
- }
- column "entry_ad_ids_map" {
- type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
- }
- column "entry_ad_ids_set" {
- type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
- }
- column "entry_channel_type_properties" {
- type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
- }
- column "pageview_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "autocapture_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "screen_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "page_screen_uniq_up_to" {
- type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
- }
- column "has_autocapture" {
- type = "SimpleAggregateFunction(max, Bool)"
- }
- column "flag_values" {
- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
- }
- column "flag_keys" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "event_names" {
- type = "SimpleAggregateFunction(groupUniqArrayArray(2000), 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)"
- }
- index "event_names_bloom_filter" {
- expr = "event_names"
- type = "bloom_filter()"
- granularity = 1
- }
- index "flag_keys_bloom_filter" {
- expr = "flag_keys"
- 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}"
- }
- }
- table "sharded_session_replay_embeddings" {
- order_by = ["toDate(generation_timestamp)", "team_id", "session_id"]
- partition_by = "toYYYYMM(generation_timestamp)"
- ttl = "toDate(generation_timestamp) + toIntervalYear(1)"
- settings = {
- index_granularity = "512"
- }
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "embeddings" {
- type = "Array(Float32)"
- }
- column "generation_timestamp" {
- type = "DateTime64(6, 'UTC')"
- default = "now('UTC')"
- }
- column "source_type" {
- type = "LowCardinality(String)"
- }
- column "input" {
- type = "String"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_embeddings"
- replica_name = "{replica}"
- }
- }
- table "sharded_session_replay_events" {
- order_by = ["toDate(min_first_timestamp)", "team_id", "session_id"]
- partition_by = "toYYYYMM(min_first_timestamp)"
- settings = {
- index_granularity = "512"
- }
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "min_first_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_last_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "first_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "click_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "keypress_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "mouse_activity_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "active_milliseconds" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_log_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_warn_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_error_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "size" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "message_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "event_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "snapshot_source" {
- type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
- }
- column "snapshot_library" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
- column "is_deleted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "ai_tags_fixed" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_tags_freeform" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_highlighted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "surfacing_score" {
- type = "SimpleAggregateFunction(max, Nullable(Float32))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
- }
- engine "replicated_aggregating_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
- replica_name = "{replica}"
- }
- }
- table "sharded_sessions" {
- order_by = ["toStartOfDay(min_timestamp)", "team_id", "session_id"]
- partition_by = "toYYYYMM(min_timestamp)"
- settings = {
- index_granularity = "512"
- }
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "SimpleAggregateFunction(any, String)"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "exit_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "initial_referring_domain" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_campaign" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_medium" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_term" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_content" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gad_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclsrc" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_dclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_wbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_fbclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_msclkid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_twclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_li_fat_id" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_mc_cid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_igshid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_ttclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_epik" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_qclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_sccid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "event_count_map" {
- type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
- }
- column "pageview_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "autocapture_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- engine "replicated_aggregating_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.sessions"
- replica_name = "{replica}"
- }
- }
- table "tophog" {
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "metric" {
- type = "LowCardinality(String)"
- }
- column "type" {
- type = "LowCardinality(String)"
- default = "'sum'"
- }
- column "key" {
- type = "Map(LowCardinality(String), String)"
- }
- column "value" {
- type = "Float64"
- }
- column "count" {
- type = "UInt64"
- default = "0"
- }
- column "pipeline" {
- type = "LowCardinality(String)"
- }
- column "lane" {
- type = "LowCardinality(String)"
- }
- column "labels" {
- type = "Map(LowCardinality(String), String)"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_tophog"
- sharding_key = "cityHash64(toString(key))"
- }
- }
- table "usage_report_events_preagg" {
- column "date" {
- type = "Date"
- }
- column "team_id" {
- type = "Int64"
- }
- column "person_mode" {
- type = "LowCardinality(String)"
- }
- column "lib" {
- type = "LowCardinality(String)"
- }
- column "event" {
- type = "String"
- }
- column "distinct_events_unique" {
- type = "AggregateFunction(uniqExact, Tuple(UInt64, UInt64, UInt64))"
- }
- column "event_count" {
- type = "AggregateFunction(sum, UInt64)"
- }
- engine "distributed" {
- cluster_name = "aux"
- remote_database = "posthog"
- remote_table = "sharded_usage_report_events_preagg"
- sharding_key = "sipHash64(date)"
- }
- }
- table "web_overview_preaggregated" {
- column "team_id" {
- type = "Int64"
- }
- column "job_id" {
- type = "UUID"
- }
- column "time_window_start" {
- type = "DateTime64(6, 'UTC')"
- }
- column "uniq_users_state" {
- type = "AggregateFunction(uniq, UUID)"
- }
- column "uniq_sessions_state" {
- type = "AggregateFunction(uniq, String)"
- }
- column "sum_pageviews_state" {
- type = "AggregateFunction(sum, Int64)"
- }
- column "avg_duration_state" {
- type = "AggregateFunction(avg, Float64)"
- }
- column "avg_bounce_state" {
- type = "AggregateFunction(avg, Int64)"
- }
- column "computed_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now()"
- }
- column "expires_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now() + toIntervalDay(7)"
- }
- engine "distributed" {
- cluster_name = "aux"
- remote_database = "posthog"
- remote_table = "sharded_web_overview_preaggregated"
- sharding_key = "sipHash64(job_id)"
- }
- }
- table "web_pre_aggregated_bounces" {
- order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_loggedIn", "mat_metadata_backend"]
- partition_by = "toYYYYMMDD(period_bucket)"
- settings = {
- index_granularity = "8192"
- }
- column "period_bucket" {
- type = "DateTime"
- }
- column "team_id" {
- type = "UInt64"
- }
- column "host" {
- type = "String"
- }
- column "device_type" {
- type = "String"
- }
- column "entry_pathname" {
- type = "String"
- }
- column "end_pathname" {
- type = "String"
- }
- column "browser" {
- type = "String"
- }
- column "os" {
- type = "String"
- }
- column "viewport_width" {
- type = "Int64"
- }
- column "viewport_height" {
- type = "Int64"
- }
- column "referring_domain" {
- type = "String"
- }
- column "utm_source" {
- type = "String"
- }
- column "utm_medium" {
- type = "String"
- }
- column "utm_campaign" {
- type = "String"
- }
- column "utm_term" {
- type = "String"
- }
- column "utm_content" {
- type = "String"
- }
- column "country_code" {
- type = "String"
- }
- column "city_name" {
- type = "String"
- }
- column "region_code" {
- type = "String"
- }
- column "region_name" {
- type = "String"
- }
- column "has_gclid" {
- type = "Bool"
- }
- column "has_gad_source_paid_search" {
- type = "Bool"
- }
- column "has_fbclid" {
- type = "Bool"
- }
- column "mat_metadata_loggedIn" {
- type = "Bool"
- }
- column "mat_metadata_backend" {
- type = "String"
- }
- column "persons_uniq_state" {
- type = "AggregateFunction(uniq, UUID)"
- }
- column "sessions_uniq_state" {
- type = "AggregateFunction(uniq, String)"
- }
- column "pageviews_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "bounces_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "total_session_duration_state" {
- type = "AggregateFunction(sum, Int64)"
- }
- column "total_session_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces"
- replica_name = "{replica}-{shard}"
- }
- }
- table "web_pre_aggregated_bounces_staging" {
- order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_loggedIn", "mat_metadata_backend"]
- partition_by = "toYYYYMMDD(period_bucket)"
- settings = {
- index_granularity = "8192"
- }
- column "period_bucket" {
- type = "DateTime"
- }
- column "team_id" {
- type = "UInt64"
- }
- column "host" {
- type = "String"
- }
- column "device_type" {
- type = "String"
- }
- column "entry_pathname" {
- type = "String"
- }
- column "end_pathname" {
- type = "String"
- }
- column "browser" {
- type = "String"
- }
- column "os" {
- type = "String"
- }
- column "viewport_width" {
- type = "Int64"
- }
- column "viewport_height" {
- type = "Int64"
- }
- column "referring_domain" {
- type = "String"
- }
- column "utm_source" {
- type = "String"
- }
- column "utm_medium" {
- type = "String"
- }
- column "utm_campaign" {
- type = "String"
- }
- column "utm_term" {
- type = "String"
- }
- column "utm_content" {
- type = "String"
- }
- column "country_code" {
- type = "String"
- }
- column "city_name" {
- type = "String"
- }
- column "region_code" {
- type = "String"
- }
- column "region_name" {
- type = "String"
- }
- column "has_gclid" {
- type = "Bool"
- }
- column "has_gad_source_paid_search" {
- type = "Bool"
- }
- column "has_fbclid" {
- type = "Bool"
- }
- column "mat_metadata_loggedIn" {
- type = "Bool"
- }
- column "mat_metadata_backend" {
- type = "String"
- }
- column "persons_uniq_state" {
- type = "AggregateFunction(uniq, UUID)"
- }
- column "sessions_uniq_state" {
- type = "AggregateFunction(uniq, String)"
- }
- column "pageviews_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "bounces_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "total_session_duration_state" {
- type = "AggregateFunction(sum, Int64)"
- }
- column "total_session_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces_staging"
- replica_name = "{replica}-{shard}"
- }
- }
- table "web_pre_aggregated_stats" {
- order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_loggedIn", "mat_metadata_backend"]
- partition_by = "toYYYYMMDD(period_bucket)"
- settings = {
- index_granularity = "8192"
- }
- column "period_bucket" {
- type = "DateTime"
- }
- column "team_id" {
- type = "UInt64"
- }
- column "host" {
- type = "String"
- }
- column "device_type" {
- type = "String"
- }
- column "pathname" {
- type = "String"
- }
- column "entry_pathname" {
- type = "String"
- }
- column "end_pathname" {
- type = "String"
- }
- column "browser" {
- type = "String"
- }
- column "os" {
- type = "String"
- }
- column "viewport_width" {
- type = "Int64"
- }
- column "viewport_height" {
- type = "Int64"
- }
- column "referring_domain" {
- type = "String"
- }
- column "utm_source" {
- type = "String"
- }
- column "utm_medium" {
- type = "String"
- }
- column "utm_campaign" {
- type = "String"
- }
- column "utm_term" {
- type = "String"
- }
- column "utm_content" {
- type = "String"
- }
- column "country_code" {
- type = "String"
- }
- column "city_name" {
- type = "String"
- }
- column "region_code" {
- type = "String"
- }
- column "region_name" {
- type = "String"
- }
- column "has_gclid" {
- type = "Bool"
- }
- column "has_gad_source_paid_search" {
- type = "Bool"
- }
- column "has_fbclid" {
- type = "Bool"
- }
- column "mat_metadata_loggedIn" {
- type = "Bool"
- }
- column "mat_metadata_backend" {
- type = "String"
- }
- column "persons_uniq_state" {
- type = "AggregateFunction(uniq, UUID)"
- }
- column "sessions_uniq_state" {
- type = "AggregateFunction(uniq, String)"
- }
- column "pageviews_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats"
- replica_name = "{replica}-{shard}"
- }
- }
- table "web_pre_aggregated_stats_staging" {
- order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_loggedIn", "mat_metadata_backend"]
- partition_by = "toYYYYMMDD(period_bucket)"
- settings = {
- index_granularity = "8192"
- }
- column "period_bucket" {
- type = "DateTime"
- }
- column "team_id" {
- type = "UInt64"
- }
- column "host" {
- type = "String"
- }
- column "device_type" {
- type = "String"
- }
- column "pathname" {
- type = "String"
- }
- column "entry_pathname" {
- type = "String"
- }
- column "end_pathname" {
- type = "String"
- }
- column "browser" {
- type = "String"
- }
- column "os" {
- type = "String"
- }
- column "viewport_width" {
- type = "Int64"
- }
- column "viewport_height" {
- type = "Int64"
- }
- column "referring_domain" {
- type = "String"
- }
- column "utm_source" {
- type = "String"
- }
- column "utm_medium" {
- type = "String"
- }
- column "utm_campaign" {
- type = "String"
- }
- column "utm_term" {
- type = "String"
- }
- column "utm_content" {
- type = "String"
- }
- column "country_code" {
- type = "String"
- }
- column "city_name" {
- type = "String"
- }
- column "region_code" {
- type = "String"
- }
- column "region_name" {
- type = "String"
- }
- column "has_gclid" {
- type = "Bool"
- }
- column "has_gad_source_paid_search" {
- type = "Bool"
- }
- column "has_fbclid" {
- type = "Bool"
- }
- column "mat_metadata_loggedIn" {
- type = "Bool"
- }
- column "mat_metadata_backend" {
- type = "String"
- }
- column "persons_uniq_state" {
- type = "AggregateFunction(uniq, UUID)"
- }
- column "sessions_uniq_state" {
- type = "AggregateFunction(uniq, String)"
- }
- column "pageviews_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats_staging"
- replica_name = "{replica}-{shard}"
- }
- }
- table "web_stats_paths_preaggregated" {
- column "team_id" {
- type = "Int64"
- }
- column "job_id" {
- type = "UUID"
- }
- column "time_window_start" {
- type = "DateTime64(6, 'UTC')"
- }
- column "breakdown_value" {
- type = "String"
- }
- column "uniq_users_state" {
- type = "AggregateFunction(uniq, UUID)"
- }
- column "sum_pageviews_state" {
- type = "AggregateFunction(sum, Int64)"
- }
- column "avg_bounce_state" {
- type = "AggregateFunction(avg, Nullable(Float64))"
- }
- column "computed_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now()"
- }
- column "expires_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now() + toIntervalDay(7)"
- }
- engine "distributed" {
- cluster_name = "aux"
- remote_database = "posthog"
- remote_table = "sharded_web_stats_paths_preaggregated"
- sharding_key = "sipHash64(job_id)"
- }
- }
- table "web_stats_paths_preaggregated_pathkey" {
- column "team_id" {
- type = "Int64"
- }
- column "job_id" {
- type = "UUID"
- }
- column "time_window_start" {
- type = "DateTime64(6, 'UTC')"
- }
- column "breakdown_value" {
- type = "String"
- }
- column "uniq_users_state" {
- type = "AggregateFunction(uniq, UUID)"
- }
- column "sum_pageviews_state" {
- type = "AggregateFunction(sum, Int64)"
- }
- column "avg_bounce_state" {
- type = "AggregateFunction(avg, Nullable(Float64))"
- }
- column "computed_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now()"
- }
- column "expires_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now() + toIntervalDay(7)"
- }
- engine "distributed" {
- cluster_name = "aux"
- remote_database = "posthog"
- remote_table = "sharded_web_stats_paths_preaggregated_pathkey"
- sharding_key = "sipHash64(breakdown_value)"
- }
- }
- table "writable_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 "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "consumer_breadcrumbs" {
- type = "Array(String)"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_events"
- sharding_key = "sipHash64(distinct_id)"
- }
- }
- table "writable_posthog_document_embeddings_text_embedding_3_large_3072" {
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- default = "''"
- }
- column "metadata" {
- type = "String"
- default = "'{}'"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_posthog_document_embeddings_text_embedding_3_large_3072"
- sharding_key = "cityHash64(document_id)"
- }
- }
- table "writable_posthog_document_embeddings_text_embedding_3_small_1536" {
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- default = "''"
- }
- column "metadata" {
- type = "String"
- default = "'{}'"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_posthog_document_embeddings_text_embedding_3_small_1536"
- sharding_key = "cityHash64(document_id)"
- }
- }
- table "writable_raw_sessions" {
- column "team_id" {
- type = "Int64"
- }
- column "session_id_v7" {
- type = "UInt128"
- }
- column "distinct_id" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "max_inserted_at" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "end_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "last_external_click_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "initial_browser" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_browser_version" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_os" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_os_version" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_device_type" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_viewport_width" {
- type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
- }
- column "initial_viewport_height" {
- type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_country_code" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_1_code" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_1_name" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_city_name" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_time_zone" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_referring_domain" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_campaign" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_medium" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_term" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_content" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gad_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclsrc" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_dclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_wbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_fbclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_msclkid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_twclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_li_fat_id" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_mc_cid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_igshid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_ttclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_epik" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_qclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_sccid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial__kx" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_irclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "pageview_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "pageview_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "autocapture_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "autocapture_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "screen_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "screen_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "maybe_has_session_replay" {
- type = "SimpleAggregateFunction(max, Bool)"
- }
- column "page_screen_autocapture_uniq_up_to" {
- type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
- }
- column "vitals_lcp" {
- type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_raw_sessions"
- sharding_key = "cityHash64(session_id_v7)"
- }
- }
- table "writable_raw_sessions_v3" {
- column "team_id" {
- type = "Int64"
- }
- column "session_id_v7" {
- type = "UInt128"
- }
- column "session_timestamp" {
- type = "DateTime64(3)"
- default = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
- }
- column "distinct_id" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "distinct_ids" {
- type = "AggregateFunction(groupUniqArray, String)"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "max_inserted_at" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "end_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "last_external_click_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "browser" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "browser_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "os" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "os_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "device_type" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "viewport_width" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
- }
- column "viewport_height" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
- }
- column "geoip_country_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_1_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_1_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_city_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_time_zone" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_referring_domain" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_campaign" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_medium" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_term" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_content" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_gclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_gad_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_fbclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_has_gclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
- }
- column "entry_has_fbclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
- }
- column "entry_ad_ids_map" {
- type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
- }
- column "entry_ad_ids_set" {
- type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
- }
- column "entry_channel_type_properties" {
- type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
- }
- column "pageview_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "autocapture_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "screen_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "page_screen_uniq_up_to" {
- type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
- }
- column "has_autocapture" {
- type = "SimpleAggregateFunction(max, Bool)"
- }
- column "flag_values" {
- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
- }
- column "flag_keys" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "event_names" {
- type = "SimpleAggregateFunction(groupUniqArrayArray(2000), 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)"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_raw_sessions_v3"
- sharding_key = "cityHash64(session_id_v7)"
- }
- }
- table "writable_session_replay_embeddings" {
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "embeddings" {
- type = "Array(Float32)"
- }
- column "generation_timestamp" {
- type = "DateTime64(6, 'UTC')"
- default = "now('UTC')"
- }
- column "source_type" {
- type = "LowCardinality(String)"
- }
- column "input" {
- type = "String"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_session_replay_embeddings"
- sharding_key = "sipHash64(session_id)"
- }
- }
- table "writable_sessions" {
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "SimpleAggregateFunction(any, String)"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "exit_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "initial_referring_domain" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_campaign" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_medium" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_term" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_content" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gad_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclsrc" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_dclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_wbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_fbclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_msclkid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_twclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_li_fat_id" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_mc_cid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_igshid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_ttclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_epik" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_qclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_sccid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "event_count_map" {
- type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
- }
- column "pageview_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "autocapture_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_sessions"
- sharding_key = "sipHash64(session_id)"
- }
- }
- table "writeable_performance_events" {
- column "uuid" {
- type = "UUID"
- }
- column "session_id" {
- type = "String"
- }
- column "window_id" {
- type = "String"
- }
- column "pageview_id" {
- type = "String"
- }
- column "distinct_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3)"
- }
- column "time_origin" {
- type = "DateTime64(3, 'UTC')"
- }
- column "entry_type" {
- type = "LowCardinality(String)"
- }
- column "name" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "current_url" {
- type = "String"
- }
- column "start_time" {
- type = "Float64"
- }
- column "duration" {
- type = "Float64"
- }
- column "redirect_start" {
- type = "Float64"
- }
- column "redirect_end" {
- type = "Float64"
- }
- column "worker_start" {
- type = "Float64"
- }
- column "fetch_start" {
- type = "Float64"
- }
- column "domain_lookup_start" {
- type = "Float64"
- }
- column "domain_lookup_end" {
- type = "Float64"
- }
- column "connect_start" {
- type = "Float64"
- }
- column "secure_connection_start" {
- type = "Float64"
- }
- column "connect_end" {
- type = "Float64"
- }
- column "request_start" {
- type = "Float64"
- }
- column "response_start" {
- type = "Float64"
- }
- column "response_end" {
- type = "Float64"
- }
- column "decoded_body_size" {
- type = "Int64"
- }
- column "encoded_body_size" {
- type = "Int64"
- }
- column "initiator_type" {
- type = "LowCardinality(String)"
- }
- column "next_hop_protocol" {
- type = "LowCardinality(String)"
- }
- column "render_blocking_status" {
- type = "LowCardinality(String)"
- }
- column "response_status" {
- type = "Int64"
- }
- column "transfer_size" {
- type = "Int64"
- }
- column "largest_contentful_paint_element" {
- type = "String"
- }
- column "largest_contentful_paint_render_time" {
- type = "Float64"
- }
- column "largest_contentful_paint_load_time" {
- type = "Float64"
- }
- column "largest_contentful_paint_size" {
- type = "Float64"
- }
- column "largest_contentful_paint_id" {
- type = "String"
- }
- column "largest_contentful_paint_url" {
- type = "String"
- }
- column "dom_complete" {
- type = "Float64"
- }
- column "dom_content_loaded_event" {
- type = "Float64"
- }
- column "dom_interactive" {
- type = "Float64"
- }
- column "load_event_end" {
- type = "Float64"
- }
- column "load_event_start" {
- type = "Float64"
- }
- column "redirect_count" {
- type = "Int64"
- }
- column "navigation_type" {
- type = "LowCardinality(String)"
- }
- column "unload_event_end" {
- type = "Float64"
- }
- column "unload_event_start" {
- type = "Float64"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_performance_events"
- sharding_key = "sipHash64(session_id)"
- }
- }
- materialized_view "events_json_mv" {
- to_table = "posthog.writable_events"
- query = file("sql/events_json_mv.sql")
-
- 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 "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"
- }
- column "group0_properties" {
- type = "String"
- }
- column "group1_properties" {
- type = "String"
- }
- column "group2_properties" {
- type = "String"
- }
- column "group3_properties" {
- type = "String"
- }
- column "group4_properties" {
- type = "String"
- }
- 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 "_timestamp" {
- type = "Nullable(DateTime)"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "consumer_breadcrumbs" {
- type = "Array(String)"
- }
- }
- materialized_view "events_recent_json_mv" {
- to_table = "posthog.writable_events_recent"
- query = file("sql/events_recent_json_mv.sql")
-
- 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 "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"
- }
- column "group0_properties" {
- type = "String"
- }
- column "group1_properties" {
- type = "String"
- }
- column "group2_properties" {
- type = "String"
- }
- column "group3_properties" {
- type = "String"
- }
- column "group4_properties" {
- type = "String"
- }
- 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 "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- }
- materialized_view "performance_events_mv" {
- to_table = "posthog.writeable_performance_events"
- query = file("sql/performance_events_mv.sql")
-
- column "uuid" {
- type = "UUID"
- }
- column "session_id" {
- type = "String"
- }
- column "window_id" {
- type = "String"
- }
- column "pageview_id" {
- type = "String"
- }
- column "distinct_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3)"
- }
- column "time_origin" {
- type = "DateTime64(3, 'UTC')"
- }
- column "entry_type" {
- type = "LowCardinality(String)"
- }
- column "name" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "current_url" {
- type = "String"
- }
- column "start_time" {
- type = "Float64"
- }
- column "duration" {
- type = "Float64"
- }
- column "redirect_start" {
- type = "Float64"
- }
- column "redirect_end" {
- type = "Float64"
- }
- column "worker_start" {
- type = "Float64"
- }
- column "fetch_start" {
- type = "Float64"
- }
- column "domain_lookup_start" {
- type = "Float64"
- }
- column "domain_lookup_end" {
- type = "Float64"
- }
- column "connect_start" {
- type = "Float64"
- }
- column "secure_connection_start" {
- type = "Float64"
- }
- column "connect_end" {
- type = "Float64"
- }
- column "request_start" {
- type = "Float64"
- }
- column "response_start" {
- type = "Float64"
- }
- column "response_end" {
- type = "Float64"
- }
- column "decoded_body_size" {
- type = "Int64"
- }
- column "encoded_body_size" {
- type = "Int64"
- }
- column "initiator_type" {
- type = "LowCardinality(String)"
- }
- column "next_hop_protocol" {
- type = "LowCardinality(String)"
- }
- column "render_blocking_status" {
- type = "LowCardinality(String)"
- }
- column "response_status" {
- type = "Int64"
- }
- column "transfer_size" {
- type = "Int64"
- }
- column "largest_contentful_paint_element" {
- type = "String"
- }
- column "largest_contentful_paint_render_time" {
- type = "Float64"
- }
- column "largest_contentful_paint_load_time" {
- type = "Float64"
- }
- column "largest_contentful_paint_size" {
- type = "Float64"
- }
- column "largest_contentful_paint_id" {
- type = "String"
- }
- column "largest_contentful_paint_url" {
- type = "String"
- }
- column "dom_complete" {
- type = "Float64"
- }
- column "dom_content_loaded_event" {
- type = "Float64"
- }
- column "dom_interactive" {
- type = "Float64"
- }
- column "load_event_end" {
- type = "Float64"
- }
- column "load_event_start" {
- type = "Float64"
- }
- column "redirect_count" {
- type = "Int64"
- }
- column "navigation_type" {
- type = "LowCardinality(String)"
- }
- column "unload_event_end" {
- type = "Float64"
- }
- column "unload_event_start" {
- type = "Float64"
- }
- column "_timestamp" {
- type = "Nullable(DateTime)"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- }
- materialized_view "person_distinct_id_mv" {
- to_table = "posthog.person_distinct_id"
- query = file("sql/person_distinct_id_mv.sql")
-
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "team_id" {
- type = "Int64"
- }
- column "_sign" {
- type = "Int16"
- }
- column "_timestamp" {
- type = "Nullable(DateTime)"
- }
- column "_offset" {
- type = "UInt64"
- }
- }
- materialized_view "person_overrides_mv" {
- to_table = "posthog.person_overrides"
- query = file("sql/person_overrides_mv.sql")
-
- column "team_id" {
- type = "Int32"
- }
- column "old_person_id" {
- type = "UUID"
- }
- column "override_person_id" {
- type = "UUID"
- }
- column "merged_at" {
- type = "DateTime64(6, 'UTC')"
- }
- column "oldest_event" {
- type = "DateTime64(6, 'UTC')"
- }
- column "version" {
- type = "Int32"
- }
- }
- materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
- to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
- query = file("sql/posthog_document_embeddings_text_embedding_3_large_3072_mv.sql")
-
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- }
- column "metadata" {
- type = "String"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- }
- materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
- to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
- query = file("sql/posthog_document_embeddings_text_embedding_3_small_1536_mv.sql")
-
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- }
- column "metadata" {
- type = "String"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- }
- materialized_view "raw_sessions_mv" {
- to_table = "posthog.writable_raw_sessions"
- query = file("sql/raw_sessions_mv.sql")
-
- column "team_id" {
- type = "Int64"
- }
- column "session_id_v7" {
- type = "UInt128"
- }
- column "distinct_id" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "min_timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "max_timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "max_inserted_at" {
- type = "DateTime64(6, 'UTC')"
- }
- column "urls" {
- type = "Array(String)"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "end_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "last_external_click_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "initial_browser" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_browser_version" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_os" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_os_version" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_device_type" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_viewport_width" {
- type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
- }
- column "initial_viewport_height" {
- type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_country_code" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_1_code" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_1_name" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_city_name" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_time_zone" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_referring_domain" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_campaign" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_medium" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_term" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_content" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gad_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclsrc" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_dclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_wbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_fbclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_msclkid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_twclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_li_fat_id" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_mc_cid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_igshid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_ttclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_epik" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_qclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_sccid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial__kx" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_irclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "pageview_count" {
- type = "UInt64"
- }
- column "pageview_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "autocapture_count" {
- type = "UInt64"
- }
- column "autocapture_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "screen_count" {
- type = "UInt64"
- }
- column "screen_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "maybe_has_session_replay" {
- type = "Bool"
- }
- column "page_screen_autocapture_uniq_up_to" {
- type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
- }
- column "vitals_lcp" {
- type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
- }
- }
- materialized_view "sessions_mv" {
- to_table = "posthog.writable_sessions"
- query = file("sql/sessions_mv.sql")
-
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "min_timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "max_timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "urls" {
- type = "Array(String)"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "exit_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "initial_referring_domain" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_campaign" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_medium" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_term" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_content" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gad_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclsrc" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_dclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_wbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_fbclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_msclkid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_twclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_li_fat_id" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_mc_cid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_igshid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_ttclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_epik" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_qclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_sccid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "event_count_map" {
- type = "Map(String, UInt64)"
- }
- column "pageview_count" {
- type = "UInt64"
- }
- column "autocapture_count" {
- type = "UInt64"
- }
- }
- view "events_batch_export" {
- query = <<SQL
-SELECT
- team_id AS team_id,
- timestamp AS timestamp,
- event AS event,
- distinct_id AS distinct_id,
- toString(uuid) AS uuid,
- coalesce(inserted_at, _timestamp) AS _inserted_at,
- created_at AS created_at,
- elements_chain AS elements_chain,
- toString(person_id) AS person_id,
- nullIf(properties, '') AS properties,
- nullIf(person_properties, '') AS person_properties,
- nullIf(JSONExtractString(properties, '$set'), '') AS set,
- nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
-FROM posthog.events
-PREWHERE
- (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
-WHERE
- (team_id = {team_id: Int64})
-AND
- (events.timestamp >= ({interval_start: DateTime64} - toIntervalDay({lookback_days: Int32})))
-AND
- (events.timestamp < ({interval_end: DateTime64} + toIntervalDay(1)))
-AND
- ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
-AND
- ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
-ORDER BY _inserted_at ASC, event ASC
-LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
-SETTINGS
- optimize_aggregation_in_order = 1
-SQL
-
- }
- view "events_batch_export_backfill" {
- query = <<SQL
-SELECT
- team_id AS team_id,
- timestamp AS timestamp,
- event AS event,
- distinct_id AS distinct_id,
- toString(uuid) AS uuid,
- timestamp AS _inserted_at,
- created_at AS created_at,
- elements_chain AS elements_chain,
- toString(person_id) AS person_id,
- nullIf(properties, '') AS properties,
- nullIf(person_properties, '') AS person_properties,
- nullIf(JSONExtractString(properties, '$set'), '') AS set,
- nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
-FROM posthog.events
-WHERE
- (team_id = {team_id: Int64})
-AND
- (events.timestamp >= {interval_start: DateTime64})
-AND
- (events.timestamp < {interval_end: DateTime64})
-AND
- ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
-AND
- ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
-ORDER BY _inserted_at ASC, event ASC
-LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
-SETTINGS
- optimize_aggregation_in_order = 1
-SQL
-
- }
- view "events_batch_export_recent" {
- query = <<SQL
-SELECT
- team_id AS team_id,
- timestamp AS timestamp,
- event AS event,
- distinct_id AS distinct_id,
- toString(uuid) AS uuid,
- inserted_at AS _inserted_at,
- created_at AS created_at,
- elements_chain AS elements_chain,
- toString(person_id) AS person_id,
- nullIf(properties, '') AS properties,
- nullIf(person_properties, '') AS person_properties,
- nullIf(JSONExtractString(properties, '$set'), '') AS set,
- nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
-FROM posthog.events_recent
-PREWHERE
- (events_recent.inserted_at >= {interval_start: DateTime64}) AND (events_recent.inserted_at < {interval_end: DateTime64})
-WHERE
- (team_id = {team_id: Int64})
-AND
- ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
-AND
- ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
-ORDER BY _inserted_at ASC, event ASC
-LIMIT 1 BY team_id, event, cityHash64(events_recent.distinct_id), cityHash64(events_recent.uuid)
-SETTINGS
- optimize_aggregation_in_order = 1
-SQL
-
- }
- view "events_batch_export_unbounded" {
- query = <<SQL
-SELECT
- team_id AS team_id,
- timestamp AS timestamp,
- event AS event,
- distinct_id AS distinct_id,
- toString(uuid) AS uuid,
- coalesce(inserted_at, _timestamp) AS _inserted_at,
- created_at AS created_at,
- elements_chain AS elements_chain,
- toString(person_id) AS person_id,
- nullIf(properties, '') AS properties,
- nullIf(person_properties, '') AS person_properties,
- nullIf(JSONExtractString(properties, '$set'), '') AS set,
- nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
-FROM posthog.events
-PREWHERE
- (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
-WHERE
- (team_id = {team_id: Int64})
-AND
- ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
-AND
- ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
-ORDER BY _inserted_at ASC, event ASC
-LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
-SETTINGS
- optimize_aggregation_in_order = 1
-SQL
-
- }
- view "persons_batch_export" {
- query = <<SQL
-WITH
- new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING ((_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64}))),
- new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING ((argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64}))),
- all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
-SELECT
- p.team_id AS team_id,
- pd.distinct_id AS distinct_id,
- toString(p.id) AS person_id,
- p.properties AS properties,
- pd.version AS person_distinct_id_version,
- p.version AS person_version,
- p.created_at AS created_at,
- multiIf(
- ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
- AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
- pd._timestamp,
- ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
- AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
- p._timestamp,
- least(p._timestamp, pd._timestamp)
- ) AS _inserted_at
-FROM
- posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
-WHERE
- (team_id = {team_id: Int64})
-AND
- ((id, version) IN (all_new_persons))
-ORDER BY _inserted_at ASC
-SQL
-
- }
- view "persons_batch_export_backfill" {
- query = <<SQL
-SELECT
- pd.team_id AS team_id,
- pd.distinct_id AS distinct_id,
- toString(p.id) AS person_id,
- p.properties AS properties,
- pd.version AS person_distinct_id_version,
- p.version AS person_version,
- p.created_at AS created_at,
- multiIf(
- (pd._timestamp < {interval_end: DateTime64})
- AND (NOT (p._timestamp < {interval_end: DateTime64})),
- pd._timestamp,
- (p._timestamp < {interval_end: DateTime64})
- AND (NOT (pd._timestamp < {interval_end: DateTime64})),
- p._timestamp,
- least(p._timestamp, pd._timestamp)
- ) AS _inserted_at
-FROM
- (SELECT team_id, distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 PREWHERE team_id = {team_id: Int64} GROUP BY team_id, distinct_id) AS pd INNER JOIN (SELECT team_id, id, max(version) AS version, argMax(properties, person.version) AS properties, argMax(created_at, person.version) AS created_at, argMax(_timestamp, person.version) AS _timestamp FROM posthog.person PREWHERE team_id = {team_id: Int64} GROUP BY team_id, id) AS p ON (p.id = pd.person_id) AND (p.team_id = pd.team_id)
-WHERE
- (pd.team_id = {team_id: Int64})
-AND
- (p.team_id = {team_id: Int64})
-AND
- ((pd._timestamp < {interval_end: DateTime64}) OR (p._timestamp < {interval_end: DateTime64}))
-ORDER BY _inserted_at ASC
-SQL
-
- }
- view "posthog_document_embeddings_union_view" {
- query = <<SQL
-SELECT
- team_id,
- product,
- document_type,
- rendering,
- document_id,
- timestamp,
- inserted_at,
- content,
- metadata,
- embedding,
- _timestamp,
- _offset,
- _partition,
- 'text-embedding-3-small-1536' AS model_name
-FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_small_1536
-UNION ALL
-SELECT
- team_id,
- product,
- document_type,
- rendering,
- document_id,
- timestamp,
- inserted_at,
- content,
- metadata,
- embedding,
- _timestamp,
- _offset,
- _partition,
- 'text-embedding-3-large-3072' AS model_name
-FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_large_3072
-SQL
-
- }
- view "raw_sessions_v" {
- query = <<SQL
-SELECT
- session_id_v7,
- fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)) AS session_timestamp,
- team_id,
- argMaxMerge(distinct_id) AS distinct_id,
- 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(initial_browser) AS initial_browser,
- argMinMerge(initial_browser_version) AS initial_browser_version,
- argMinMerge(initial_os) AS initial_os,
- argMinMerge(initial_os_version) AS initial_os_version,
- argMinMerge(initial_device_type) AS initial_device_type,
- argMinMerge(initial_viewport_width) AS initial_viewport_width,
- argMinMerge(initial_viewport_height) AS initial_viewport_height,
- argMinMerge(initial_geoip_country_code) AS initial_geoip_country_code,
- argMinMerge(initial_geoip_subdivision_1_code) AS initial_geoip_subdivision_1_code,
- argMinMerge(initial_geoip_subdivision_1_name) AS initial_geoip_subdivision_1_name,
- argMinMerge(initial_geoip_subdivision_city_name) AS initial_geoip_subdivision_city_name,
- argMinMerge(initial_geoip_time_zone) AS initial_geoip_time_zone,
- argMinMerge(initial_utm_source) AS initial_utm_source,
- argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
- argMinMerge(initial_utm_medium) AS initial_utm_medium,
- argMinMerge(initial_utm_term) AS initial_utm_term,
- argMinMerge(initial_utm_content) AS initial_utm_content,
- argMinMerge(initial_referring_domain) AS initial_referring_domain,
- argMinMerge(initial_gclid) AS initial_gclid,
- argMinMerge(initial_gad_source) AS initial_gad_source,
- argMinMerge(initial_gclsrc) AS initial_gclsrc,
- argMinMerge(initial_dclid) AS initial_dclid,
- argMinMerge(initial_gbraid) AS initial_gbraid,
- argMinMerge(initial_wbraid) AS initial_wbraid,
- argMinMerge(initial_fbclid) AS initial_fbclid,
- argMinMerge(initial_msclkid) AS initial_msclkid,
- argMinMerge(initial_twclid) AS initial_twclid,
- argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
- argMinMerge(initial_mc_cid) AS initial_mc_cid,
- argMinMerge(initial_igshid) AS initial_igshid,
- argMinMerge(initial_ttclid) AS initial_ttclid,
- argMinMerge(initial__kx) AS initial__kx,
- argMinMerge(initial_irclid) AS initial_irclid,
- sum(pageview_count) AS pageview_count,
- uniqMerge(pageview_uniq) AS pageview_uniq,
- sum(autocapture_count) AS autocapture_count,
- uniqMerge(autocapture_uniq) AS autocapture_uniq,
- sum(screen_count) AS screen_count,
- uniqMerge(screen_uniq) AS screen_uniq,
- max(maybe_has_session_replay) AS maybe_has_session_replay,
- uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,
- argMinMerge(vitals_lcp) AS vitals_lcp
-FROM posthog.raw_sessions
-GROUP BY
- session_id_v7, team_id
-SQL
-
- }
- view "raw_sessions_v3_v" {
- query = <<SQL
-SELECT
- session_id_v7,
- session_timestamp,
- team_id,
- argMaxMerge(distinct_id) AS distinct_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,
- 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,
- 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_uniq_up_to) AS page_screen_uniq_up_to,
- max(has_autocapture) AS has_autocapture,
- groupUniqArrayMapMerge(flag_values) AS flag_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_events
-FROM posthog.raw_sessions_v3
-GROUP BY
- session_id_v7, session_timestamp, team_id
-SQL
-
- }
- view "sessions_v" {
- query = <<SQL
-SELECT
- session_id,
- team_id,
- any(distinct_id) AS distinct_id,
- min(min_timestamp) AS min_timestamp,
- max(max_timestamp) AS max_timestamp,
- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
- argMinMerge(entry_url) AS entry_url,
- argMaxMerge(exit_url) AS exit_url,
- argMinMerge(initial_utm_source) AS initial_utm_source,
- argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
- argMinMerge(initial_utm_medium) AS initial_utm_medium,
- argMinMerge(initial_utm_term) AS initial_utm_term,
- argMinMerge(initial_utm_content) AS initial_utm_content,
- argMinMerge(initial_referring_domain) AS initial_referring_domain,
- argMinMerge(initial_gclid) AS initial_gclid,
- argMinMerge(initial_gad_source) AS initial_gad_source,
- argMinMerge(initial_gclsrc) AS initial_gclsrc,
- argMinMerge(initial_dclid) AS initial_dclid,
- argMinMerge(initial_gbraid) AS initial_gbraid,
- argMinMerge(initial_wbraid) AS initial_wbraid,
- argMinMerge(initial_fbclid) AS initial_fbclid,
- argMinMerge(initial_msclkid) AS initial_msclkid,
- argMinMerge(initial_twclid) AS initial_twclid,
- argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
- argMinMerge(initial_mc_cid) AS initial_mc_cid,
- argMinMerge(initial_igshid) AS initial_igshid,
- argMinMerge(initial_ttclid) AS initial_ttclid,
- argMinMerge(initial_epik) AS initial_epik,
- argMinMerge(initial_qclid) AS initial_qclid,
- argMinMerge(initial_sccid) AS initial_sccid,
- sumMap(event_count_map) AS event_count_map,
- sum(pageview_count) AS pageview_count,
- sum(autocapture_count) AS autocapture_count
-FROM posthog.sessions
-GROUP BY
- session_id, team_id
-SQL
-
- }
- dictionary "exchange_rate_dict" {
- primary_key = ["currency"]
- lifetime {
- min = 3000
- max = 3600
- }
- range {
- min = "start_date"
- max = "end_date"
- }
- attribute "currency" {
- type = "String"
- }
- attribute "start_date" {
- type = "Date"
- }
- attribute "end_date" {
- type = "Nullable(Date)"
- }
- attribute "rate" {
- type = "Decimal64(10)"
- }
- source "clickhouse" {
- user = "default"
- query = "SELECT currency, date AS start_date, leadInFrame(date::Nullable(Date), 1, NULL::Nullable(Date)) OVER w AS end_date, argMax(rate, version) AS rate FROM `posthog`.`exchange_rate` GROUP BY date, currency WINDOW w AS ( PARTITION BY currency ORDER BY date ASC ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING )"
- }
- layout "complex_key_range_hashed" {
- range_lookup_strategy = "max"
- }
- }
- dictionary "person_distinct_id_overrides_dict" {
- primary_key = ["team_id", "distinct_id"]
- lifetime {
- min = 3600
- max = 18000
- }
- attribute "team_id" {
- type = "Int64"
- }
- attribute "distinct_id" {
+ column "country_code" {
type = "String"
}
- attribute "person_id" {
- type = "UUID"
- }
- source "clickhouse" {
- user = "default"
- query = "SELECT team_id, distinct_id, argMax(person_id, version) AS person_id FROM posthog.person_distinct_id_overrides GROUP BY team_id, distinct_id"
- }
- layout "complex_key_hashed" {
- }
- }
- dictionary "person_overrides_dict" {
- primary_key = ["team_id", "old_person_id"]
- lifetime {
- min = 5
- max = 10
- }
- attribute "team_id" {
- type = "INT"
- }
- attribute "old_person_id" {
- type = "UUID"
- }
- attribute "override_person_id" {
- type = "UUID"
- }
- source "clickhouse" {
- user = "default"
- query = "\\nSELECT\\n team_id,\\n old_person_id,\\n argMax(override_person_id, version)\\nFROM\\n `posthog`.`person_overrides` AS overrides\\nGROUP BY\\n team_id,\\n old_person_id\\n"
- }
- layout "complex_key_hashed" {
- 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"
+ column "city_name" {
+ type = "String"
}
- 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)"
+ column "region_code" {
+ type = "String"
}
- drop_columns = ["mat_historical_migration"]
- column "elements_chain" {
+ column "region_name" {
type = "String"
}
- column "person_id" {
- type = "UUID"
+ column "has_gclid" {
+ type = "Bool"
}
- column "person_created_at" {
- type = "DateTime64(3)"
+ column "has_gad_source_paid_search" {
+ type = "Bool"
}
- column "person_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "has_fbclid" {
+ type = "Bool"
}
- column "group0_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "mat_metadata_loggedIn" {
+ type = "Bool"
}
- column "group1_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "mat_metadata_backend" {
+ type = "String"
}
- column "group2_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
}
- column "group3_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
}
- column "group4_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
}
- column "group0_created_at" {
- type = "DateTime64(3)"
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
}
- column "group1_created_at" {
- type = "DateTime64(3)"
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
}
- column "group2_created_at" {
- type = "DateTime64(3)"
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
}
- column "group3_created_at" {
- type = "DateTime64(3)"
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces_staging"
+ replica_name = "{replica}-{shard}"
}
- column "group4_created_at" {
- type = "DateTime64(3)"
+ }
+
+ table "web_pre_aggregated_stats_staging" {
+ order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_loggedIn", "mat_metadata_backend"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
}
- column "_timestamp" {
+ column "period_bucket" {
type = "DateTime"
}
- column "_offset" {
+ column "team_id" {
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
+ column "host" {
+ type = "String"
}
- index "minmax_$group_3" {
- expr = "`$group_3`"
- type = "minmax"
- granularity = 1
+ column "device_type" {
+ type = "String"
}
- index "minmax_$group_4" {
- expr = "`$group_4`"
- type = "minmax"
- granularity = 1
+ column "pathname" {
+ type = "String"
}
- index "minmax_$window_id" {
- expr = "`$window_id`"
- type = "minmax"
- granularity = 1
+ column "entry_pathname" {
+ type = "String"
}
- index "minmax_$session_id" {
- expr = "`$session_id`"
- type = "minmax"
- granularity = 1
+ column "end_pathname" {
+ type = "String"
}
- index "kafka_timestamp_minmax_sharded_events" {
- expr = "_timestamp"
- type = "minmax"
- granularity = 3
+ column "browser" {
+ type = "String"
}
- index "is_deleted_idx" {
- expr = "(is_deleted)"
- type = "minmax"
- granularity = 1
+ column "os" {
+ type = "String"
}
- index "minmax_historical_migration" {
- expr = "(historical_migration)"
- type = "minmax"
- granularity = 1
+ column "viewport_width" {
+ type = "Int64"
}
- }
-
- patch_table "events" {
- modify_column "properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "viewport_height" {
+ type = "Int64"
}
- drop_columns = ["mat_historical_migration"]
- column "elements_chain" {
+ column "referring_domain" {
type = "String"
}
- column "person_id" {
- type = "UUID"
+ column "utm_source" {
+ type = "String"
}
- column "person_created_at" {
- type = "DateTime64(3)"
+ column "utm_medium" {
+ type = "String"
}
- column "person_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "utm_campaign" {
+ type = "String"
}
- column "group0_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "utm_term" {
+ type = "String"
}
- column "group1_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "utm_content" {
+ type = "String"
}
- column "group2_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "country_code" {
+ type = "String"
}
- column "group3_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "city_name" {
+ type = "String"
}
- column "group4_properties" {
- type = "String"
- codec = "ZSTD(3)"
+ column "region_code" {
+ type = "String"
}
- column "group0_created_at" {
- type = "DateTime64(3)"
+ column "region_name" {
+ type = "String"
}
- column "group1_created_at" {
- type = "DateTime64(3)"
+ column "has_gclid" {
+ type = "Bool"
}
- column "group2_created_at" {
- type = "DateTime64(3)"
+ column "has_gad_source_paid_search" {
+ type = "Bool"
}
- column "group3_created_at" {
- type = "DateTime64(3)"
+ column "has_fbclid" {
+ type = "Bool"
}
- column "group4_created_at" {
- type = "DateTime64(3)"
+ column "mat_metadata_loggedIn" {
+ type = "Bool"
}
- column "_timestamp" {
- type = "DateTime"
+ column "mat_metadata_backend" {
+ type = "String"
}
- column "_offset" {
- type = "UInt64"
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
}
- column "mat_$ai_trace_id" {
- type = "Nullable(String)"
- comment = "column_materializer::properties::$ai_trace_id"
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
}
- column "mat_$ai_experiment_id" {
- type = "Nullable(String)"
- comment = "column_materializer::properties::$ai_experiment_id"
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
}
- }
- table "billing_usage_records" {
- column "schema_version" { type = "UInt8" }
- column "record_id" { type = "String" }
- column "producer_id" { type = "LowCardinality(String)" }
- column "team_id" { type = "Int64" }
- column "organization_id" { type = "UUID" }
- column "usage_key" { type = "LowCardinality(String)" }
- column "unit" { type = "LowCardinality(String)" }
- column "quantity" { type = "Int64" }
- column "timestamp" { type = "DateTime64(6, 'UTC')" }
- column "inserted_at" { type = "DateTime64(6, 'UTC')" }
- column "_timestamp" { type = "DateTime" }
- column "_offset" { type = "UInt64" }
- column "_partition" { type = "UInt64" }
- engine "distributed" {
- cluster_name = "aux"
- remote_database = "posthog"
- remote_table = "sharded_billing_usage_records"
- sharding_key = "cityHash64(team_id)"
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats_staging"
+ replica_name = "{replica}-{shard}"
}
}
}
diff --git a/posthog/clickhouse/hcl/roles/data/prod-eu/tables.hcl b/posthog/clickhouse/hcl/roles/data/prod-eu/tables.hcl
new file mode 100644
index 000000000000..e70a51daef98
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/data/prod-eu/tables.hcl
@@ -0,0 +1,3387 @@
+# prod-eu data cluster: objects only prod-eu runs, and the deltas it applies to the cloud shape.
+database "posthog" {
+ table "asyncdeletion" {
+ override = true
+ order_by = ["deletion_type", "delete_verified_at"]
+ partition_by = "toYYYYMM(created_at)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "delete_verified_at" {
+ type = "DateTime"
+ }
+ column "created_by_id" {
+ type = "UInt64"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/asyncdeletion"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "kafka_session_replay_features" {
+ # The ingestion nodes declare this name too, for the table they write through.
+ # A data node holds a different object under it, so this restates rather than
+ # redeclares.
+ override = true
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "batch_id" {
+ type = "String"
+ }
+ column "first_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "last_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "event_count" {
+ type = "Int64"
+ }
+ column "mouse_position_count" {
+ type = "Int64"
+ }
+ column "mouse_sum_x" {
+ type = "Float64"
+ }
+ column "mouse_sum_x_squared" {
+ type = "Float64"
+ }
+ column "mouse_sum_y" {
+ type = "Float64"
+ }
+ column "mouse_sum_y_squared" {
+ type = "Float64"
+ }
+ column "mouse_distance_traveled" {
+ type = "Float64"
+ }
+ column "mouse_direction_change_count" {
+ type = "Int64"
+ }
+ column "mouse_velocity_sum" {
+ type = "Float64"
+ }
+ column "mouse_velocity_sum_of_squares" {
+ type = "Float64"
+ }
+ column "mouse_velocity_count" {
+ type = "Int64"
+ }
+ column "scroll_event_count" {
+ type = "Int64"
+ }
+ column "total_scroll_magnitude" {
+ type = "Float64"
+ }
+ column "scroll_direction_reversal_count" {
+ type = "Int64"
+ }
+ column "rapid_scroll_reversal_count" {
+ type = "Int64"
+ }
+ column "click_count" {
+ type = "Int64"
+ }
+ column "keypress_count" {
+ type = "Int64"
+ }
+ column "mouse_activity_count" {
+ type = "Int64"
+ }
+ column "rage_click_count" {
+ type = "Int64"
+ }
+ column "dead_click_count" {
+ type = "Int64"
+ }
+ column "inter_action_gap_count" {
+ type = "Int64"
+ }
+ column "inter_action_gap_sum_ms" {
+ type = "Float64"
+ }
+ column "inter_action_gap_sum_of_squares_ms" {
+ type = "Float64"
+ }
+ column "max_idle_gap_ms" {
+ type = "Float64"
+ }
+ column "quick_back_count" {
+ type = "Int64"
+ }
+ column "page_visit_count" {
+ type = "Int64"
+ }
+ column "visited_urls" {
+ type = "Array(String)"
+ }
+ column "console_error_count" {
+ type = "Int64"
+ }
+ column "console_error_after_click_count" {
+ type = "Int64"
+ }
+ column "network_request_count" {
+ type = "Int64"
+ }
+ column "network_failed_request_count" {
+ type = "Int64"
+ }
+ column "network_request_duration_sum" {
+ type = "Float64"
+ }
+ column "network_request_duration_sum_of_squares" {
+ type = "Float64"
+ }
+ column "network_request_duration_count" {
+ type = "Int64"
+ }
+ column "max_scroll_y" {
+ type = "Float64"
+ }
+ column "click_target_ids" {
+ type = "Array(Int64)"
+ }
+ column "text_selection_count" {
+ type = "Int64"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ engine "kafka" {
+ collection = "msk_cluster"
+ topic_list = "clickhouse_session_replay_features"
+ group_name = "group1"
+ format = "JSONEachRow"
+ }
+ }
+
+ table "metrics_query_log" {
+ order_by = ["toDate(timestamp)", "team_id", "query_type"]
+ partition_by = "toYYYYMM(timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "team_events_last_month" {
+ type = "UInt64"
+ }
+ column "user_id" {
+ type = "Int64"
+ }
+ column "kind" {
+ type = "String"
+ }
+ column "query_type" {
+ type = "String"
+ }
+ column "client_query_id" {
+ type = "String"
+ }
+ column "id" {
+ type = "String"
+ }
+ column "route_id" {
+ type = "String"
+ }
+ column "query_time_range_days" {
+ type = "Int64"
+ }
+ column "has_joins" {
+ type = "UInt8"
+ }
+ column "has_json_operations" {
+ type = "UInt8"
+ }
+ column "filter_by_type" {
+ type = "Array(String)"
+ }
+ column "breakdown_by" {
+ type = "Array(String)"
+ }
+ column "entity_math" {
+ type = "Array(String)"
+ }
+ column "filter" {
+ type = "String"
+ }
+ column "tables" {
+ type = "Array(LowCardinality(String))"
+ }
+ column "columns" {
+ type = "Array(LowCardinality(String))"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "log_comment" {
+ type = "String"
+ }
+ column "is_exception" {
+ type = "UInt8"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.metrics_query_log"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "new_writable_raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "new_writable_sessions" {
+ override = true
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "pending_person_deletes_reporting" {
+ override = true
+ order_by = ["team_id", "deletion_type", "key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "Nullable(String)"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "delete_verified_at" {
+ type = "Nullable(DateTime)"
+ }
+ column "created_by_id" {
+ type = "Nullable(String)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/pending_person_deletes_reporting"
+ replica_name = "{shard}-{replica}"
+ }
+ }
+
+ table "person" {
+ override = true
+ order_by = ["team_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ default = "0"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "last_seen_at" {
+ type = "Nullable(DateTime64(3))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_collapsing" {
+ override = true
+ order_by = ["team_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_sign" {
+ type = "Int8"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/noshard/posthog.person_collapsing"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "session_recording_events" {
+ override = true
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "has_full_snapshot" {
+ type = "Int8"
+ comment = "column_materializer::has_full_snapshot"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "events_summary" {
+ type = "Array(String)"
+ comment = "column_materializer::events_summary"
+ }
+ column "click_count" {
+ type = "Int8"
+ comment = "column_materializer::click_count"
+ }
+ column "keypress_count" {
+ type = "Int8"
+ comment = "column_materializer::keypress_count"
+ }
+ column "timestamps_summary" {
+ type = "Array(DateTime64(6, 'UTC'))"
+ comment = "column_materializer::timestamps_summary"
+ }
+ column "first_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::first_event_timestamp"
+ }
+ column "last_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ comment = "column_materializer::last_event_timestamp"
+ }
+ column "urls" {
+ type = "Array(String)"
+ comment = "column_materializer::urls"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_recording_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "sharded_precalculated_person_properties" {
+ override = true
+ order_by = ["team_id", "condition", "distinct_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "condition" {
+ type = "String"
+ }
+ column "matches" {
+ type = "Bool"
+ }
+ column "source" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_precalculated_person_properties"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_raw_sessions_v3" {
+ override = true
+ order_by = ["team_id", "session_timestamp", "session_id_v7"]
+ partition_by = "toYYYYMM(session_timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ index "event_names_bloom_filter" {
+ expr = "event_names"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ index "flag_keys_bloom_filter" {
+ expr = "flag_keys"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.raw_sessions_v3"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_session_recording_events" {
+ override = true
+ order_by = ["team_id", "toHour(timestamp)", "session_id", "timestamp", "uuid"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(created_at) + toIntervalWeek(3)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "session_id" {
+ type = "String"
+ }
+ column "window_id" {
+ type = "String"
+ }
+ column "snapshot_data" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "has_full_snapshot" {
+ type = "Int8"
+ materialized = "JSONExtractBool(snapshot_data, 'has_full_snapshot')"
+ comment = "column_materializer::has_full_snapshot"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "events_summary" {
+ type = "Array(String)"
+ materialized = "JSONExtract(JSON_QUERY(snapshot_data, '$.events_summary[*]'), 'Array(String)')"
+ }
+ column "click_count" {
+ type = "Int8"
+ materialized = "length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 2) AND (JSONExtractInt(x, 'data', 'source') = 2)), events_summary))"
+ }
+ column "keypress_count" {
+ type = "Int8"
+ materialized = "length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 5)), events_summary))"
+ }
+ column "timestamps_summary" {
+ type = "Array(DateTime64(6, 'UTC'))"
+ materialized = "arraySort(arrayMap(x -> toDateTime(JSONExtractInt(x, 'timestamp') / 1000), events_summary))"
+ }
+ column "first_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ materialized = "arrayReduce('min', timestamps_summary)"
+ }
+ column "last_event_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ materialized = "arrayReduce('max', timestamps_summary)"
+ }
+ column "urls" {
+ type = "Array(String)"
+ materialized = "arrayFilter(x -> (x != ''), arrayMap(x -> JSONExtractString(x, 'data', 'href'), events_summary))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_recording_events"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "swap_person_distinct_id" {
+ override = true
+ order_by = ["team_id", "distinct_id", "person_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_sign" {
+ type = "Int8"
+ default = "1"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ alias = "if(_sign = -1, 1, 0)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/noshard/posthog.swap_person_distinct_id"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "web_bounces_daily_distributed" {
+ override = true
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "updated_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_bounces_daily"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_bounces_hourly_distributed" {
+ override = true
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "updated_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_bounces_hourly"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_stats_daily_distributed" {
+ override = true
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "updated_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_stats_daily"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_stats_hourly_distributed" {
+ override = true
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "updated_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now()"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_stats_hourly"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "writable_events" {
+ override = true
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ column "consumer_breadcrumbs" {
+ type = "Array(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)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "writable_events_dead_letter_queue" {
+ override = true
+ column "id" {
+ type = "UUID"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "ip" {
+ type = "String"
+ }
+ column "site_url" {
+ type = "String"
+ }
+ column "now" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "raw_payload" {
+ type = "String"
+ }
+ column "error_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "error_location" {
+ type = "String"
+ }
+ column "error" {
+ type = "String"
+ }
+ column "tags" {
+ type = "Array(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog_single_shard"
+ remote_database = "posthog"
+ remote_table = "events_dead_letter_queue"
+ }
+ }
+
+ materialized_view "session_replay_features_mv" {
+ # The ingestion nodes declare this name too, for the table they write through.
+ # A data node holds a different object under it, so this restates rather than
+ # redeclares.
+ override = true
+ to_table = "posthog.writable_session_replay_features"
+ query = <<SQL
+SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(first_timestamp) AS min_first_timestamp,
+ max(last_timestamp) AS max_last_timestamp,
+ sum(event_count) AS event_count,
+ sum(mouse_position_count) AS mouse_position_count,
+ sum(mouse_sum_x) AS mouse_sum_x,
+ sum(mouse_sum_x_squared) AS mouse_sum_x_squared,
+ sum(mouse_sum_y) AS mouse_sum_y,
+ sum(mouse_sum_y_squared) AS mouse_sum_y_squared,
+ sum(mouse_distance_traveled) AS mouse_distance_traveled,
+ sum(mouse_direction_change_count) AS mouse_direction_change_count,
+ sum(mouse_velocity_sum) AS mouse_velocity_sum,
+ sum(mouse_velocity_sum_of_squares) AS mouse_velocity_sum_of_squares,
+ sum(mouse_velocity_count) AS mouse_velocity_count,
+ sum(scroll_event_count) AS scroll_event_count,
+ sum(total_scroll_magnitude) AS total_scroll_magnitude,
+ sum(scroll_direction_reversal_count) AS scroll_direction_reversal_count,
+ sum(rapid_scroll_reversal_count) AS rapid_scroll_reversal_count,
+ sum(click_count) AS click_count,
+ sum(keypress_count) AS keypress_count,
+ sum(mouse_activity_count) AS mouse_activity_count,
+ sum(rage_click_count) AS rage_click_count,
+ sum(dead_click_count) AS dead_click_count,
+ sum(inter_action_gap_count) AS inter_action_gap_count,
+ sum(inter_action_gap_sum_ms) AS inter_action_gap_sum_ms,
+ sum(inter_action_gap_sum_of_squares_ms) AS inter_action_gap_sum_of_squares_ms,
+ max(max_idle_gap_ms) AS max_idle_gap_ms,
+ sum(quick_back_count) AS quick_back_count,
+ sum(page_visit_count) AS page_visit_count,
+ uniqExactArrayState(visited_urls) AS unique_url_count,
+ sum(console_error_count) AS console_error_count,
+ sum(console_error_after_click_count) AS console_error_after_click_count,
+ sum(network_request_count) AS network_request_count,
+ sum(network_failed_request_count) AS network_failed_request_count,
+ sum(network_request_duration_sum) AS network_request_duration_sum,
+ sum(network_request_duration_sum_of_squares) AS network_request_duration_sum_of_squares,
+ sum(network_request_duration_count) AS network_request_duration_count,
+ max(max_scroll_y) AS max_scroll_y,
+ uniqExactArrayState(click_target_ids) AS unique_click_target_count,
+ sum(text_selection_count) AS text_selection_count,
+ max(is_deleted) AS is_deleted
+FROM posthog.kafka_session_replay_features
+GROUP BY
+ session_id, team_id
+SQL
+
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "max_last_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "event_count" {
+ type = "Int64"
+ }
+ column "mouse_position_count" {
+ type = "Int64"
+ }
+ column "mouse_sum_x" {
+ type = "Float64"
+ }
+ column "mouse_sum_x_squared" {
+ type = "Float64"
+ }
+ column "mouse_sum_y" {
+ type = "Float64"
+ }
+ column "mouse_sum_y_squared" {
+ type = "Float64"
+ }
+ column "mouse_distance_traveled" {
+ type = "Float64"
+ }
+ column "mouse_direction_change_count" {
+ type = "Int64"
+ }
+ column "mouse_velocity_sum" {
+ type = "Float64"
+ }
+ column "mouse_velocity_sum_of_squares" {
+ type = "Float64"
+ }
+ column "mouse_velocity_count" {
+ type = "Int64"
+ }
+ column "scroll_event_count" {
+ type = "Int64"
+ }
+ column "total_scroll_magnitude" {
+ type = "Float64"
+ }
+ column "scroll_direction_reversal_count" {
+ type = "Int64"
+ }
+ column "rapid_scroll_reversal_count" {
+ type = "Int64"
+ }
+ column "click_count" {
+ type = "Int64"
+ }
+ column "keypress_count" {
+ type = "Int64"
+ }
+ column "mouse_activity_count" {
+ type = "Int64"
+ }
+ column "rage_click_count" {
+ type = "Int64"
+ }
+ column "dead_click_count" {
+ type = "Int64"
+ }
+ column "inter_action_gap_count" {
+ type = "Int64"
+ }
+ column "inter_action_gap_sum_ms" {
+ type = "Float64"
+ }
+ column "inter_action_gap_sum_of_squares_ms" {
+ type = "Float64"
+ }
+ column "max_idle_gap_ms" {
+ type = "Float64"
+ }
+ column "quick_back_count" {
+ type = "Int64"
+ }
+ column "page_visit_count" {
+ type = "Int64"
+ }
+ column "unique_url_count" {
+ type = "AggregateFunction(uniqExactArray, Array(String))"
+ }
+ column "console_error_count" {
+ type = "Int64"
+ }
+ column "console_error_after_click_count" {
+ type = "Int64"
+ }
+ column "network_request_count" {
+ type = "Int64"
+ }
+ column "network_failed_request_count" {
+ type = "Int64"
+ }
+ column "network_request_duration_sum" {
+ type = "Float64"
+ }
+ column "network_request_duration_sum_of_squares" {
+ type = "Float64"
+ }
+ column "network_request_duration_count" {
+ type = "Int64"
+ }
+ column "max_scroll_y" {
+ type = "Float64"
+ }
+ column "unique_click_target_count" {
+ type = "AggregateFunction(uniqExactArray, Array(Int64))"
+ }
+ column "text_selection_count" {
+ type = "Int64"
+ }
+ column "is_deleted" {
+ type = "UInt8"
+ }
+ }
+
+ patch_table "events" {
+ modify_column "properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "elements_chain" {
+ type = "String"
+ after = "distinct_id"
+ }
+ column "person_id" {
+ type = "UUID"
+ after = "created_at"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ after = "person_id"
+ }
+ column "person_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "person_created_at"
+ }
+ column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "person_properties"
+ }
+ column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group0_properties"
+ }
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group1_properties"
+ }
+ column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group2_properties"
+ }
+ column "group4_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group3_properties"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ after = "group4_properties"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ after = "group0_created_at"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ after = "group1_created_at"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ after = "group2_created_at"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ after = "group3_created_at"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ after = "$session_id"
+ }
+ column "_offset" {
+ type = "UInt64"
+ after = "_timestamp"
+ }
+ column "mat_metadata_backend" {
+ type = "String"
+ comment = "column_materializer::properties::metadata.backend"
+ after = "person_mode"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "String"
+ comment = "column_materializer::properties::metadata.loggedIn"
+ after = "mat_metadata_backend"
+ }
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_trace_id"
+ after = "person_properties_map_custom"
+ }
+ column "mat_$ai_experiment_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_experiment_id"
+ after = "mat_$ai_prompt_name"
+ }
+ }
+
+ patch_table "sharded_events" {
+ column "elements_chain" {
+ type = "String"
+ after = "distinct_id"
+ }
+ column "person_id" {
+ type = "UUID"
+ after = "created_at"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ after = "person_id"
+ }
+ column "person_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "person_created_at"
+ }
+ column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "person_properties"
+ }
+ column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group0_properties"
+ }
+ column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group1_properties"
+ }
+ column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group2_properties"
+ }
+ column "group4_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ after = "group3_properties"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ after = "group4_properties"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ after = "group0_created_at"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ after = "group1_created_at"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ after = "group2_created_at"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ after = "group3_created_at"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ after = "$session_id"
+ }
+ column "_offset" {
+ type = "UInt64"
+ after = "_timestamp"
+ }
+ column "mat_metadata_backend" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, 'metadata.backend'), '^\"|\"$', '')"
+ after = "person_mode"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, 'metadata.loggedIn'), '^\"|\"$', '')"
+ after = "mat_metadata_backend"
+ }
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
+ after = "person_properties_map_custom"
+ }
+ index "minmax_mat_metadata_backend" {
+ expr = "mat_metadata_backend"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_mat_metadata_loggedIn" {
+ expr = "mat_metadata_loggedIn"
+ type = "minmax"
+ granularity = 1
+ }
+ index "minmax_mat_$ai_trace_id" {
+ expr = "`mat_$ai_trace_id`"
+ type = "minmax"
+ granularity = 1
+ }
+ settings = {
+ max_avg_part_size_for_too_many_parts = "0"
+ }
+ }
+
+ patch_table "ai_events" {
+ engine "distributed" {
+ cluster_name = "ai_events"
+ remote_database = "posthog"
+ remote_table = "ai_events"
+ sharding_key = "rand()"
+ }
+ }
+
+ patch_table "billing_usage_records" {
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_billing_usage_records"
+ sharding_key = "cityHash64(team_id)"
+ }
+ }
+
+ patch_table "cohortpeople" {
+ order_by = ["team_id", "cohort_id", "person_id"]
+ partition_by = "team_id % 16"
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.cohortpeople_new_partitioned"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ patch_table "ingestion_warnings" {
+ modify_column "details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ }
+
+ patch_table "plugin_log_entries" {
+ order_by = ["team_id", "plugin_id", "plugin_config_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.plugin_log_entries.fixed"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ patch_table "raw_sessions" {
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ patch_table "raw_sessions_v3" {
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ patch_table "sessions" {
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ patch_table "sharded_session_replay_events" {
+ settings = {
+ ttl_only_drop_parts = "1"
+ }
+ modify_column "snapshot_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ }
+
+ patch_table "writable_events_recent" {
+ modify_column "group0_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ modify_column "group1_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ modify_column "group2_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ modify_column "group3_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ modify_column "group4_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ modify_column "person_properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ modify_column "properties" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "historical_migration" {
+ type = "Bool"
+ after = "person_mode"
+ }
+ }
+
+ patch_table "writable_raw_sessions" {
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ 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"
+ remote_table = "raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ patch_table "writable_session_replay_events" {
+ drop_columns = ["is_deleted"]
+ }
+
+ patch_table "writable_sessions" {
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ patch_view "events_batch_export" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ (events.timestamp >= ({interval_start: DateTime64} - toIntervalDay({lookback_days: Int32})))
+AND
+ (events.timestamp < ({interval_end: DateTime64} + toIntervalDay(1)))
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ patch_view "events_batch_export_unbounded" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ table "clickhouse_cleanup_deleted_persons" {
+ override = true
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "max_version" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_orphaned_distinct_ids" {
+ override = true
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "own_tombstone" {
+ type = "UInt8"
+ }
+ column "max_version" {
+ type = "Int64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_distinct_ids" {
+ override = true
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_persons" {
+ override = true
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "distributed_events_recent" {
+ override = true
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ column "_timestamp_ms" {
+ type = "DateTime64(3)"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_system_processes" {
+ override = true
+ settings = {
+ skip_unavailable_shards = "1"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "user" {
+ type = "String"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "address" {
+ type = "IPv6"
+ }
+ column "port" {
+ type = "UInt16"
+ }
+ column "initial_user" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "initial_address" {
+ type = "IPv6"
+ }
+ column "initial_port" {
+ type = "UInt16"
+ }
+ column "interface" {
+ type = "UInt8"
+ }
+ column "os_user" {
+ type = "String"
+ }
+ column "client_hostname" {
+ type = "String"
+ }
+ column "client_name" {
+ type = "String"
+ }
+ column "client_revision" {
+ type = "UInt64"
+ }
+ column "client_version_major" {
+ type = "UInt64"
+ }
+ column "client_version_minor" {
+ type = "UInt64"
+ }
+ column "client_version_patch" {
+ type = "UInt64"
+ }
+ column "http_method" {
+ type = "UInt8"
+ }
+ column "http_user_agent" {
+ type = "String"
+ }
+ column "http_referer" {
+ type = "String"
+ }
+ column "forwarded_for" {
+ type = "String"
+ }
+ column "quota_key" {
+ type = "String"
+ }
+ column "distributed_depth" {
+ type = "UInt64"
+ }
+ column "elapsed" {
+ type = "Float64"
+ }
+ column "is_cancelled" {
+ type = "UInt8"
+ }
+ column "is_all_data_sent" {
+ type = "UInt8"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "total_rows_approx" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "Int64"
+ }
+ column "peak_memory_usage" {
+ type = "Int64"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "query_kind" {
+ type = "String"
+ }
+ column "thread_ids" {
+ type = "Array(UInt64)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "Settings" {
+ type = "Map(String, String)"
+ }
+ column "current_database" {
+ type = "String"
+ }
+ column "ProfileEvents.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(ProfileEvents)"
+ }
+ column "ProfileEvents.Values" {
+ type = "Array(UInt64)"
+ alias = "mapValues(ProfileEvents)"
+ }
+ column "Settings.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(Settings)"
+ }
+ column "Settings.Values" {
+ type = "Array(String)"
+ alias = "mapValues(Settings)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "system"
+ remote_table = "processes"
+ }
+ }
+
+ table "events_dead_letter_queue" {
+ override = true
+ order_by = ["id", "event_uuid", "distinct_id", "team_id"]
+ ttl = "toDate(_timestamp) + toIntervalWeek(4)"
+ settings = {
+ index_granularity = "512"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "event_uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "ip" {
+ type = "String"
+ }
+ column "site_url" {
+ type = "String"
+ }
+ column "now" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "raw_payload" {
+ type = "String"
+ }
+ column "error_timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "error_location" {
+ type = "String"
+ }
+ column "error" {
+ type = "String"
+ }
+ column "tags" {
+ type = "Array(String)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.events_dead_letter_queue"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "groups" {
+ override = true
+ order_by = ["team_id", "group_type_index", "group_key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "group_type_index" {
+ type = "UInt8"
+ }
+ column "group_key" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "group_properties" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "Bool"
+ }
+ index "is_deleted_idx" {
+ expr = "is_deleted"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.groups"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ view "persons_batch_export" {
+ override = true
+ query = <<SQL
+WITH
+ new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
+ new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
+ all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
+SELECT
+ p.team_id AS team_id,
+ pd.distinct_id AS distinct_id,
+ toString(p.id) AS person_id,
+ p.properties AS properties,
+ pd.version AS person_distinct_id_version,
+ p.version AS person_version,
+ p.created_at AS created_at,
+ multiIf(
+ ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
+ pd._timestamp,
+ ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
+ p._timestamp,
+ least(p._timestamp, pd._timestamp)
+ ) AS _inserted_at
+FROM
+ posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((id, version) IN (all_new_persons))
+ORDER BY _inserted_at ASC
+SQL
+
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
+ override = true
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-large-3072'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
+ override = true
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-small-1536'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ table "property_definitions" {
+ override = true
+ order_by = ["team_id", "type", "coalesce(event, '')", "name", "coalesce(group_type_index, 255)"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "UInt32"
+ }
+ column "project_id" {
+ type = "Nullable(UInt32)"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "property_type" {
+ type = "Nullable(String)"
+ }
+ column "event" {
+ type = "Nullable(String)"
+ }
+ column "group_type_index" {
+ type = "Nullable(UInt8)"
+ }
+ column "type" {
+ type = "UInt8"
+ default = "1"
+ }
+ column "last_seen_at" {
+ type = "DateTime"
+ }
+ column "version" {
+ type = "UInt64"
+ materialized = "bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.property_definitions"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ 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
+
+ }
+
+ table "session_replay_events" {
+ override = true
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ view "sessions_v" {
+ override = true
+ query = <<SQL
+SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(exit_url) AS exit_url,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ sumMap(event_count_map) AS event_count_map,
+ sum(pageview_count) AS pageview_count,
+ sum(autocapture_count) AS autocapture_count
+FROM posthog.sessions
+GROUP BY
+ session_id, team_id
+SQL
+
+ }
+
+ table "tophog" {
+ override = true
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "metric" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ default = "'sum'"
+ }
+ column "key" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "0"
+ }
+ column "pipeline" {
+ type = "LowCardinality(String)"
+ }
+ column "lane" {
+ type = "LowCardinality(String)"
+ }
+ column "labels" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_tophog"
+ sharding_key = "cityHash64(toString(key))"
+ }
+ }
+
+ table "web_pre_aggregated_bounces" {
+ override = true
+ order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "web_pre_aggregated_stats" {
+ override = true
+ order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
+ partition_by = "toYYYYMMDD(period_bucket)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "has_gclid" {
+ type = "Bool"
+ }
+ column "has_gad_source_paid_search" {
+ type = "Bool"
+ }
+ column "has_fbclid" {
+ type = "Bool"
+ }
+ column "mat_metadata_backend" {
+ type = "Nullable(String)"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "mat_metadata_loggedIn" {
+ type = "Nullable(Bool)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/data/prod-us/tables.hcl b/posthog/clickhouse/hcl/roles/data/prod-us/tables.hcl
new file mode 100644
index 000000000000..ba18e29d3445
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/data/prod-us/tables.hcl
@@ -0,0 +1,2820 @@
+# prod-us data cluster: objects only prod-us runs, and the deltas it applies to the cloud shape.
+database "posthog" {
+
+ table "asyncdeletion_join" {
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "delete_verified_at" {
+ type = "DateTime"
+ }
+ column "created_by_id" {
+ type = "UInt64"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "key"]
+ }
+ }
+
+ table "distributed_person" {
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_person"
+ sharding_key = "sipHash64(id)"
+ }
+ }
+
+ table "distributed_person_distinct_id" {
+ column "id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_person_distinct_id"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "person" {
+ override = true
+ order_by = ["team_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ default = "0"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt32"
+ }
+ column "last_seen_at" {
+ type = "Nullable(DateTime64(3))"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/am0005_20220623103132_noshard/posthog.person"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_distinct_id_overrides_join_table" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "distinct_id"]
+ }
+ }
+
+ table "person_distinct_id_overrides_to_delete" {
+ order_by = ["team_id", "distinct_id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "512"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id_overrides_to_delete"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "person_distinct_id_overrides_to_delete_join" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "distinct_id"]
+ }
+ }
+
+ table "person_overrides_join_table" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "distinct_id"]
+ }
+ }
+
+ table "sharded_events" {
+ override = true
+ 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"
+ max_avg_part_size_for_too_many_parts = "0"
+ }
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "elements_hash" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "$group_0" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$group_1" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$group_2" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$group_3" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$group_4" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$window_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "$session_id" {
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), concat('^[', regexpQuoteMeta('\"'), ']*|[', regexpQuoteMeta('\"'), ']*$'), '')"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "group0_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "group1_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "group2_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "group3_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "group4_properties" {
+ type = "String"
+ codec = "Default"
+ }
+ column "person_created_at" {
+ type = "DateTime64(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 "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"
+ 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 "elements_chain_ids" {
+ type = "Array(String)"
+ materialized = "arrayDistinct(extractAll(elements_chain, '(?::|\")attr_id=\"(.*?)\"'))"
+ }
+ 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'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
+ codec = "Default"
+ }
+ column "properties_group_feature_flags" {
+ type = "Map(String, String)"
+ materialized = "mapSort(mapFilter((key, _) -> (key LIKE '$feature/%'), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)')))"
+ codec = "Default"
+ }
+ 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 = "Default"
+ }
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, '$ai_trace_id', 'Nullable(String)')"
+ }
+ column "$session_id_uuid" {
+ type = "Nullable(UInt128)"
+ materialized = "toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)'))"
+ }
+ column "consumer_breadcrumbs" {
+ type = "Array(String)"
+ }
+ column "properties_map_ephemeral" {
+ type = "Map(String, String)"
+ }
+ column "person_properties_map_ephemeral" {
+ type = "Map(String, 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 = "Default"
+ }
+ column "mat_historical_migration" {
+ type = "Nullable(String)"
+ default = "JSONExtract(properties, 'historical_migration', '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 "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)"
+ materialized = "JSONExtract(properties, '$ai_prompt_name', 'Nullable(String)')"
+ }
+ column "mat_$ai_experiment_id" {
+ type = "Nullable(String)"
+ materialized = "JSONExtract(properties, '$ai_experiment_id', 'Nullable(String)')"
+ }
+ index "kafka_timestamp_minmax_sharded_events" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ 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_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 "minmax_mat_$ai_trace_id" {
+ expr = "`mat_$ai_trace_id`"
+ type = "minmax"
+ 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
+ }
+ index "bloom_filter_$session_id" {
+ expr = "nullIf(nullIf(`$session_id`, ''), 'null')"
+ type = "bloom_filter"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard3/{shard}/posthog.sharded_events"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_person" {
+ order_by = ["team_id", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_person"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_person_distinct_id" {
+ order_by = ["team_id", "distinct_id", "person_id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_person_distinct_id"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "sharded_raw_sessions_v3" {
+ override = true
+ order_by = ["team_id", "session_timestamp", "session_id_v7"]
+ partition_by = "toYYYYMM(session_timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ default = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ index "event_names_bloom_filter" {
+ expr = "event_names"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ index "flag_keys_bloom_filter" {
+ expr = "flag_keys"
+ type = "bloom_filter()"
+ granularity = 1
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.raw_sessions_v3"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "writable_ingestion_warnings" {
+ # The ingestion nodes declare this name too, for the table they write through.
+ # A data node holds a different object under it, so this restates rather than
+ # redeclares.
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_ingestion_warnings"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "writable_posthog_document_embeddings" {
+ # The ingestion nodes declare this name too, for the table they write through.
+ # A data node holds a different object under it, so this restates rather than
+ # redeclares.
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "writable_raw_sessions_primary" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "writable_sessions_background" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ view "events_with_array_props_view" {
+ query = <<SQL
+SELECT
+ uuid,
+ event,
+ properties,
+ timestamp,
+ team_id,
+ distinct_id,
+ elements_chain,
+ created_at,
+ arrayMap(k -> toString(k.1), JSONExtractKeysAndValuesRaw(properties)) AS array_property_keys,
+ arrayMap(k -> toString(k.2), JSONExtractKeysAndValuesRaw(properties)) AS array_property_values,
+ _timestamp,
+ _offset
+FROM posthog.events
+SQL
+
+ }
+
+ view "persons_properties_up_to_date_view" {
+ query = <<SQL
+SELECT *
+FROM posthog.persons_properties_view
+WHERE
+ (id, created_at)
+ IN (SELECT id, maxMerge(updated_at) AS latest FROM posthog.persons_up_to_date GROUP BY id)
+SQL
+
+ }
+
+ view "persons_up_to_date_view" {
+ query = <<SQL
+SELECT
+ id,
+ minMerge(created_at_) AS created_at,
+ argMaxMerge(team_id) AS team_id,
+ argMaxMerge(properties) AS properties,
+ argMaxMerge(is_identified) AS is_identified,
+ maxMerge(updated_at) AS updated_at
+FROM posthog.persons_up_to_date
+GROUP BY
+ id
+SQL
+
+ }
+
+ view "team_events_last_month_view" {
+ query = <<SQL
+SELECT team_id, count() AS event_count
+FROM posthog.events
+WHERE
+ (timestamp > (now() - toIntervalMonth(1)))
+AND
+ (timestamp < now())
+GROUP BY
+ team_id
+ORDER BY event_count DESC
+SQL
+
+ }
+
+ patch_table "events" {
+ column "elements_hash" {
+ type = "String"
+ after = "distinct_id"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ after = "created_at"
+ }
+ column "_offset" {
+ type = "UInt64"
+ after = "_timestamp"
+ }
+ column "elements_chain" {
+ type = "String"
+ after = "_offset"
+ }
+ column "group_0" {
+ type = "String"
+ alias = "`$group_0`"
+ after = "$session_id"
+ }
+ column "group_1" {
+ type = "String"
+ alias = "`$group_1`"
+ after = "group_0"
+ }
+ column "group_2" {
+ type = "String"
+ alias = "`$group_2`"
+ after = "group_1"
+ }
+ column "group_3" {
+ type = "String"
+ alias = "`$group_3`"
+ after = "group_2"
+ }
+ column "group_4" {
+ type = "String"
+ alias = "`$group_4`"
+ after = "group_3"
+ }
+ column "person_id" {
+ type = "UUID"
+ after = "group_4"
+ }
+ column "person_properties" {
+ type = "String"
+ after = "person_id"
+ }
+ column "group0_properties" {
+ type = "String"
+ after = "person_properties"
+ }
+ column "group1_properties" {
+ type = "String"
+ after = "group0_properties"
+ }
+ column "group2_properties" {
+ type = "String"
+ after = "group1_properties"
+ }
+ column "group3_properties" {
+ type = "String"
+ after = "group2_properties"
+ }
+ column "group4_properties" {
+ type = "String"
+ after = "group3_properties"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ after = "group4_properties"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ after = "person_created_at"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ after = "group0_created_at"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ after = "group1_created_at"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ after = "group2_created_at"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ after = "group3_created_at"
+ }
+ column "mat_$ai_trace_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_trace_id"
+ after = "person_properties_map_custom"
+ }
+ column "mat_$ai_experiment_id" {
+ type = "Nullable(String)"
+ comment = "column_materializer::properties::$ai_experiment_id"
+ after = "mat_$ai_prompt_name"
+ }
+ }
+
+ patch_table "adhoc_events_deletion" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "ai_events" {
+ engine "distributed" {
+ cluster_name = "ai_events"
+ remote_database = "posthog"
+ remote_table = "ai_events"
+ sharding_key = "rand()"
+ }
+ }
+
+ patch_table "billing_usage_records" {
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "sharded_billing_usage_records"
+ sharding_key = "cityHash64(team_id)"
+ }
+ }
+
+ patch_table "channel_definition" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "cohort_membership" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/posthog.cohort_membership"
+ replica_name = "{replica}-{shard}"
+ version_column = "last_updated"
+ }
+ }
+
+ patch_table "cohortpeople" {
+ order_by = ["team_id", "cohort_id", "person_id"]
+ partition_by = "team_id % 16"
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.cohortpeople_new_partitioned"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ patch_table "duplicate_events" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "error_tracking_issue_fingerprint_overrides" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "events_dead_letter_queue" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ index "kafka_timestamp_minmax" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ first = true
+ }
+ index "kafka_timestamp_minmax_events_dead_letter_queue" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.new_events_dead_letter_queue_2"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ patch_table "exchange_rate" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "ingestion_warnings" {
+ modify_column "details" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ }
+
+ patch_table "llma_metrics_daily" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "person_distinct_id" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id-swap2-2021-08-18"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ patch_table "person_distinct_id_overrides" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "person_overrides" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "person_static_cohort" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/noshard/person_static_cohort"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ patch_table "pg_embeddings" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "plugin_log_entries" {
+ order_by = ["team_id", "plugin_id", "plugin_config_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "property_definitions" {
+ settings = {
+ always_fetch_merged_part = "0"
+ default_compression_codec = "lz4"
+ replicated_can_become_leader = "1"
+ }
+ }
+
+ patch_table "raw_sessions" {
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ patch_table "sessions" {
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ patch_table "sharded_app_metrics2" {
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_app_metrics2"
+ replica_name = "{replica}"
+ }
+ }
+
+ patch_table "sharded_heatmaps" {
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.heatmaps"
+ replica_name = "{replica}"
+ }
+ }
+
+ patch_table "sharded_log_entries" {
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_log_entries"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ patch_table "sharded_performance_events" {
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.performance_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ patch_table "sharded_posthog_document_embeddings_buffer" {
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_posthog_document_embeddings_buffer"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ patch_table "sharded_posthog_document_embeddings_text_embedding_3_large_3072" {
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ patch_table "sharded_posthog_document_embeddings_text_embedding_3_small_1536" {
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536"
+ replica_name = "{replica}"
+ version_column = "inserted_at"
+ }
+ }
+
+ patch_table "sharded_preaggregation_results" {
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.preaggregation_results"
+ replica_name = "{replica}"
+ }
+ }
+
+ patch_table "sharded_session_replay_embeddings" {
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.session_replay_embeddings"
+ replica_name = "{replica}"
+ }
+ }
+
+ patch_table "sharded_session_replay_events" {
+ modify_column "snapshot_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.session_replay_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ patch_table "web_pre_aggregated_bounces" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "web_pre_aggregated_stats" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "web_pre_aggregated_teams" {
+ settings = {
+ default_compression_codec = "lz4"
+ }
+ }
+
+ patch_table "writable_raw_sessions" {
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ 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"
+ remote_table = "raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ patch_table "writable_session_replay_events" {
+ drop_columns = ["is_deleted"]
+ engine "distributed" {
+ cluster_name = "posthog_writable"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ patch_table "writable_sessions" {
+ engine "distributed" {
+ cluster_name = "posthog_writable"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ patch_view "events_batch_export" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ (events.timestamp >= ({interval_start: DateTime64} - toIntervalDay({lookback_days: Int32})))
+AND
+ (events.timestamp < ({interval_end: DateTime64} + toIntervalDay(1)))
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ patch_view "events_batch_export_unbounded" {
+ query = <<SQL
+SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1
+SQL
+
+ }
+
+ table "clickhouse_cleanup_deleted_persons" {
+ override = true
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "max_version" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_orphaned_distinct_ids" {
+ override = true
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "own_tombstone" {
+ type = "UInt8"
+ }
+ column "max_version" {
+ type = "Int64"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_distinct_ids" {
+ override = true
+ order_by = ["run_id", "team_id", "distinct_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "clickhouse_cleanup_revived_persons" {
+ override = true
+ order_by = ["run_id", "team_id", "person_id"]
+ partition_by = "run_id"
+ ttl = "created_at + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "run_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
+ replica_name = "{replica}-{shard}"
+ version_column = "created_at"
+ }
+ }
+
+ table "distributed_events_recent" {
+ override = true
+ 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 "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ default = "now64()"
+ }
+ column "_timestamp_ms" {
+ type = "DateTime64(3)"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "distributed_posthog_document_embeddings" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+
+ table "distributed_system_processes" {
+ override = true
+ settings = {
+ skip_unavailable_shards = "1"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "user" {
+ type = "String"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "address" {
+ type = "IPv6"
+ }
+ column "port" {
+ type = "UInt16"
+ }
+ column "initial_user" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "initial_address" {
+ type = "IPv6"
+ }
+ column "initial_port" {
+ type = "UInt16"
+ }
+ column "interface" {
+ type = "UInt8"
+ }
+ column "os_user" {
+ type = "String"
+ }
+ column "client_hostname" {
+ type = "String"
+ }
+ column "client_name" {
+ type = "String"
+ }
+ column "client_revision" {
+ type = "UInt64"
+ }
+ column "client_version_major" {
+ type = "UInt64"
+ }
+ column "client_version_minor" {
+ type = "UInt64"
+ }
+ column "client_version_patch" {
+ type = "UInt64"
+ }
+ column "http_method" {
+ type = "UInt8"
+ }
+ column "http_user_agent" {
+ type = "String"
+ }
+ column "http_referer" {
+ type = "String"
+ }
+ column "forwarded_for" {
+ type = "String"
+ }
+ column "quota_key" {
+ type = "String"
+ }
+ column "distributed_depth" {
+ type = "UInt64"
+ }
+ column "elapsed" {
+ type = "Float64"
+ }
+ column "is_cancelled" {
+ type = "UInt8"
+ }
+ column "is_all_data_sent" {
+ type = "UInt8"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "total_rows_approx" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "Int64"
+ }
+ column "peak_memory_usage" {
+ type = "Int64"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "query_kind" {
+ type = "String"
+ }
+ column "thread_ids" {
+ type = "Array(UInt64)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "Settings" {
+ type = "Map(String, String)"
+ }
+ column "current_database" {
+ type = "String"
+ }
+ column "ProfileEvents.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(ProfileEvents)"
+ }
+ column "ProfileEvents.Values" {
+ type = "Array(UInt64)"
+ alias = "mapValues(ProfileEvents)"
+ }
+ column "Settings.Names" {
+ type = "Array(String)"
+ alias = "mapKeys(Settings)"
+ }
+ column "Settings.Values" {
+ type = "Array(String)"
+ alias = "mapValues(Settings)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "system"
+ remote_table = "processes"
+ }
+ }
+
+ table "groups" {
+ override = true
+ order_by = ["team_id", "group_type_index", "group_key"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "group_type_index" {
+ type = "UInt8"
+ }
+ column "group_key" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "group_properties" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "is_deleted" {
+ type = "Bool"
+ }
+ index "is_deleted_idx" {
+ expr = "is_deleted"
+ type = "minmax"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.groups"
+ replica_name = "{replica}-{shard}"
+ version_column = "_timestamp"
+ }
+ }
+
+ view "persons_batch_export" {
+ override = true
+ query = <<SQL
+WITH
+ new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
+ new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
+ all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
+SELECT
+ p.team_id AS team_id,
+ pd.distinct_id AS distinct_id,
+ toString(p.id) AS person_id,
+ p.properties AS properties,
+ pd.version AS person_distinct_id_version,
+ p.version AS person_version,
+ p.created_at AS created_at,
+ multiIf(
+ ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
+ pd._timestamp,
+ ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
+ p._timestamp,
+ least(p._timestamp, pd._timestamp)
+ ) AS _inserted_at
+FROM
+ posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((id, version) IN (all_new_persons))
+ORDER BY _inserted_at ASC
+SQL
+
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
+ override = true
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-large-3072'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
+ override = true
+ to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
+ query = <<SQL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-small-1536'
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ }
+ column "metadata" {
+ type = "String"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ table "raw_sessions_v3" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "session_timestamp" {
+ type = "DateTime64(3)"
+ materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "distinct_ids" {
+ type = "AggregateFunction(groupUniqArray, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "browser_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "os_version" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "device_type" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_width" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "viewport_height" {
+ type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_country_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "geoip_time_zone" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_referring_domain" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_campaign" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_medium" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_term" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_utm_content" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_gad_source" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_fbclid" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_gclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_has_fbclid" {
+ type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_map" {
+ type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_ad_ids_set" {
+ type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
+ }
+ column "entry_channel_type_properties" {
+ type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniqExact, Nullable(UUID))"
+ }
+ column "page_screen_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "has_autocapture" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "flag_values" {
+ type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
+ }
+ column "flag_keys" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "event_names" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "has_replay_events" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions_v3"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ 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
+
+ }
+
+ table "session_replay_events" {
+ override = true
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "min_first_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_last_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "first_url" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "click_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "keypress_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "mouse_activity_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "active_milliseconds" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_log_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_warn_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "console_error_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "size" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "message_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "event_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "snapshot_source" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "snapshot_library" {
+ type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
+ }
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
+ column "is_deleted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "ai_tags_fixed" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_tags_freeform" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "ai_highlighted" {
+ type = "SimpleAggregateFunction(max, UInt8)"
+ default = "0"
+ }
+ column "surfacing_score" {
+ type = "SimpleAggregateFunction(max, Nullable(Float32))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_session_replay_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ view "sessions_v" {
+ override = true
+ query = <<SQL
+SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(exit_url) AS exit_url,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ sumMap(event_count_map) AS event_count_map,
+ sum(pageview_count) AS pageview_count,
+ sum(autocapture_count) AS autocapture_count
+FROM posthog.sessions
+GROUP BY
+ session_id, team_id
+SQL
+
+ }
+
+ table "tophog" {
+ override = true
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "metric" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ default = "'sum'"
+ }
+ column "key" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "0"
+ }
+ column "pipeline" {
+ type = "LowCardinality(String)"
+ }
+ column "lane" {
+ type = "LowCardinality(String)"
+ }
+ column "labels" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_tophog"
+ sharding_key = "cityHash64(toString(key))"
+ }
+ }
+
+ table "writable_posthog_document_embeddings_buffer" {
+ override = true
+ column "team_id" {
+ type = "Int64"
+ }
+ column "product" {
+ type = "LowCardinality(String)"
+ }
+ column "document_type" {
+ type = "LowCardinality(String)"
+ }
+ column "model_name" {
+ type = "LowCardinality(String)"
+ }
+ column "rendering" {
+ type = "LowCardinality(String)"
+ }
+ column "document_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "inserted_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "content" {
+ type = "String"
+ default = "''"
+ }
+ column "metadata" {
+ type = "String"
+ default = "'{}'"
+ }
+ column "embedding" {
+ type = "Array(Float64)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_posthog_document_embeddings_buffer"
+ sharding_key = "cityHash64(document_id)"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/data/prod/shared_declarations.hcl b/posthog/clickhouse/hcl/roles/data/prod/shared_declarations.hcl
new file mode 100644
index 000000000000..8408bd1bf2de
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/data/prod/shared_declarations.hcl
@@ -0,0 +1,585 @@
+# Objects more than one data layer used to declare. The declaration lives here,
+# in a layer every consumer composes; a cluster whose shape genuinely differs
+# restates it with override = true rather than declaring it a second time.
+database "posthog" {
+ table "asyncdeletion" {
+ order_by = ["deletion_type", "delete_verified_at"]
+ partition_by = "toYYYYMM(created_at)"
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "UInt64"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "delete_verified_at" {
+ type = "DateTime"
+ }
+ column "created_by_id" {
+ type = "UInt64"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/asyncdeletion"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "new_writable_sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "sessions"
+ remote_database = "posthog"
+ remote_table = "sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "pending_person_deletes_reporting" {
+ order_by = ["team_id", "deletion_type", "key"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "deletion_type" {
+ type = "UInt8"
+ }
+ column "key" {
+ type = "String"
+ }
+ column "group_type_index" {
+ type = "Nullable(String)"
+ }
+ column "created_at" {
+ type = "DateTime"
+ }
+ column "delete_verified_at" {
+ type = "Nullable(DateTime)"
+ }
+ column "created_by_id" {
+ type = "Nullable(String)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/pending_person_deletes_reporting"
+ replica_name = "{shard}-{replica}"
+ }
+ }
+
+ table "person_collapsing" {
+ order_by = ["team_id", "id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "created_at" {
+ type = "DateTime64(3)"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "is_identified" {
+ type = "Int8"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_sign" {
+ type = "Int8"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/noshard/posthog.person_collapsing"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "swap_person_distinct_id" {
+ order_by = ["team_id", "distinct_id", "person_id"]
+ settings = {
+ default_compression_codec = "lz4"
+ index_granularity = "8192"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "_sign" {
+ type = "Int8"
+ default = "1"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ alias = "if(_sign = -1, 1, 0)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_collapsing_merge_tree" {
+ zoo_path = "/clickhouse/prod/tables/noshard/posthog.person_distinct_id_"
+ replica_name = "{replica}-{shard}"
+ sign_column = "_sign"
+ }
+ }
+
+ table "web_bounces_daily_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_bounces_daily"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_bounces_hourly_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "bounces_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ column "total_session_duration_state" {
+ type = "AggregateFunction(sum, Int64)"
+ }
+ column "total_session_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_bounces_hourly"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_stats_daily_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_stats_daily"
+ sharding_key = "rand()"
+ }
+ }
+
+ table "web_stats_hourly_distributed" {
+ column "period_bucket" {
+ type = "DateTime"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "host" {
+ type = "String"
+ }
+ column "device_type" {
+ type = "String"
+ }
+ column "pathname" {
+ type = "String"
+ }
+ column "entry_pathname" {
+ type = "String"
+ }
+ column "end_pathname" {
+ type = "String"
+ }
+ column "browser" {
+ type = "String"
+ }
+ column "os" {
+ type = "String"
+ }
+ column "viewport_width" {
+ type = "Int64"
+ }
+ column "viewport_height" {
+ type = "Int64"
+ }
+ column "referring_domain" {
+ type = "String"
+ }
+ column "utm_source" {
+ type = "String"
+ }
+ column "utm_medium" {
+ type = "String"
+ }
+ column "utm_campaign" {
+ type = "String"
+ }
+ column "utm_term" {
+ type = "String"
+ }
+ column "utm_content" {
+ type = "String"
+ }
+ column "country_code" {
+ type = "String"
+ }
+ column "city_name" {
+ type = "String"
+ }
+ column "region_code" {
+ type = "String"
+ }
+ column "region_name" {
+ type = "String"
+ }
+ column "persons_uniq_state" {
+ type = "AggregateFunction(uniq, UUID)"
+ }
+ column "sessions_uniq_state" {
+ type = "AggregateFunction(uniq, String)"
+ }
+ column "pageviews_count_state" {
+ type = "AggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "web_stats_hourly"
+ sharding_key = "rand()"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/data/prod/tables.hcl b/posthog/clickhouse/hcl/roles/data/prod/tables.hcl
new file mode 100644
index 000000000000..dc7a42f39105
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/data/prod/tables.hcl
@@ -0,0 +1,328 @@
+# Objects both prod data clusters run and dev does not.
+database "posthog" {
+ table "log_entries_distributed" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
+ table "new_raw_sessions" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "session_id_v7" {
+ type = "UInt128"
+ }
+ column "distinct_id" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "max_inserted_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "end_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "last_external_click_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_browser_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_os_version" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_device_type" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_width" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_viewport_height" {
+ type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_country_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_code" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_1_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_subdivision_city_name" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_geoip_time_zone" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_irclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "pageview_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "screen_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "screen_uniq" {
+ type = "AggregateFunction(uniq, Nullable(UUID))"
+ }
+ column "maybe_has_session_replay" {
+ type = "SimpleAggregateFunction(max, Bool)"
+ }
+ column "page_screen_autocapture_uniq_up_to" {
+ type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
+ }
+ column "vitals_lcp" {
+ type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
+ }
+ column "initial__kx" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_raw_sessions"
+ sharding_key = "cityHash64(session_id_v7)"
+ }
+ }
+
+ table "new_sessions" {
+ column "session_id" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "SimpleAggregateFunction(any, String)"
+ }
+ column "min_timestamp" {
+ type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
+ }
+ column "urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
+ column "entry_url" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "exit_url" {
+ type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_referring_domain" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_campaign" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_medium" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_term" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_utm_content" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gad_source" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gclsrc" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_dclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_gbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_wbraid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_fbclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_msclkid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_twclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_li_fat_id" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_mc_cid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_igshid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "initial_ttclid" {
+ type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
+ }
+ column "event_count_map" {
+ type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
+ }
+ column "pageview_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ column "autocapture_count" {
+ type = "SimpleAggregateFunction(sum, Int64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_sessions"
+ sharding_key = "sipHash64(session_id)"
+ }
+ }
+
+ table "person_overrides_to_delete" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "partitions" {
+ type = "Array(String)"
+ }
+ engine "join" {
+ strictness = "ANY"
+ type = "LEFT"
+ keys = ["team_id", "distinct_id"]
+ }
+ }
+
+ # Both prod clusters dropped the person and group property columns from the flag
+ # evaluation tables. dev and the local node still carry them.
+ patch_table "flag_evaluations" {
+ drop_columns = ["group0_properties", "group1_properties", "group2_properties", "group3_properties", "group4_properties", "person_properties"]
+ }
+
+ patch_table "sharded_flag_evaluations" {
+ drop_columns = ["group0_properties", "group1_properties", "group2_properties", "group3_properties", "group4_properties", "person_properties"]
+ }
+}
diff --git a/posthog/clickhouse/hcl/sql/dev/data.sql b/posthog/clickhouse/hcl/sql/dev/data.sql
new file mode 100644
index 000000000000..767532040c20
--- /dev/null
+++ b/posthog/clickhouse/hcl/sql/dev/data.sql
@@ -0,0 +1,3157 @@
+-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit.
+-- Full CREATE schema for the dev/data node. Apply to a fresh ClickHouse to build it.
+
+CREATE TABLE posthog.adhoc_events_deletion (
+ team_id Int64,
+ uuid UUID,
+ created_at DateTime64(6, 'UTC') DEFAULT now64(),
+ deleted_at DateTime,
+ is_deleted UInt8 DEFAULT 0
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.adhoc_events_deletion', '{replica}-{shard}', deleted_at, is_deleted) ORDER BY (team_id, uuid) TTL deleted_at + toIntervalMonth(3) WHERE is_deleted = 1 SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.ai_events (
+ uuid UUID,
+ event LowCardinality(String),
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ properties String,
+ retention_days Int16 DEFAULT 30,
+ drop_date Date MATERIALIZED toDate(timestamp) + toIntervalDay(retention_days),
+ trace_id String,
+ session_id Nullable(String),
+ parent_id Nullable(String),
+ span_id Nullable(String),
+ span_type LowCardinality(Nullable(String)),
+ generation_id Nullable(String),
+ experiment_id Nullable(String),
+ span_name Nullable(String),
+ trace_name Nullable(String),
+ prompt_name Nullable(String),
+ model LowCardinality(Nullable(String)),
+ provider LowCardinality(Nullable(String)),
+ framework LowCardinality(Nullable(String)),
+ total_tokens Nullable(Int64),
+ input_tokens Nullable(Int64),
+ output_tokens Nullable(Int64),
+ text_input_tokens Nullable(Int64),
+ text_output_tokens Nullable(Int64),
+ image_input_tokens Nullable(Int64),
+ image_output_tokens Nullable(Int64),
+ audio_input_tokens Nullable(Int64),
+ audio_output_tokens Nullable(Int64),
+ video_input_tokens Nullable(Int64),
+ video_output_tokens Nullable(Int64),
+ reasoning_tokens Nullable(Int64),
+ cache_read_input_tokens Nullable(Int64),
+ cache_creation_input_tokens Nullable(Int64),
+ web_search_count Nullable(Int64),
+ input_cost_usd Nullable(Float64),
+ output_cost_usd Nullable(Float64),
+ total_cost_usd Nullable(Float64),
+ request_cost_usd Nullable(Float64),
+ web_search_cost_usd Nullable(Float64),
+ audio_cost_usd Nullable(Float64),
+ image_cost_usd Nullable(Float64),
+ video_cost_usd Nullable(Float64),
+ latency Nullable(Float64),
+ time_to_first_token Nullable(Float64),
+ is_error UInt8,
+ error Nullable(String),
+ error_type LowCardinality(Nullable(String)),
+ error_normalized Nullable(String),
+ input Nullable(String),
+ output Nullable(String),
+ output_choices Nullable(String),
+ input_state Nullable(String),
+ output_state Nullable(String),
+ tools Nullable(String),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('ai_events', 'posthog', 'sharded_ai_events', cityHash64(concat(toString(team_id), '-', trace_id, '-', toString(toDate(timestamp)))));
+CREATE TABLE posthog.async_deletion_run (
+ id UInt64,
+ deletion_type UInt8,
+ key String,
+ group_type_index String,
+ team_id Int64
+) ENGINE = Join(ANY, LEFT, team_id, deletion_type, key);
+CREATE TABLE posthog.channel_definition (
+ domain String,
+ kind String,
+ domain_type Nullable(String),
+ type_if_paid Nullable(String),
+ type_if_organic Nullable(String)
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.channel_definition', '{replica}-{shard}') ORDER BY (domain, kind) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.clickhouse_cleanup_deleted_persons (
+ run_id String,
+ team_id Int64,
+ person_id UUID,
+ max_version UInt64,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, person_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.clickhouse_cleanup_orphaned_distinct_ids (
+ run_id String,
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ own_tombstone UInt8,
+ max_version Int64,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, distinct_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.clickhouse_cleanup_revived_distinct_ids (
+ run_id String,
+ team_id Int64,
+ distinct_id String,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, distinct_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.clickhouse_cleanup_revived_persons (
+ run_id String,
+ team_id Int64,
+ person_id UUID,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, person_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.cohort_membership (
+ team_id Int64,
+ cohort_id Int64,
+ person_id UUID,
+ status Enum8('entered'=1, 'left'=2),
+ last_updated DateTime64(6) DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.cohort_membership', '{replica}-{shard}', last_updated) ORDER BY (team_id, cohort_id, person_id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.cohortpeople (
+ person_id UUID,
+ cohort_id Int64,
+ team_id Int64,
+ sign Int8,
+ version UInt64
+) ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/tables/noshard/posthog.cohortpeople', '{replica}-{shard}', sign) ORDER BY (team_id, cohort_id, person_id, version) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.conversion_goal_attributed_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ person_id UUID,
+ conversion_timestamp DateTime64(6, 'UTC'),
+ conversion_value Float64,
+ touchpoint_timestamp DateTime64(6, 'UTC'),
+ touchpoint_weight Float64,
+ campaign_name String,
+ source_name String,
+ medium_name String,
+ content_name String,
+ term_name String,
+ referring_domain_name String,
+ gclid_name String,
+ fbclid_name String,
+ gad_source_name String,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_conversion_goal_attributed_preaggregated', cityHash64(person_id));
+CREATE TABLE posthog.distributed_events_recent (
+ uuid UUID,
+ event String,
+ properties String CODEC(ZSTD(3)),
+ 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),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ inserted_at DateTime64(6, 'UTC') DEFAULT now64(),
+ _timestamp_ms DateTime64(3)
+) ENGINE = Distributed('batch_exports', 'posthog', 'sharded_events_recent', sipHash64(distinct_id));
+CREATE TABLE posthog.distributed_posthog_document_embeddings (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ model_name LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings', cityHash64(document_id));
+CREATE TABLE posthog.distributed_system_processes (
+ is_initial_query UInt8,
+ user String,
+ query_id String,
+ address IPv6,
+ port UInt16,
+ initial_user String,
+ initial_query_id String,
+ initial_address IPv6,
+ initial_port UInt16,
+ interface UInt8,
+ os_user String,
+ client_hostname String,
+ client_name String,
+ client_revision UInt64,
+ client_version_major UInt64,
+ client_version_minor UInt64,
+ client_version_patch UInt64,
+ http_method UInt8,
+ http_user_agent String,
+ http_referer String,
+ forwarded_for String,
+ quota_key String,
+ distributed_depth UInt64,
+ elapsed Float64,
+ is_cancelled UInt8,
+ is_all_data_sent UInt8,
+ read_rows UInt64,
+ read_bytes UInt64,
+ total_rows_approx UInt64,
+ written_rows UInt64,
+ written_bytes UInt64,
+ memory_usage Int64,
+ peak_memory_usage Int64,
+ query String,
+ query_kind String,
+ thread_ids Array(UInt64),
+ ProfileEvents Map(String, UInt64),
+ Settings Map(String, String),
+ current_database String,
+ ProfileEvents.Names Array(String) ALIAS mapKeys(ProfileEvents),
+ ProfileEvents.Values Array(UInt64) ALIAS mapValues(ProfileEvents),
+ Settings.Names Array(String) ALIAS mapKeys(Settings),
+ Settings.Values Array(String) ALIAS mapValues(Settings)
+) ENGINE = Distributed('posthog', 'system', 'processes') SETTINGS skip_unavailable_shards = 1;
+CREATE TABLE posthog.dmat_slot_assignments (
+ team_id UInt64,
+ column_index UInt8,
+ property_name String,
+ version UInt32 DEFAULT toUnixTimestamp(now())
+) ENGINE = ReplacingMergeTree(version) ORDER BY (team_id, column_index) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.dummy (
+ id String
+) ENGINE = MergeTree() ORDER BY (id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.dummy_privileges (
+ id String
+) ENGINE = MergeTree() ORDER BY (id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.duplicate_events (
+ team_id Int64,
+ distinct_id String,
+ event String,
+ source_uuid UUID,
+ duplicate_uuid UUID,
+ similarity_score Float64,
+ dedup_type LowCardinality(String),
+ is_confirmed UInt8,
+ reason Nullable(String),
+ version String,
+ different_property_count UInt32,
+ properties_similarity Float64,
+ source_message String,
+ duplicate_message String,
+ distinct_fields Array(Tuple(field_name String, original_value String, new_value String)),
+ inserted_at DateTime64(3, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX kafka_timestamp_minmax_duplicate_events _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.duplicate_events', '{replica}-{shard}') ORDER BY (team_id, distinct_id, event, inserted_at) PARTITION BY toYYYYMMDD(inserted_at) TTL inserted_at + toIntervalDay(7) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.eni_inventory (
+ collected_at DateTime,
+ eni_id String,
+ ip_address String,
+ owner_account String,
+ subnet_id String,
+ security_groups Array(JSON),
+ instance_id String,
+ node_name String,
+ karpenter_nodeclaim String,
+ karpenter_ec2nodeclass String
+) ENGINE = ReplacingMergeTree(collected_at) ORDER BY (eni_id, ip_address) PARTITION BY toYYYYMMDD(collected_at) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.error_tracking_fingerprint_issue_state (
+ team_id Int64,
+ fingerprint String,
+ issue_id UUID,
+ issue_name Nullable(String),
+ issue_description Nullable(String),
+ issue_status String,
+ issue_severity Nullable(String),
+ assigned_user_id Nullable(Int64),
+ assigned_role_id Nullable(UUID),
+ first_seen DateTime64(3, 'UTC'),
+ is_deleted Int8,
+ version Int64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'raw_error_tracking_fingerprint_issue_state');
+CREATE TABLE posthog.error_tracking_issue_fingerprint_overrides (
+ team_id Int64,
+ fingerprint String,
+ issue_id UUID,
+ is_deleted Int8,
+ version Int64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX kafka_timestamp_minmax_error_tracking_issue_fingerprint_overrides _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.error_tracking_issue_fingerprint_overrides', '{replica}-{shard}', version) ORDER BY (team_id, fingerprint) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.events_dead_letter_queue (
+ id UUID,
+ event_uuid UUID,
+ event String,
+ properties String,
+ distinct_id String,
+ team_id Int64,
+ elements_chain String,
+ created_at DateTime64(6, 'UTC'),
+ ip String,
+ site_url String,
+ now DateTime64(6, 'UTC'),
+ raw_payload String,
+ error_timestamp DateTime64(6, 'UTC'),
+ error_location String,
+ error String,
+ tags Array(String),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.events_dead_letter_queue', '{replica}-{shard}', _timestamp) ORDER BY (id, event_uuid, distinct_id, team_id) TTL toDate(_timestamp) + toIntervalWeek(4) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.events_recent (
+ uuid UUID,
+ event String,
+ properties String,
+ 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,
+ group0_properties String,
+ group1_properties String,
+ group2_properties String,
+ group3_properties String,
+ group4_properties String,
+ 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),
+ _timestamp DateTime,
+ _offset UInt64,
+ inserted_at DateTime64(6, 'UTC')
+) ENGINE = Distributed('batch_exports', 'posthog', 'sharded_events_recent', sipHash64(distinct_id));
+CREATE TABLE posthog.exchange_rate (
+ currency String,
+ date Date,
+ rate Decimal(18, 10),
+ version UInt32 DEFAULT toUnixTimestamp(now())
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.exchange_rate', '{replica}-{shard}', version) ORDER BY (date, currency) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.experiment_metric_events_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ entity_id String,
+ timestamp DateTime64(6, 'UTC'),
+ event_uuid UUID,
+ session_id String,
+ numeric_value Float64 DEFAULT 0,
+ steps Array(UInt8) DEFAULT [],
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_experiment_metric_events_preaggregated', cityHash64(entity_id));
+CREATE TABLE posthog.flow_logs_local (
+ interface_id String,
+ srcaddr String,
+ dstaddr String,
+ srcport UInt16,
+ dstport UInt16,
+ protocol UInt8,
+ packets UInt32,
+ bytes UInt64,
+ ts_start DateTime,
+ ts_end DateTime,
+ action LowCardinality(String),
+ log_status LowCardinality(String)
+) ENGINE = MergeTree() ORDER BY (ts_start, dstport, dstaddr, interface_id) PARTITION BY toYYYYMMDD(ts_start) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.groups (
+ group_type_index UInt8,
+ group_key String,
+ created_at DateTime64(3),
+ team_id Int64,
+ group_properties String,
+ _timestamp DateTime,
+ _offset UInt64,
+ is_deleted Bool,
+ INDEX is_deleted_idx is_deleted TYPE minmax GRANULARITY 1
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.groups', '{replica}-{shard}', _timestamp) ORDER BY (team_id, group_type_index, group_key) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.groups2 (
+ group_key String,
+ created_at DateTime64(3)
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.groups2', '{replica}-{shard}') ORDER BY (group_key) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.hog_invocation_results (
+ team_id Int64,
+ function_kind LowCardinality(String),
+ function_id String,
+ invocation_id String,
+ parent_run_id String,
+ status LowCardinality(String),
+ attempts UInt8,
+ is_retry UInt8,
+ scheduled_at DateTime64(6, 'UTC'),
+ first_scheduled_at DateTime64(6, 'UTC'),
+ started_at Nullable(DateTime64(6, 'UTC')),
+ finished_at Nullable(DateTime64(6, 'UTC')),
+ duration_ms Nullable(UInt32),
+ error_kind LowCardinality(String),
+ error_message String,
+ event_uuid String,
+ distinct_id String,
+ person_id String,
+ invocation_globals String,
+ version UInt64,
+ is_deleted UInt8,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'hog_invocation_results_data');
+CREATE TABLE posthog.ingestion_warnings (
+ team_id Int64,
+ source LowCardinality(String),
+ type String,
+ details String,
+ timestamp DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'sharded_ingestion_warnings', rand());
+CREATE TABLE posthog.ingestion_warnings_v2_distributed (
+ team_id Int64,
+ source LowCardinality(String),
+ type LowCardinality(String),
+ details String,
+ timestamp DateTime64(6, 'UTC'),
+ category LowCardinality(String) DEFAULT coalesce(nullIf(JSONExtractString(details, 'category'), ''), 'unknown'),
+ severity LowCardinality(String) DEFAULT coalesce(nullIf(JSONExtractString(details, 'severity'), ''), 'warning'),
+ pipeline_step LowCardinality(String) DEFAULT coalesce(nullIf(JSONExtractString(details, 'pipelineStep'), ''), 'unknown'),
+ event_uuid Nullable(UUID) DEFAULT toUUIDOrNull(JSONExtractString(details, 'eventUuid')),
+ distinct_id Nullable(String) DEFAULT nullIf(JSONExtractString(details, 'distinctId'), ''),
+ group_key Nullable(String) DEFAULT nullIf(JSONExtractString(details, 'groupKey'), ''),
+ person_id Nullable(UUID) DEFAULT toUUIDOrNull(JSONExtractString(details, 'personId')),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'ingestion_warnings_v2');
+CREATE TABLE posthog.k8s_node_inventory (
+ collected_at DateTime,
+ node_name String,
+ instance_id String,
+ region String,
+ nodeclaim String,
+ nodepool String,
+ ec2nodeclass String,
+ labels JSON,
+ enis Array(JSON)
+) ENGINE = ReplacingMergeTree(collected_at) ORDER BY (nodepool, instance_id) PARTITION BY toYYYYMMDD(collected_at) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.kafka_error_tracking_issue_fingerprint_overrides_ws (
+ team_id Int64,
+ fingerprint String,
+ issue_id UUID,
+ is_deleted Int8,
+ version Int64
+) ENGINE = Kafka(warpstream_shared) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_error_tracking_issue_fingerprint_overrides_ws', kafka_topic_list = 'clickhouse_error_tracking_issue_fingerprint';
+CREATE TABLE posthog.llma_metrics_daily (
+ date Date,
+ team_id UInt64,
+ metric_name String,
+ metric_value Float64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.llma_metrics_daily', '{replica}-{shard}') ORDER BY (team_id, date, metric_name) PARTITION BY toYYYYMM(date) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.marketing_conversions_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ person_id UUID,
+ conversion_timestamp DateTime64(6, 'UTC'),
+ conversion_math_value Float64,
+ session_id String,
+ campaign_name String,
+ source_name String,
+ medium_name String,
+ content_name String,
+ term_name String,
+ referring_domain_name String,
+ gclid_name String,
+ fbclid_name String,
+ gad_source_name String,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_marketing_conversions_preaggregated', cityHash64(person_id));
+CREATE TABLE posthog.marketing_costs_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ source_id String,
+ source_name String,
+ grain LowCardinality(String),
+ match_key String,
+ campaign_id String,
+ campaign_name String,
+ ad_group_id String,
+ ad_group_name String,
+ ad_id String,
+ ad_name String,
+ cost_date Date,
+ cost Float64,
+ clicks Float64,
+ impressions Float64,
+ reported_conversions Float64,
+ reported_conversion_value Float64,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_marketing_costs_preaggregated', cityHash64(source_name, campaign_id));
+CREATE TABLE posthog.marketing_touchpoints_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ person_id UUID,
+ touchpoint_timestamp DateTime64(6, 'UTC'),
+ campaign_name String,
+ source_name String,
+ medium_name String,
+ content_name String,
+ term_name String,
+ referring_domain_name String,
+ gclid_name String,
+ fbclid_name String,
+ gad_source_name String,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_marketing_touchpoints_preaggregated', cityHash64(person_id));
+CREATE TABLE posthog.materialized_test (
+ id UInt32,
+ properties String
+) ENGINE = MergeTree() ORDER BY (id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.message_assets (
+ team_id Int64,
+ function_kind LowCardinality(String),
+ function_id String,
+ parent_run_id String,
+ invocation_id String,
+ action_id String,
+ kind LowCardinality(String),
+ distinct_id String,
+ person_id String,
+ recipient String,
+ subject String,
+ status LowCardinality(String),
+ sent_at DateTime64(6, 'UTC'),
+ version UInt64,
+ is_deleted UInt8,
+ html String,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'message_assets_data');
+CREATE TABLE posthog.person (
+ id UUID,
+ created_at DateTime64(3),
+ team_id Int64,
+ properties String,
+ is_identified Int8,
+ is_deleted Int8 DEFAULT 0,
+ version UInt64,
+ _timestamp DateTime,
+ _offset UInt64,
+ last_seen_at Nullable(DateTime64(3))
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/am0005_20220705151225_noshard/posthog.person', '{replica}-{shard}', version) ORDER BY (team_id, id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.person_distinct_id (
+ distinct_id String COMMENT 'skip_0003_fill_person_distinct_id2',
+ person_id UUID,
+ team_id Int64,
+ _sign Int8 DEFAULT 1,
+ is_deleted Int8 ALIAS if(_sign = -1, 1, 0),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/tables/noshard/posthog.person_distinct_id', '{replica}-{shard}', _sign) ORDER BY (team_id, distinct_id, person_id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.person_distinct_id2 (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ is_deleted Int8,
+ version Int64 DEFAULT 1,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_distinct_id2', '{replica}-{shard}', version) ORDER BY (team_id, distinct_id) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.person_distinct_id_overrides (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ is_deleted Int8,
+ version Int64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX kafka_timestamp_minmax_person_distinct_id_overrides _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_distinct_id_overrides', '{replica}-{shard}', version) ORDER BY (team_id, distinct_id) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.person_overrides (
+ team_id Int32,
+ old_person_id UUID,
+ override_person_id UUID,
+ merged_at DateTime64(6, 'UTC'),
+ oldest_event DateTime64(6, 'UTC'),
+ created_at DateTime64(6, 'UTC') DEFAULT now(),
+ version Int32
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_overrides', '{replica}-{shard}', version) ORDER BY (team_id, old_person_id) PARTITION BY toYYYYMM(oldest_event) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.person_static_cohort (
+ id UUID,
+ person_id UUID,
+ cohort_id Int64,
+ team_id Int64,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_static_cohort', '{replica}-{shard}', _timestamp) ORDER BY (team_id, cohort_id, person_id, id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.pg_embeddings (
+ domain String,
+ team_id Int64,
+ id String,
+ vector Array(Float32),
+ text String,
+ properties String CODEC(ZSTD(3)),
+ timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ is_deleted UInt8
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.pg_embeddings', '{replica}-{shard}', timestamp, is_deleted) ORDER BY (team_id, domain, id) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.plugin_log_entries (
+ id UUID,
+ team_id Int64,
+ plugin_id Int64,
+ plugin_config_id Int64,
+ timestamp DateTime64(6, 'UTC'),
+ source String,
+ type String,
+ message String,
+ instance_id UUID,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.plugin_log_entries', '{replica}-{shard}', _timestamp) ORDER BY (team_id, id) PARTITION BY plugin_id TTL toDate(timestamp) + toIntervalWeek(1) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.poc_events (
+ uuid UUID,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String
+) ENGINE = MergeTree() ORDER BY (team_id, toDate(timestamp), cityHash64(distinct_id), cityHash64(uuid)) PARTITION BY toYYYYMM(timestamp) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.posthog_document_embeddings (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ model_name LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ content String DEFAULT '',
+ INDEX kafka_timestamp_minmax_posthog_document_embeddings _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.posthog_document_embeddings', '{replica}-{shard}', inserted_at) ORDER BY (team_id, toDate(timestamp), product, document_type, model_name, rendering, cityHash64(document_id)) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.property_definitions (
+ team_id UInt32,
+ project_id Nullable(UInt32),
+ name String,
+ property_type Nullable(String),
+ event Nullable(String),
+ group_type_index Nullable(UInt8),
+ type UInt8 DEFAULT 1,
+ last_seen_at DateTime,
+ version UInt64 MATERIALIZED bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.property_definitions', '{replica}-{shard}', version) ORDER BY (team_id, type, coalesce(event, ''), name, coalesce(group_type_index, 255)) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.property_values_distributed (
+ team_id Int64 CODEC(DoubleDelta, ZSTD(1)),
+ property_type LowCardinality(String),
+ property_key LowCardinality(String),
+ property_value String,
+ property_count SimpleAggregateFunction(sum, UInt64),
+ last_seen SimpleAggregateFunction(max, DateTime) DEFAULT now()
+) ENGINE = Distributed('aux', 'posthog', 'property_values');
+CREATE TABLE posthog.query_log_archive (
+ hostname LowCardinality(String),
+ user LowCardinality(String),
+ query_id String,
+ initial_query_id String,
+ is_initial_query UInt8,
+ type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4),
+ event_date Date,
+ event_time DateTime,
+ event_time_microseconds DateTime64(6),
+ query_start_time DateTime,
+ query_start_time_microseconds DateTime64(6),
+ query_duration_ms UInt64,
+ read_rows UInt64,
+ read_bytes UInt64,
+ written_rows UInt64,
+ written_bytes UInt64,
+ result_rows UInt64,
+ result_bytes UInt64,
+ memory_usage UInt64,
+ peak_threads_usage UInt64,
+ current_database LowCardinality(String),
+ query String,
+ formatted_query String,
+ normalized_query_hash UInt64,
+ query_kind LowCardinality(String),
+ exception_code Int32,
+ exception String,
+ stack_trace String,
+ team_id Int64,
+ log_comment JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email),
+ ProfileEvents Map(String, UInt64),
+ exception_name String ALIAS errorCodeToName(exception_code),
+ ProfileEvents_RealTimeMicroseconds Int64 ALIAS ProfileEvents['RealTimeMicroseconds'],
+ ProfileEvents_OSCPUVirtualTimeMicroseconds Int64 ALIAS ProfileEvents['OSCPUVirtualTimeMicroseconds'],
+ ProfileEvents_S3Clients Int64 ALIAS ProfileEvents['S3Clients'],
+ ProfileEvents_S3DeleteObjects Int64 ALIAS ProfileEvents['S3DeleteObjects'],
+ ProfileEvents_S3CopyObject Int64 ALIAS ProfileEvents['S3CopyObject'],
+ ProfileEvents_S3ListObjects Int64 ALIAS ProfileEvents['S3ListObjects'],
+ ProfileEvents_S3HeadObject Int64 ALIAS ProfileEvents['S3HeadObject'],
+ ProfileEvents_S3GetObjectAttributes Int64 ALIAS ProfileEvents['S3GetObjectAttributes'],
+ ProfileEvents_S3CreateMultipartUpload Int64 ALIAS ProfileEvents['S3CreateMultipartUpload'],
+ ProfileEvents_S3UploadPartCopy Int64 ALIAS ProfileEvents['S3UploadPartCopy'],
+ ProfileEvents_S3UploadPart Int64 ALIAS ProfileEvents['S3UploadPart'],
+ ProfileEvents_S3AbortMultipartUpload Int64 ALIAS ProfileEvents['S3AbortMultipartUpload'],
+ ProfileEvents_S3CompleteMultipartUpload Int64 ALIAS ProfileEvents['S3CompleteMultipartUpload'],
+ ProfileEvents_S3PutObject Int64 ALIAS ProfileEvents['S3PutObject'],
+ ProfileEvents_S3GetObject Int64 ALIAS ProfileEvents['S3GetObject'],
+ ProfileEvents_ReadBufferFromS3Bytes Int64 ALIAS ProfileEvents['ReadBufferFromS3Bytes'],
+ ProfileEvents_WriteBufferFromS3Bytes Int64 ALIAS ProfileEvents['WriteBufferFromS3Bytes'],
+ lc_workflow LowCardinality(String) ALIAS log_comment.workflow,
+ lc_kind LowCardinality(String) ALIAS log_comment.kind,
+ lc_id String ALIAS CAST(log_comment.id, 'String'),
+ lc_route_id String ALIAS CAST(log_comment.route_id, 'String'),
+ lc_access_method LowCardinality(String) ALIAS log_comment.access_method,
+ lc_api_key_label String ALIAS CAST(log_comment.api_key_label, 'String'),
+ lc_api_key_mask String ALIAS CAST(log_comment.api_key_mask, 'String'),
+ lc_query_type LowCardinality(String) ALIAS log_comment.query_type,
+ lc_product LowCardinality(String) ALIAS log_comment.product,
+ lc_chargeable Bool ALIAS log_comment.chargeable,
+ lc_name String ALIAS CAST(log_comment.name, 'String'),
+ lc_request_name String ALIAS CAST(log_comment.request_name, 'String'),
+ lc_client_query_id String ALIAS CAST(log_comment.client_query_id, 'String'),
+ lc_org_id String ALIAS CAST(log_comment.org_id, 'String'),
+ lc_user_id Int64 ALIAS log_comment.user_id,
+ lc_is_impersonated Bool ALIAS log_comment.is_impersonated,
+ lc_session_id String ALIAS CAST(log_comment.session_id, 'String'),
+ lc_dashboard_id Int64 ALIAS log_comment.dashboard_id,
+ lc_insight_id Int64 ALIAS log_comment.insight_id,
+ lc_cohort_id Int64 ALIAS log_comment.cohort_id,
+ lc_batch_export_id String ALIAS CAST(log_comment.batch_export_id, 'String'),
+ lc_experiment_id Int64 ALIAS log_comment.experiment_id,
+ lc_experiment_feature_flag_key String ALIAS CAST(log_comment.experiment_feature_flag_key, 'String'),
+ lc_alert_config_id String ALIAS CAST(log_comment.alert_config_id, 'String'),
+ lc_feature LowCardinality(String) ALIAS log_comment.feature,
+ lc_table_id String ALIAS CAST(log_comment.table_id, 'String'),
+ lc_warehouse_query Bool ALIAS log_comment.warehouse_query,
+ lc_person_on_events_mode LowCardinality(String) ALIAS log_comment.person_on_events_mode,
+ lc_service_name String ALIAS CAST(log_comment.service_name, 'String'),
+ lc_workload LowCardinality(String) ALIAS log_comment.workload,
+ lc_query__kind LowCardinality(String) ALIAS if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind')),
+ lc_query__query String ALIAS multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query')),
+ lc_query String ALIAS if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), ''),
+ lc_temporal__workflow_namespace String ALIAS CAST(log_comment.`temporal.workflow_namespace`, 'String'),
+ lc_temporal__workflow_type String ALIAS CAST(log_comment.`temporal.workflow_type`, 'String'),
+ lc_temporal__workflow_id String ALIAS CAST(log_comment.`temporal.workflow_id`, 'String'),
+ lc_temporal__workflow_run_id String ALIAS CAST(log_comment.`temporal.workflow_run_id`, 'String'),
+ lc_temporal__activity_type String ALIAS CAST(log_comment.`temporal.activity_type`, 'String'),
+ lc_temporal__activity_id String ALIAS CAST(log_comment.`temporal.activity_id`, 'String'),
+ lc_temporal__attempt Int64 ALIAS log_comment.`temporal.attempt`,
+ lc_dagster__job_name String ALIAS CAST(log_comment.`dagster.job_name`, 'String'),
+ lc_dagster__run_id String ALIAS CAST(log_comment.`dagster.run_id`, 'String'),
+ lc_dagster__owner String ALIAS CAST(log_comment.`dagster.tags.owner`, 'String'),
+ lc_modifiers String ALIAS if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')
+) ENGINE = Distributed('ops', 'posthog', 'sharded_query_log_archive');
+CREATE TABLE posthog.rds_inventory (
+ collected_at DateTime,
+ region String,
+ instance_name String,
+ cluster_name String,
+ endpoint String,
+ ip_address String
+) ENGINE = ReplacingMergeTree(collected_at) ORDER BY (region, instance_name) PARTITION BY toYYYYMMDD(collected_at) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.session_replay_features (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ event_count SimpleAggregateFunction(sum, Int64),
+ mouse_position_count SimpleAggregateFunction(sum, Int64),
+ mouse_sum_x SimpleAggregateFunction(sum, Float64),
+ mouse_sum_x_squared SimpleAggregateFunction(sum, Float64),
+ mouse_sum_y SimpleAggregateFunction(sum, Float64),
+ mouse_sum_y_squared SimpleAggregateFunction(sum, Float64),
+ mouse_distance_traveled SimpleAggregateFunction(sum, Float64),
+ mouse_direction_change_count SimpleAggregateFunction(sum, Int64),
+ mouse_velocity_sum SimpleAggregateFunction(sum, Float64),
+ mouse_velocity_sum_of_squares SimpleAggregateFunction(sum, Float64),
+ mouse_velocity_count SimpleAggregateFunction(sum, Int64),
+ scroll_event_count SimpleAggregateFunction(sum, Int64),
+ total_scroll_magnitude SimpleAggregateFunction(sum, Float64),
+ scroll_direction_reversal_count SimpleAggregateFunction(sum, Int64),
+ rapid_scroll_reversal_count SimpleAggregateFunction(sum, Int64),
+ scroll_to_top_count SimpleAggregateFunction(sum, Int64),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ rage_click_count SimpleAggregateFunction(sum, Int64),
+ dead_click_count SimpleAggregateFunction(sum, Int64),
+ backspace_count SimpleAggregateFunction(sum, Int64),
+ inter_action_gap_count SimpleAggregateFunction(sum, Int64),
+ inter_action_gap_sum_ms SimpleAggregateFunction(sum, Float64),
+ inter_action_gap_sum_of_squares_ms SimpleAggregateFunction(sum, Float64),
+ max_idle_gap_ms SimpleAggregateFunction(max, Float64),
+ long_idle_gap_count SimpleAggregateFunction(sum, Int64),
+ quick_back_count SimpleAggregateFunction(sum, Int64),
+ page_visit_count SimpleAggregateFunction(sum, Int64),
+ unique_url_count AggregateFunction(uniqCombined(12), String),
+ login_path_visit_count SimpleAggregateFunction(sum, Int64),
+ signup_path_visit_count SimpleAggregateFunction(sum, Int64),
+ checkout_path_visit_count SimpleAggregateFunction(sum, Int64),
+ cart_path_visit_count SimpleAggregateFunction(sum, Int64),
+ billing_path_visit_count SimpleAggregateFunction(sum, Int64),
+ settings_path_visit_count SimpleAggregateFunction(sum, Int64),
+ account_path_visit_count SimpleAggregateFunction(sum, Int64),
+ error_path_visit_count SimpleAggregateFunction(sum, Int64),
+ not_found_path_visit_count SimpleAggregateFunction(sum, Int64),
+ admin_path_visit_count SimpleAggregateFunction(sum, Int64),
+ dashboard_path_visit_count SimpleAggregateFunction(sum, Int64),
+ onboarding_path_visit_count SimpleAggregateFunction(sum, Int64),
+ cancel_path_visit_count SimpleAggregateFunction(sum, Int64),
+ refund_path_visit_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ console_error_after_click_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ network_request_count SimpleAggregateFunction(sum, Int64),
+ network_failed_request_count SimpleAggregateFunction(sum, Int64),
+ network_4xx_count SimpleAggregateFunction(sum, Int64),
+ network_5xx_count SimpleAggregateFunction(sum, Int64),
+ network_request_duration_sum SimpleAggregateFunction(sum, Float64),
+ network_request_duration_sum_of_squares SimpleAggregateFunction(sum, Float64),
+ network_request_duration_count SimpleAggregateFunction(sum, Int64),
+ mutation_count SimpleAggregateFunction(sum, Int64),
+ viewport_resize_count SimpleAggregateFunction(sum, Int64),
+ touch_event_count SimpleAggregateFunction(sum, Int64),
+ max_scroll_y SimpleAggregateFunction(max, Float64),
+ unique_click_target_count AggregateFunction(uniqCombined(12), Int64),
+ unique_form_field_count AggregateFunction(uniqCombined(12), Int64),
+ text_selection_count SimpleAggregateFunction(sum, Int64),
+ selection_copy_count SimpleAggregateFunction(sum, Int64),
+ is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0
+) ENGINE = Distributed('aux', 'posthog', 'sharded_session_replay_features', sipHash64(session_id));
+CREATE TABLE posthog.sharded_app_metrics (
+ team_id Int64,
+ timestamp DateTime64(6, 'UTC'),
+ plugin_config_id Int64,
+ category LowCardinality(String),
+ job_id String,
+ successes SimpleAggregateFunction(sum, Int64),
+ successes_on_retry SimpleAggregateFunction(sum, Int64),
+ failures SimpleAggregateFunction(sum, Int64),
+ error_uuid UUID,
+ error_type String,
+ error_details String CODEC(ZSTD(3)),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_app_metrics', '{replica}') ORDER BY (team_id, plugin_config_id, job_id, category, toStartOfHour(timestamp), error_type, error_uuid) PARTITION BY toYYYYMM(timestamp) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_app_metrics2 (
+ team_id Int64,
+ timestamp DateTime64(6, 'UTC'),
+ app_source LowCardinality(String),
+ app_source_id String,
+ instance_id String,
+ metric_kind LowCardinality(String),
+ metric_name LowCardinality(String),
+ count SimpleAggregateFunction(sum, Int64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_app_metrics2', '{replica}') ORDER BY (team_id, app_source, app_source_id, instance_id, toStartOfHour(timestamp), metric_kind, metric_name) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_billing_usage_records (
+ schema_version UInt8,
+ record_id String,
+ producer_id LowCardinality(String),
+ team_id Int64,
+ organization_id UUID,
+ usage_key LowCardinality(String),
+ unit LowCardinality(String),
+ quantity Int64,
+ timestamp DateTime64(6, 'UTC'),
+ inserted_at DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_billing_usage_records', '{replica}', inserted_at) ORDER BY (team_id, toDate(timestamp), producer_id, usage_key, record_id) PARTITION BY toYYYYMM(timestamp) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_distinct_id_usage (
+ team_id Int64,
+ distinct_id String,
+ minute DateTime,
+ event_count UInt64
+) ENGINE = ReplicatedSummingMergeTree('/clickhouse/tables/{shard}/posthog.distinct_id_usage', '{replica}', (event_count)) 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;
+CREATE TABLE posthog.sharded_events (
+ uuid UUID,
+ event String,
+ properties String CODEC(ZSTD(3)),
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ elements_chain String,
+ created_at DateTime64(6, 'UTC'),
+ person_id UUID,
+ 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)),
+ $group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0',
+ $group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1',
+ $group_2 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^"|"$', '') COMMENT 'column_materializer::$group_2',
+ $group_3 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^"|"$', '') COMMENT 'column_materializer::$group_3',
+ $group_4 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^"|"$', '') COMMENT 'column_materializer::$group_4',
+ $window_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^"|"$', '') COMMENT 'column_materializer::$window_id',
+ $session_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^"|"$', '') COMMENT 'column_materializer::$session_id',
+ _timestamp DateTime,
+ _offset UInt64,
+ person_created_at DateTime64(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),
+ 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'))), 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)),
+ $session_id_uuid Nullable(UInt128) MATERIALIZED toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)')),
+ consumer_breadcrumbs Array(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_trace_id Nullable(String) MATERIALIZED JSONExtract(properties, '$ai_trace_id', 'Nullable(String)'),
+ mat_historical_migration Nullable(String) DEFAULT JSONExtract(properties, 'historical_migration', 'Nullable(String)'),
+ 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_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_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 is_deleted_idx is_deleted TYPE minmax 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 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 minmax_mat_historical_migration mat_historical_migration TYPE minmax GRANULARITY 1,
+ 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_$session_id_uuid `$session_id_uuid` 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, replicated_fetches_min_part_level = 1, replicated_fetches_min_part_level_timeout_seconds = 300;
+CREATE TABLE posthog.sharded_events_codec_test (
+ uuid UUID,
+ event String,
+ properties String CODEC(ZSTD(3)),
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ elements_chain String,
+ created_at DateTime64(6, 'UTC'),
+ person_id UUID,
+ 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)),
+ $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',
+ $group_3 String MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^"|"$', '') COMMENT 'column_materializer::$group_3',
+ $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',
+ _timestamp DateTime,
+ _offset UInt64,
+ person_created_at DateTime64(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),
+ 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_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)(?:\\.|$|:)')),
+ elements_chain_ids Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")attr_id="(.*?)"')),
+ 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'))), 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)),
+ $session_id_uuid Nullable(UInt128) MATERIALIZED toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)')),
+ consumer_breadcrumbs Array(String),
+ properties_map_ephemeral Map(String, String),
+ person_properties_map_ephemeral Map(String, 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_trace_id Nullable(String) MATERIALIZED JSONExtract(properties, '$ai_trace_id', 'Nullable(String)'),
+ mat_historical_migration Nullable(String) DEFAULT JSONExtract(properties, 'historical_migration', 'Nullable(String)'),
+ 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)'),
+ mat_$ai_experiment_id Nullable(String) DEFAULT JSONExtract(properties, '$ai_experiment_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_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 is_deleted_idx is_deleted TYPE minmax 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 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 minmax_mat_historical_migration mat_historical_migration TYPE minmax GRANULARITY 1,
+ 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_$session_id_uuid `$session_id_uuid` TYPE minmax GRANULARITY 1
+) ENGINE = ReplacingMergeTree(_timestamp) ORDER BY (team_id, toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) PARTITION BY toYYYYMM(timestamp) SAMPLE BY cityHash64(distinct_id) SETTINGS default_compression_codec = 'ZSTD(3)', index_granularity = 8192;
+CREATE TABLE posthog.sharded_experiment_exposures_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ entity_id String,
+ variant String,
+ first_exposure_time DateTime64(6, 'UTC'),
+ last_exposure_time DateTime64(6, 'UTC'),
+ exposure_event_uuid UUID,
+ exposure_session_id String,
+ breakdown_value Array(String),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.experiment_exposures_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, entity_id, breakdown_value) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_flag_evaluations (
+ uuid UUID,
+ event LowCardinality(String),
+ properties String,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ created_at DateTime64(6, 'UTC'),
+ person_id UUID,
+ person_properties String,
+ group0_properties String,
+ group1_properties String,
+ group2_properties String,
+ group3_properties String,
+ group4_properties String,
+ inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,
+ $group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0',
+ $group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1',
+ $group_2 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^"|"$', '') COMMENT 'column_materializer::$group_2',
+ $group_3 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^"|"$', '') COMMENT 'column_materializer::$group_3',
+ $group_4 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^"|"$', '') COMMENT 'column_materializer::$group_4',
+ flag_key String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag',
+ response LowCardinality(String) DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag_response',
+ session_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^"|"$', '') COMMENT 'column_materializer::properties::$session_id',
+ request_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_request_id'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag_request_id',
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX distinct_id_idx distinct_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX person_id_idx person_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX session_id_idx session_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX request_id_idx request_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX inserted_at_idx inserted_at TYPE minmax GRANULARITY 1
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.flag_evaluations', '{replica}') ORDER BY (team_id, flag_key, toDate(timestamp), cityHash64(distinct_id)) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_heatmaps (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ timestamp DateTime64(6, 'UTC'),
+ x Int16,
+ y Int16,
+ scale_factor Int16,
+ viewport_width Int16,
+ viewport_height Int16,
+ pointer_target_fixed Bool,
+ current_url String,
+ type LowCardinality(String),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.heatmaps', '{replica}') ORDER BY (type, team_id, toDate(timestamp), current_url, viewport_width) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_log_entries (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_log_entries', '{replica}', _timestamp) ORDER BY (team_id, log_source, log_source_id, instance_id, timestamp) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_performance_events (
+ uuid UUID,
+ session_id String,
+ window_id String,
+ pageview_id String,
+ distinct_id String,
+ timestamp DateTime64(3),
+ time_origin DateTime64(3, 'UTC'),
+ entry_type LowCardinality(String),
+ name String,
+ team_id Int64,
+ current_url String,
+ start_time Float64,
+ duration Float64,
+ redirect_start Float64,
+ redirect_end Float64,
+ worker_start Float64,
+ fetch_start Float64,
+ domain_lookup_start Float64,
+ domain_lookup_end Float64,
+ connect_start Float64,
+ secure_connection_start Float64,
+ connect_end Float64,
+ request_start Float64,
+ response_start Float64,
+ response_end Float64,
+ decoded_body_size Int64,
+ encoded_body_size Int64,
+ initiator_type LowCardinality(String),
+ next_hop_protocol LowCardinality(String),
+ render_blocking_status LowCardinality(String),
+ response_status Int64,
+ transfer_size Int64,
+ largest_contentful_paint_element String,
+ largest_contentful_paint_render_time Float64,
+ largest_contentful_paint_load_time Float64,
+ largest_contentful_paint_size Float64,
+ largest_contentful_paint_id String,
+ largest_contentful_paint_url String,
+ dom_complete Float64,
+ dom_content_loaded_event Float64,
+ dom_interactive Float64,
+ load_event_end Float64,
+ load_event_start Float64,
+ redirect_count Int64,
+ navigation_type LowCardinality(String),
+ unload_event_end Float64,
+ unload_event_start Float64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.performance_events', '{replica}') ORDER BY (team_id, toDate(timestamp), session_id, pageview_id, timestamp) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalWeek(3) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_posthog_document_embeddings_buffer (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ model_name LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_buffer', '{replica}', inserted_at) ORDER BY (inserted_at, model_name, cityHash64(document_id)) PARTITION BY toDate(inserted_at) TTL inserted_at + toIntervalDay(1) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ CONSTRAINT embedding_dimension_check CHECK length(embedding) = 3072,
+ INDEX kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_large_3072 _timestamp TYPE minmax GRANULARITY 3,
+ INDEX embedding_idx_l2 embedding TYPE vector_similarity('hnsw', 'L2Distance', 3072) GRANULARITY 100000000,
+ INDEX embedding_idx_cosine embedding TYPE vector_similarity('hnsw', 'cosineDistance', 3072) GRANULARITY 100000000
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072', '{replica}', inserted_at) ORDER BY (team_id, toDate(timestamp), product, document_type, rendering, cityHash64(document_id)) PARTITION BY toMonday(timestamp) TTL timestamp + toIntervalMonth(3) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ CONSTRAINT embedding_dimension_check CHECK length(embedding) = 1536,
+ INDEX kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_small_1536 _timestamp TYPE minmax GRANULARITY 3,
+ INDEX embedding_idx_l2 embedding TYPE vector_similarity('hnsw', 'L2Distance', 1536) GRANULARITY 100000000,
+ INDEX embedding_idx_cosine embedding TYPE vector_similarity('hnsw', 'cosineDistance', 1536) GRANULARITY 100000000
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536', '{replica}', inserted_at) ORDER BY (team_id, toDate(timestamp), product, document_type, rendering, cityHash64(document_id)) PARTITION BY toMonday(timestamp) TTL timestamp + toIntervalMonth(3) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_preaggregation_results (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7),
+ breakdown_value Array(String),
+ uniq_exact_state AggregateFunction(uniqExact, UUID)
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.preaggregation_results', '{replica}') ORDER BY (team_id, job_id, time_window_start, breakdown_value) PARTITION BY toYYYYMM(time_window_start) TTL expires_at SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_precalculated_events (
+ team_id Int64,
+ date Date,
+ distinct_id String,
+ person_id UUID,
+ condition String,
+ uuid UUID,
+ source String,
+ _timestamp DateTime64(6),
+ _partition UInt64,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_precalculated_events', '{replica}', _timestamp) ORDER BY (team_id, condition, date, distinct_id, uuid) PARTITION BY toYYYYMM(date) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_precalculated_person_properties (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ condition String,
+ matches Bool,
+ source String,
+ _timestamp DateTime64(6),
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_precalculated_person_properties', '{replica}', _timestamp) ORDER BY (team_id, condition, distinct_id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_raw_sessions (
+ team_id Int64,
+ session_id_v7 UInt128,
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_browser AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_browser_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_device_type AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_viewport_width AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_viewport_height AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_geoip_country_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_city_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_time_zone AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_irclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ pageview_uniq AggregateFunction(uniq, Nullable(UUID)),
+ autocapture_count SimpleAggregateFunction(sum, Int64),
+ autocapture_uniq AggregateFunction(uniq, Nullable(UUID)),
+ screen_count SimpleAggregateFunction(sum, Int64),
+ screen_uniq AggregateFunction(uniq, Nullable(UUID)),
+ maybe_has_session_replay SimpleAggregateFunction(max, Bool),
+ page_screen_autocapture_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),
+ vitals_lcp AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC')),
+ initial__kx AggregateFunction(argMin, String, DateTime64(6, 'UTC'))
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.raw_sessions', '{replica}') ORDER BY (team_id, toStartOfHour(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000))), cityHash64(session_id_v7), session_id_v7) PARTITION BY toYYYYMM(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000))) SAMPLE BY cityHash64(session_id_v7) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_raw_sessions_v3 (
+ team_id Int64,
+ session_id_v7 UInt128,
+ session_timestamp DateTime64(3) MATERIALIZED fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80))),
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ distinct_ids AggregateFunction(groupUniqArray, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),
+ entry_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ browser AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ browser_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ device_type AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ viewport_width AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ viewport_height AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ geoip_country_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_city_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_time_zone AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_referring_domain AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_campaign AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_medium AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_term AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_content AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gad_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_fbclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_has_gclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_has_fbclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_ad_ids_map AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC')),
+ entry_ad_ids_set AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC')),
+ entry_channel_type_properties AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC')),
+ pageview_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ autocapture_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ 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_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ event_names SimpleAggregateFunction(groupUniqArrayArray, 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
+) 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,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ session_id String,
+ window_id String,
+ snapshot_data String,
+ created_at DateTime64(6, 'UTC'),
+ has_full_snapshot Int8 MATERIALIZED JSONExtractBool(snapshot_data, 'has_full_snapshot') COMMENT 'column_materializer::has_full_snapshot',
+ _timestamp DateTime,
+ _offset UInt64,
+ events_summary Array(String) MATERIALIZED JSONExtract(JSON_QUERY(snapshot_data, '$.events_summary[*]'), 'Array(String)'),
+ click_count Int8 MATERIALIZED length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 2) AND (JSONExtractInt(x, 'data', 'source') = 2)), events_summary)),
+ keypress_count Int8 MATERIALIZED length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 5)), events_summary)),
+ timestamps_summary Array(DateTime64(6, 'UTC')) MATERIALIZED arraySort(arrayMap(x -> toDateTime(JSONExtractInt(x, 'timestamp') / 1000), events_summary)),
+ first_event_timestamp DateTime64(6, 'UTC') MATERIALIZED arrayReduce('min', timestamps_summary),
+ last_event_timestamp DateTime64(6, 'UTC') MATERIALIZED arrayReduce('max', timestamps_summary),
+ urls Array(String) MATERIALIZED arrayFilter(x -> (x != ''), arrayMap(x -> JSONExtractString(x, 'data', 'href'), events_summary))
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.session_recording_events', '{replica}', _timestamp) ORDER BY (team_id, toHour(timestamp), session_id, timestamp, uuid) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(created_at) + toIntervalWeek(3) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.sharded_session_replay_embeddings (
+ session_id String,
+ team_id Int64,
+ embeddings Array(Float32),
+ generation_timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ source_type LowCardinality(String),
+ input String
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.session_replay_embeddings', '{replica}') ORDER BY (toDate(generation_timestamp), team_id, session_id) PARTITION BY toYYYYMM(generation_timestamp) TTL toDate(generation_timestamp) + toIntervalYear(1) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.sharded_session_replay_events (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ active_milliseconds SimpleAggregateFunction(sum, Int64),
+ console_log_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ size SimpleAggregateFunction(sum, Int64),
+ message_count SimpleAggregateFunction(sum, Int64),
+ event_count SimpleAggregateFunction(sum, Int64),
+ _timestamp SimpleAggregateFunction(max, DateTime),
+ snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.session_replay_events', '{replica}') ORDER BY (toDate(min_first_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_sessions (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.sessions', '{replica}') ORDER BY (toStartOfDay(min_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_timestamp) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.tophog (
+ timestamp DateTime64(6, 'UTC'),
+ metric LowCardinality(String),
+ type LowCardinality(String) DEFAULT 'sum',
+ key Map(LowCardinality(String), String),
+ value Float64,
+ count UInt64 DEFAULT 0,
+ pipeline LowCardinality(String),
+ lane LowCardinality(String),
+ labels Map(LowCardinality(String), String)
+) ENGINE = Distributed('ops', 'posthog', 'sharded_tophog', cityHash64(toString(key)));
+CREATE TABLE posthog.usage_report_events_preagg (
+ date Date,
+ team_id Int64,
+ person_mode LowCardinality(String),
+ lib LowCardinality(String),
+ event String,
+ distinct_events_unique AggregateFunction(uniqExact, Tuple(UInt64, UInt64, UInt64)),
+ event_count AggregateFunction(sum, UInt64)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_usage_report_events_preagg', sipHash64(date));
+CREATE TABLE posthog.web_bot_definition (
+ id UInt64,
+ parent_id UInt64,
+ regexp String,
+ keys Array(String),
+ values Array(String)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_bot_definition', sipHash64(id));
+CREATE TABLE posthog.web_bounces_dimensional_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ period_bucket DateTime,
+ host String,
+ device_type String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ mat_metadata_loggedIn Nullable(Bool),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, Int64),
+ bounces_count_state AggregateFunction(sum, Int64),
+ total_session_duration_state AggregateFunction(sum, Int64),
+ total_session_count_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_bounces_dimensional_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_goals_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ action_id Int64,
+ count_state AggregateFunction(sum, Int64),
+ unique_persons_state AggregateFunction(uniq, UUID),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_goals_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_overview_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ uniq_users_state AggregateFunction(uniq, UUID),
+ uniq_sessions_state AggregateFunction(uniq, String),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ avg_duration_state AggregateFunction(avg, Float64),
+ avg_bounce_state AggregateFunction(avg, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_overview_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_pre_aggregated_bounces (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64),
+ bounces_count_state AggregateFunction(sum, UInt64),
+ total_session_duration_state AggregateFunction(sum, Int64),
+ total_session_count_state AggregateFunction(sum, UInt64),
+ mat_metadata_loggedIn Nullable(Bool)
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces', '{replica}-{shard}') ORDER BY (team_id, period_bucket, host, device_type, entry_pathname, end_pathname, browser, os, viewport_width, viewport_height, referring_domain, utm_source, utm_medium, utm_campaign, utm_term, utm_content, country_code, city_name, region_code, region_name, has_gclid, has_gad_source_paid_search, has_fbclid) PARTITION BY toYYYYMMDD(period_bucket) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.web_pre_aggregated_stats (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ pathname String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64),
+ mat_metadata_loggedIn Nullable(Bool)
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats', '{replica}-{shard}') ORDER BY (team_id, period_bucket, host, device_type, pathname, entry_pathname, end_pathname, browser, os, viewport_width, viewport_height, referring_domain, utm_source, utm_medium, utm_campaign, utm_term, utm_content, country_code, city_name, region_code, region_name, has_gclid, has_gad_source_paid_search, has_fbclid) PARTITION BY toYYYYMMDD(period_bucket) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.web_pre_aggregated_teams (
+ team_id UInt64,
+ enabled_by String DEFAULT 'system',
+ version UInt32 DEFAULT toUnixTimestamp(now())
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.web_analytics_team_selection', '{replica}-{shard}', version) ORDER BY (team_id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.web_stats_dimensional_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ period_bucket DateTime,
+ host String,
+ device_type String,
+ pathname String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ mat_metadata_loggedIn Nullable(Bool),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_dimensional_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_stats_frustration_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_value String,
+ sum_rage_clicks_state AggregateFunction(sum, Int64),
+ sum_dead_clicks_state AggregateFunction(sum, Int64),
+ sum_errors_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_frustration_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_stats_paths_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_value String,
+ uniq_users_state AggregateFunction(uniq, UUID),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ avg_bounce_state AggregateFunction(avg, Nullable(Float64)),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_paths_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_stats_paths_preaggregated_pathkey (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_value String,
+ uniq_users_state AggregateFunction(uniq, UUID),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ avg_bounce_state AggregateFunction(avg, Nullable(Float64)),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_paths_preaggregated_pathkey', sipHash64(breakdown_value));
+CREATE TABLE posthog.web_stats_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_by String,
+ breakdown_value String,
+ uniq_users_state AggregateFunction(uniq, UUID),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_vitals_paths_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ path String,
+ inp_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ lcp_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ cls_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ fcp_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_vitals_paths_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.writable_events (
+ uuid UUID,
+ event String,
+ properties String,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ elements_chain String,
+ created_at DateTime64(6, 'UTC'),
+ person_id UUID,
+ person_properties String,
+ group0_properties String,
+ group1_properties String,
+ group2_properties String,
+ group3_properties String,
+ group4_properties String,
+ _timestamp DateTime,
+ _offset UInt64,
+ person_created_at DateTime64(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),
+ consumer_breadcrumbs Array(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)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_events', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_events_dead_letter_queue (
+ id UUID,
+ event_uuid UUID,
+ event String,
+ properties String,
+ distinct_id String,
+ team_id Int64,
+ elements_chain String,
+ created_at DateTime64(6, 'UTC'),
+ ip String,
+ site_url String,
+ now DateTime64(6, 'UTC'),
+ raw_payload String,
+ error_timestamp DateTime64(6, 'UTC'),
+ error_location String,
+ error String,
+ tags Array(String),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog_single_shard', 'posthog', 'events_dead_letter_queue');
+CREATE TABLE posthog.writable_events_recent (
+ uuid UUID,
+ event String,
+ properties String,
+ 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,
+ group0_properties String,
+ group1_properties String,
+ group2_properties String,
+ group3_properties String,
+ group4_properties String,
+ 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),
+ _timestamp DateTime,
+ _offset UInt64,
+ inserted_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = Distributed('batch_exports_writable', 'posthog', 'sharded_events_recent', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_log_entries (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_log_entries', rand());
+CREATE TABLE posthog.writable_posthog_document_embeddings_buffer (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ model_name LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_buffer', cityHash64(document_id));
+CREATE TABLE posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_large_3072', cityHash64(document_id));
+CREATE TABLE posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_small_1536', cityHash64(document_id));
+CREATE TABLE posthog.writable_query_log_archive (
+ hostname LowCardinality(String),
+ user LowCardinality(String),
+ query_id String,
+ initial_query_id String,
+ is_initial_query UInt8,
+ type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4),
+ event_date Date,
+ event_time DateTime,
+ event_time_microseconds DateTime64(6),
+ query_start_time DateTime,
+ query_start_time_microseconds DateTime64(6),
+ query_duration_ms UInt64,
+ read_rows UInt64,
+ read_bytes UInt64,
+ written_rows UInt64,
+ written_bytes UInt64,
+ result_rows UInt64,
+ result_bytes UInt64,
+ memory_usage UInt64,
+ peak_threads_usage UInt64,
+ current_database LowCardinality(String),
+ query String,
+ formatted_query String,
+ normalized_query_hash UInt64,
+ query_kind LowCardinality(String),
+ exception_code Int32,
+ exception String,
+ stack_trace String,
+ team_id Int64,
+ log_comment JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email),
+ ProfileEvents Map(String, UInt64)
+) ENGINE = Distributed('ops', 'posthog', 'query_log_archive_buffer');
+CREATE TABLE posthog.writable_raw_sessions (
+ team_id Int64,
+ session_id_v7 UInt128,
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_browser AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_browser_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_device_type AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_viewport_width AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_viewport_height AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_geoip_country_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_city_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_time_zone AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_irclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ pageview_uniq AggregateFunction(uniq, Nullable(UUID)),
+ autocapture_count SimpleAggregateFunction(sum, Int64),
+ autocapture_uniq AggregateFunction(uniq, Nullable(UUID)),
+ screen_count SimpleAggregateFunction(sum, Int64),
+ screen_uniq AggregateFunction(uniq, Nullable(UUID)),
+ maybe_has_session_replay SimpleAggregateFunction(max, Bool),
+ page_screen_autocapture_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),
+ vitals_lcp AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC')),
+ initial__kx AggregateFunction(argMin, String, DateTime64(6, 'UTC'))
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_raw_sessions', cityHash64(session_id_v7));
+CREATE TABLE posthog.writable_raw_sessions_v3 (
+ team_id Int64,
+ session_id_v7 UInt128,
+ session_timestamp DateTime64(3) MATERIALIZED fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80))),
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ distinct_ids AggregateFunction(groupUniqArray, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),
+ entry_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ browser AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ browser_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ device_type AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ viewport_width AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ viewport_height AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ geoip_country_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_city_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_time_zone AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_referring_domain AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_campaign AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_medium AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_term AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_content AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gad_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_fbclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_has_gclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_has_fbclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_ad_ids_map AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC')),
+ entry_ad_ids_set AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC')),
+ entry_channel_type_properties AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC')),
+ pageview_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ autocapture_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ 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_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ event_names SimpleAggregateFunction(groupUniqArrayArray, 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 (
+ uuid UUID,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ session_id String,
+ window_id String,
+ snapshot_data String,
+ created_at DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_recording_events', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_session_replay_embeddings (
+ session_id String,
+ team_id Int64,
+ embeddings Array(Float32),
+ generation_timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ source_type LowCardinality(String),
+ input String
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_embeddings', sipHash64(session_id));
+CREATE TABLE posthog.writable_session_replay_events (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
+ first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ active_milliseconds SimpleAggregateFunction(sum, Int64),
+ console_log_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ size SimpleAggregateFunction(sum, Int64),
+ message_count SimpleAggregateFunction(sum, Int64),
+ event_count SimpleAggregateFunction(sum, Int64),
+ snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
+ snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ _timestamp SimpleAggregateFunction(max, DateTime),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_sessions (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_sessions', sipHash64(session_id));
+CREATE TABLE posthog.writeable_performance_events (
+ uuid UUID,
+ session_id String,
+ window_id String,
+ pageview_id String,
+ distinct_id String,
+ timestamp DateTime64(3),
+ time_origin DateTime64(3, 'UTC'),
+ entry_type LowCardinality(String),
+ name String,
+ team_id Int64,
+ current_url String,
+ start_time Float64,
+ duration Float64,
+ redirect_start Float64,
+ redirect_end Float64,
+ worker_start Float64,
+ fetch_start Float64,
+ domain_lookup_start Float64,
+ domain_lookup_end Float64,
+ connect_start Float64,
+ secure_connection_start Float64,
+ connect_end Float64,
+ request_start Float64,
+ response_start Float64,
+ response_end Float64,
+ decoded_body_size Int64,
+ encoded_body_size Int64,
+ initiator_type LowCardinality(String),
+ next_hop_protocol LowCardinality(String),
+ render_blocking_status LowCardinality(String),
+ response_status Int64,
+ transfer_size Int64,
+ largest_contentful_paint_element String,
+ largest_contentful_paint_render_time Float64,
+ largest_contentful_paint_load_time Float64,
+ largest_contentful_paint_size Float64,
+ largest_contentful_paint_id String,
+ largest_contentful_paint_url String,
+ dom_complete Float64,
+ dom_content_loaded_event Float64,
+ dom_interactive Float64,
+ load_event_end Float64,
+ load_event_start Float64,
+ redirect_count Int64,
+ navigation_type LowCardinality(String),
+ unload_event_end Float64,
+ unload_event_start Float64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_performance_events', sipHash64(session_id));
+CREATE MATERIALIZED VIEW posthog.ops_query_log_archive_mv TO posthog.writable_query_log_archive (hostname LowCardinality(String), user LowCardinality(String), query_id String, initial_query_id String, is_initial_query UInt8, type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4), event_date Date, event_time DateTime, event_time_microseconds DateTime64(6), query_start_time DateTime, query_start_time_microseconds DateTime64(6), query_duration_ms UInt64, read_rows UInt64, read_bytes UInt64, written_rows UInt64, written_bytes UInt64, result_rows UInt64, result_bytes UInt64, memory_usage UInt64, peak_threads_usage UInt64, current_database LowCardinality(String), query String, formatted_query String, normalized_query_hash UInt64, query_kind LowCardinality(String), exception_code Int32, exception String, stack_trace String, team_id Int64, log_comment String, ProfileEvents Map(LowCardinality(String), UInt64)) AS SELECT
+ hostname,
+ user,
+ query_id,
+ initial_query_id,
+ is_initial_query,
+ type,
+ event_date,
+ event_time,
+ event_time_microseconds,
+ query_start_time,
+ query_start_time_microseconds,
+ query_duration_ms,
+ read_rows,
+ read_bytes,
+ written_rows,
+ written_bytes,
+ result_rows,
+ result_bytes,
+ memory_usage,
+ peak_threads_usage,
+ current_database,
+ query,
+ formatted_query,
+ normalized_query_hash,
+ query_kind,
+ exception_code,
+ exception,
+ stack_trace,
+ JSONExtractInt(log_comment, 'team_id') AS team_id,
+ if(isValidJSON(log_comment), log_comment, '{}') AS log_comment,
+ ProfileEvents
+FROM system.query_log
+WHERE type != 'QueryStart';
+CREATE MATERIALIZED VIEW posthog.posthog_document_embeddings_text_embedding_3_large_3072_mv TO posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072 (team_id Int64, product LowCardinality(String), document_type LowCardinality(String), rendering LowCardinality(String), document_id String, timestamp DateTime64(3, 'UTC'), inserted_at DateTime64(3, 'UTC'), content String, metadata String, embedding Array(Float64), _timestamp DateTime, _offset UInt64, _partition UInt64) AS SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-large-3072';
+CREATE MATERIALIZED VIEW posthog.posthog_document_embeddings_text_embedding_3_small_1536_mv TO posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536 (team_id Int64, product LowCardinality(String), document_type LowCardinality(String), rendering LowCardinality(String), document_id String, timestamp DateTime64(3, 'UTC'), inserted_at DateTime64(3, 'UTC'), content String, metadata String, embedding Array(Float64), _timestamp DateTime, _offset UInt64, _partition UInt64) AS SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-small-1536';
+CREATE VIEW posthog.custom_metrics_backups AS WITH
+ ['ClickHouseCustomMetric_BackupFailed', 'ClickHouseCustomMetric_BackupSuccess', 'ClickHouseCustomMetric_BackupCancelled', 'ClickHouseCustomMetric_BackupAttempts'] AS names,
+ [toInt64(countIf(status = 'BACKUP_FAILED')), toInt64(countIf(status = 'BACKUP_CREATED')), toInt64(countIf(status = 'BACKUP_CANCELLED')), toInt64(countIf(status = 'CREATING_BACKUP'))] AS `values`,
+ ['Number of failed backups', 'Number of successful backups', 'Number of cancelled backups', 'Number of backup attempts'] AS descriptions,
+ ['gauge', 'gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.backup_log
+WHERE event_date = today()
+GROUP BY
+ event_date;
+CREATE VIEW posthog.custom_metrics_dictionaries AS SELECT
+ 'ClickHouseCustomMetric_DictionariesFailed' AS name,
+ map(
+ 'instance',
+ hostname(),
+ 'database',
+ d.database,
+ 'dictionary',
+ d.dict_name,
+ 'uuid',
+ toString(d.uuid),
+ 'status',
+ toString(d.status)
+ ) AS labels,
+ toUInt64(1) AS value,
+ 'Dictionary is in FAILED or FAILED_AND_RELOADING status' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT name AS dict_name, database, uuid, status
+ FROM system.dictionaries
+ WHERE status IN ('FAILED', 'FAILED_AND_RELOADING')
+ ) AS d;
+CREATE VIEW posthog.custom_metrics_part_counts AS SELECT
+ 'ClickHouseCustomMetric_MaxPartCountPerPartition' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`, 'partition', partition) AS labels,
+ part_count AS value,
+ 'Maximum number of active parts for any partition in a PostHog table' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT database, `table`, partition, count() AS part_count
+ FROM system.parts
+ WHERE
+ active
+ AND
+ (database = 'posthog')
+ GROUP BY
+ database, `table`, partition
+ ORDER BY database ASC, `table` ASC, part_count DESC, partition ASC
+ LIMIT 1 BY database, `table`
+ );
+CREATE VIEW posthog.custom_metrics_replication_queue AS WITH
+ ['ClickHouseCustomMetric_ReplicationQueueStuckEntries', 'ClickHouseCustomMetric_ReplicationQueueMaxPostponedEntrySeconds', 'ClickHouseCustomMetric_ReplicationQueueMaxErrorEntrySeconds'] AS names,
+ [toInt64(countIf(create_time < (now() - toIntervalDay(15)))), maxIf(dateDiff('seconds', create_time, last_postpone_time), last_postpone_time != '1970-01-01'), maxIf(dateDiff('seconds', create_time, last_exception_time), (last_exception_time != '1970-01-01') AND (last_exception_time > (now() - toIntervalMinute(5))))] AS `values`,
+ ['Number of entries that have been in the replication queue for more than 15 days', 'Maximum number of seconds that an entry has been postponed', 'Maximum number of seconds that an entry has been in error'] AS descriptions,
+ ['gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('table', `table`, 'instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.replication_queue
+GROUP BY
+ `table`
+HAVING
+ value > 0;
+CREATE VIEW posthog.custom_metrics_server_crash AS SELECT
+ 'ClickHouseCustomMetric_ServerCrash' AS name,
+ map('instance', hostname()) AS labels,
+ count() AS value,
+ 'Number of server crashes for current date' AS help,
+ 'gauge' AS type
+FROM system.crash_log
+WHERE event_date = today()
+GROUP BY
+ hostname();
+CREATE VIEW posthog.custom_metrics_table_sizes AS SELECT
+ 'ClickHouseCustomMetric_TableTotalBytes' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`) AS labels,
+ CAST(total_bytes, 'Float64') AS value,
+ 'Size of a database table on a given node (need a sum for sharded)' AS help,
+ 'gauge' AS type
+FROM system.tables
+WHERE
+ (database NOT IN ('INFORMATION_SCHEMA', 'information_schema'))
+AND
+ (total_bytes IS NOT NULL);
+CREATE VIEW posthog.custom_metrics_test AS SELECT
+ 'ClickHouseCustomMetric_Test' AS name,
+ map('instance', hostname()) AS labels,
+ 1 AS value,
+ 'Test to check that the metric endpoint is working' AS help,
+ 'gauge' AS type;
+CREATE VIEW posthog.events_batch_export_recent AS SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ inserted_at AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events_recent
+PREWHERE
+ (events_recent.inserted_at >= {interval_start: DateTime64}) AND (events_recent.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events_recent.distinct_id), cityHash64(events_recent.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1;
+CREATE VIEW posthog.persons_batch_export AS WITH
+ new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
+ new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
+ all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
+SELECT
+ p.team_id AS team_id,
+ pd.distinct_id AS distinct_id,
+ toString(p.id) AS person_id,
+ p.properties AS properties,
+ pd.version AS person_distinct_id_version,
+ p.version AS person_version,
+ p.created_at AS created_at,
+ multiIf(
+ ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
+ pd._timestamp,
+ ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
+ p._timestamp,
+ least(p._timestamp, pd._timestamp)
+ ) AS _inserted_at
+FROM
+ posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((id, version) IN (all_new_persons))
+ORDER BY _inserted_at ASC;
+CREATE OR REPLACE DICTIONARY posthog.channel_definition_dict (`domain` String, `kind` String, `domain_type` Nullable(String), `type_if_paid` Nullable(String), `type_if_organic` Nullable(String)) PRIMARY KEY domain, kind SOURCE(CLICKHOUSE(USER 'dict_reader' TABLE 'channel_definition')) LAYOUT(COMPLEX_KEY_HASHED()) LIFETIME(MIN 3000 MAX 3600);
+CREATE OR REPLACE DICTIONARY posthog.web_bot_definition_dict (`regexp` String, `name` String, `category` String, `traffic_type` String, `operator` String) PRIMARY KEY regexp SOURCE(CLICKHOUSE(USER 'default' DB 'posthog' TABLE 'web_bot_definition')) LAYOUT(REGEXP_TREE()) LIFETIME(MIN 3000 MAX 3600);
+CREATE OR REPLACE DICTIONARY posthog.web_pre_aggregated_teams_dict (`team_id` UInt64) PRIMARY KEY team_id SOURCE(CLICKHOUSE(USER 'dict_reader' QUERY 'SELECT team_id FROM `web_pre_aggregated_teams` FINAL WHERE version > 0')) LAYOUT(HASHED()) LIFETIME(MIN 3000 MAX 3600);
+CREATE TABLE posthog.app_metrics (
+ team_id Int64,
+ timestamp DateTime64(6, 'UTC'),
+ plugin_config_id Int64,
+ category LowCardinality(String),
+ job_id String,
+ successes SimpleAggregateFunction(sum, Int64),
+ successes_on_retry SimpleAggregateFunction(sum, Int64),
+ failures SimpleAggregateFunction(sum, Int64),
+ error_uuid UUID,
+ error_type String,
+ error_details String CODEC(ZSTD(3)),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_app_metrics', rand());
+CREATE TABLE posthog.app_metrics2 (
+ team_id Int64,
+ timestamp DateTime64(6, 'UTC'),
+ app_source LowCardinality(String),
+ app_source_id String,
+ instance_id String,
+ metric_kind LowCardinality(String),
+ metric_name LowCardinality(String),
+ count SimpleAggregateFunction(sum, Int64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_app_metrics2', rand());
+CREATE TABLE posthog.billing_usage_records (
+ schema_version UInt8,
+ record_id String,
+ producer_id LowCardinality(String),
+ team_id Int64,
+ organization_id UUID,
+ usage_key LowCardinality(String),
+ unit LowCardinality(String),
+ quantity Int64,
+ timestamp DateTime64(6, 'UTC'),
+ inserted_at DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_billing_usage_records', cityHash64(team_id));
+CREATE TABLE posthog.distinct_id_usage (
+ team_id Int64,
+ distinct_id String,
+ minute DateTime,
+ event_count UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_distinct_id_usage', sipHash64(distinct_id));
+CREATE TABLE posthog.distributed_posthog_document_embeddings_text_embedding_3_large_3072 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_large_3072', cityHash64(document_id));
+CREATE TABLE posthog.distributed_posthog_document_embeddings_text_embedding_3_small_1536 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_small_1536', cityHash64(document_id));
+CREATE TABLE posthog.events (
+ uuid UUID,
+ event String,
+ properties String,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ elements_chain String,
+ created_at DateTime64(6, 'UTC'),
+ person_id UUID,
+ person_properties String,
+ group0_properties String,
+ group1_properties String,
+ group2_properties String,
+ group3_properties String,
+ group4_properties 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',
+ $group_3 String COMMENT 'column_materializer::$group_3',
+ $group_4 String COMMENT 'column_materializer::$group_4',
+ $window_id String COMMENT 'column_materializer::$window_id',
+ $session_id String COMMENT 'column_materializer::$session_id',
+ _timestamp DateTime,
+ _offset UInt64,
+ person_created_at DateTime64(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),
+ 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_feature_flags Map(String, String),
+ is_deleted Bool,
+ person_properties_map_custom Map(String, String),
+ $session_id_uuid Nullable(UInt128),
+ consumer_breadcrumbs Array(String),
+ properties_group_ai Map(String, String),
+ mat_$ai_trace_id Nullable(String) COMMENT 'column_materializer::properties::$ai_trace_id',
+ mat_historical_migration Nullable(String) COMMENT 'column_materializer::properties::historical_migration',
+ 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'
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_events', sipHash64(distinct_id));
+CREATE TABLE posthog.experiment_exposures_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ entity_id String,
+ variant String,
+ first_exposure_time DateTime64(6, 'UTC'),
+ last_exposure_time DateTime64(6, 'UTC'),
+ exposure_event_uuid UUID,
+ exposure_session_id String,
+ breakdown_value Array(String),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_experiment_exposures_preaggregated', cityHash64(entity_id));
+CREATE TABLE posthog.flag_evaluations (
+ uuid UUID,
+ event LowCardinality(String),
+ properties String,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ created_at DateTime64(6, 'UTC'),
+ person_id UUID,
+ person_properties String,
+ group0_properties String,
+ group1_properties String,
+ group2_properties String,
+ group3_properties String,
+ group4_properties String,
+ inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,
+ $group_0 String COMMENT 'column_materializer::$group_0',
+ $group_1 String COMMENT 'column_materializer::$group_1',
+ $group_2 String COMMENT 'column_materializer::$group_2',
+ $group_3 String COMMENT 'column_materializer::$group_3',
+ $group_4 String COMMENT 'column_materializer::$group_4',
+ flag_key String COMMENT 'column_materializer::properties::$feature_flag',
+ response LowCardinality(String) COMMENT 'column_materializer::properties::$feature_flag_response',
+ session_id String COMMENT 'column_materializer::properties::$session_id',
+ request_id String COMMENT 'column_materializer::properties::$feature_flag_request_id',
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_flag_evaluations', sipHash64(distinct_id));
+CREATE TABLE posthog.heatmaps (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ timestamp DateTime64(6, 'UTC'),
+ x Int16,
+ y Int16,
+ scale_factor Int16,
+ viewport_width Int16,
+ viewport_height Int16,
+ pointer_target_fixed Bool,
+ current_url String,
+ type LowCardinality(String),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_heatmaps', cityHash64(concat(toString(team_id), '-', session_id, '-', toString(toDate(timestamp)))));
+CREATE TABLE posthog.log_entries (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_log_entries', rand());
+CREATE TABLE posthog.performance_events (
+ uuid UUID,
+ session_id String,
+ window_id String,
+ pageview_id String,
+ distinct_id String,
+ timestamp DateTime64(3),
+ time_origin DateTime64(3, 'UTC'),
+ entry_type LowCardinality(String),
+ name String,
+ team_id Int64,
+ current_url String,
+ start_time Float64,
+ duration Float64,
+ redirect_start Float64,
+ redirect_end Float64,
+ worker_start Float64,
+ fetch_start Float64,
+ domain_lookup_start Float64,
+ domain_lookup_end Float64,
+ connect_start Float64,
+ secure_connection_start Float64,
+ connect_end Float64,
+ request_start Float64,
+ response_start Float64,
+ response_end Float64,
+ decoded_body_size Int64,
+ encoded_body_size Int64,
+ initiator_type LowCardinality(String),
+ next_hop_protocol LowCardinality(String),
+ render_blocking_status LowCardinality(String),
+ response_status Int64,
+ transfer_size Int64,
+ largest_contentful_paint_element String,
+ largest_contentful_paint_render_time Float64,
+ largest_contentful_paint_load_time Float64,
+ largest_contentful_paint_size Float64,
+ largest_contentful_paint_id String,
+ largest_contentful_paint_url String,
+ dom_complete Float64,
+ dom_content_loaded_event Float64,
+ dom_interactive Float64,
+ load_event_end Float64,
+ load_event_start Float64,
+ redirect_count Int64,
+ navigation_type LowCardinality(String),
+ unload_event_end Float64,
+ unload_event_start Float64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_performance_events', sipHash64(session_id));
+CREATE TABLE posthog.preaggregation_results (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7),
+ breakdown_value Array(String),
+ uniq_exact_state AggregateFunction(uniqExact, UUID)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_preaggregation_results', sipHash64(job_id));
+CREATE TABLE posthog.precalculated_events (
+ team_id Int64,
+ date Date,
+ distinct_id String,
+ person_id UUID,
+ condition String,
+ uuid UUID,
+ source String,
+ _timestamp DateTime64(6),
+ _partition UInt64,
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_precalculated_events', sipHash64(distinct_id));
+CREATE TABLE posthog.precalculated_person_properties (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ condition String,
+ matches Bool,
+ source String,
+ _timestamp DateTime64(6),
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_precalculated_person_properties', sipHash64(distinct_id));
+CREATE TABLE posthog.raw_sessions (
+ team_id Int64,
+ session_id_v7 UInt128,
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_browser AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_browser_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_device_type AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_viewport_width AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_viewport_height AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_geoip_country_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_city_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_time_zone AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial__kx AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_irclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ pageview_uniq AggregateFunction(uniq, Nullable(UUID)),
+ autocapture_count SimpleAggregateFunction(sum, Int64),
+ autocapture_uniq AggregateFunction(uniq, Nullable(UUID)),
+ screen_count SimpleAggregateFunction(sum, Int64),
+ screen_uniq AggregateFunction(uniq, Nullable(UUID)),
+ maybe_has_session_replay SimpleAggregateFunction(max, Bool),
+ page_screen_autocapture_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),
+ vitals_lcp AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_raw_sessions', cityHash64(session_id_v7));
+CREATE TABLE posthog.raw_sessions_v3 (
+ team_id Int64,
+ session_id_v7 UInt128,
+ session_timestamp DateTime64(3) MATERIALIZED fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80))),
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ distinct_ids AggregateFunction(groupUniqArray, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),
+ entry_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ browser AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ browser_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ device_type AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ viewport_width AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ viewport_height AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ geoip_country_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_city_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_time_zone AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_referring_domain AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_campaign AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_medium AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_term AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_content AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gad_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_fbclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_has_gclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_has_fbclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_ad_ids_map AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC')),
+ entry_ad_ids_set AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC')),
+ entry_channel_type_properties AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC')),
+ pageview_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ autocapture_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ 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_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ event_names SimpleAggregateFunction(groupUniqArrayArray, 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 (
+ uuid UUID,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ session_id String,
+ window_id String,
+ snapshot_data String,
+ created_at DateTime64(6, 'UTC'),
+ has_full_snapshot Int8 COMMENT 'column_materializer::has_full_snapshot',
+ _timestamp DateTime,
+ _offset UInt64,
+ events_summary Array(String) COMMENT 'column_materializer::events_summary',
+ click_count Int8 COMMENT 'column_materializer::click_count',
+ keypress_count Int8 COMMENT 'column_materializer::keypress_count',
+ timestamps_summary Array(DateTime64(6, 'UTC')) COMMENT 'column_materializer::timestamps_summary',
+ first_event_timestamp DateTime64(6, 'UTC') COMMENT 'column_materializer::first_event_timestamp',
+ last_event_timestamp DateTime64(6, 'UTC') COMMENT 'column_materializer::last_event_timestamp',
+ urls Array(String) COMMENT 'column_materializer::urls'
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_recording_events', sipHash64(distinct_id));
+CREATE TABLE posthog.session_replay_embeddings (
+ session_id String,
+ team_id Int64,
+ embeddings Array(Float32),
+ generation_timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ source_type LowCardinality(String),
+ input String
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_embeddings', sipHash64(session_id));
+CREATE TABLE posthog.session_replay_events (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ active_milliseconds SimpleAggregateFunction(sum, Int64),
+ console_log_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ size SimpleAggregateFunction(sum, Int64),
+ message_count SimpleAggregateFunction(sum, Int64),
+ event_count SimpleAggregateFunction(sum, Int64),
+ _timestamp SimpleAggregateFunction(max, DateTime),
+ snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
+CREATE TABLE posthog.sessions (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_sessions', sipHash64(session_id));
+CREATE VIEW posthog.custom_metrics AS SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_test
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_replication_queue
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_server_crash
+UNION ALL
+SELECT *
+FROM posthog.custom_metrics_table_sizes
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_part_counts
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_dictionaries
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_S3DiskBytesUsed' AS name,
+ map('instance', hostname(), 'disk', disk_name) AS labels,
+ toFloat64(sum(bytes_on_disk)) AS value,
+ 'Bytes currently used by ClickHouse parts on S3-backed disks on this node' AS help,
+ 'gauge' AS type
+FROM system.parts
+WHERE disk_name IN ('s3disk', 'cache')
+GROUP BY
+ disk_name
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeFailures15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(count()) AS value,
+ 'Number of failed merge operations in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM system.part_log
+WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+AND
+ (event_type = 'MergeParts')
+AND
+ (error > 0)
+AND
+ (merge_reason != 'NotAMerge')
+AND
+ (error != 40)
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeRetriesMaxPerTable15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(max(cnt)) AS value,
+ 'Max failed merge retries for any single table in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT count() AS cnt
+ FROM system.part_log
+ WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+ AND
+ (event_type = 'MergeParts')
+ AND
+ (error > 0)
+ AND
+ (merge_reason != 'NotAMerge')
+ AND
+ (error != 40)
+ GROUP BY
+ database, `table`, partition_id
+ );
+CREATE VIEW posthog.events_batch_export AS SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (events.inserted_at >= {interval_start: DateTime64}) AND (events.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ (events.timestamp >= ({interval_start: DateTime64} - toIntervalDay({lookback_days: Int32})))
+AND
+ (events.timestamp < ({interval_end: DateTime64} + toIntervalDay(1)))
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1;
+CREATE VIEW posthog.events_batch_export_unbounded AS SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (events.inserted_at >= {interval_start: DateTime64}) AND (events.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1;
+CREATE VIEW posthog.posthog_document_embeddings_union_view AS SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-small-1536' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_small_1536
+UNION ALL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-large-3072' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_large_3072;
+CREATE VIEW posthog.raw_sessions_v AS SELECT
+ session_id_v7,
+ fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)) AS session_timestamp,
+ team_id,
+ argMaxMerge(distinct_id) AS distinct_id,
+ 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(initial_browser) AS initial_browser,
+ argMinMerge(initial_browser_version) AS initial_browser_version,
+ argMinMerge(initial_os) AS initial_os,
+ argMinMerge(initial_os_version) AS initial_os_version,
+ argMinMerge(initial_device_type) AS initial_device_type,
+ argMinMerge(initial_viewport_width) AS initial_viewport_width,
+ argMinMerge(initial_viewport_height) AS initial_viewport_height,
+ argMinMerge(initial_geoip_country_code) AS initial_geoip_country_code,
+ argMinMerge(initial_geoip_subdivision_1_code) AS initial_geoip_subdivision_1_code,
+ argMinMerge(initial_geoip_subdivision_1_name) AS initial_geoip_subdivision_1_name,
+ argMinMerge(initial_geoip_subdivision_city_name) AS initial_geoip_subdivision_city_name,
+ argMinMerge(initial_geoip_time_zone) AS initial_geoip_time_zone,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ argMinMerge(initial__kx) AS initial__kx,
+ argMinMerge(initial_irclid) AS initial_irclid,
+ sum(pageview_count) AS pageview_count,
+ uniqMerge(pageview_uniq) AS pageview_uniq,
+ sum(autocapture_count) AS autocapture_count,
+ uniqMerge(autocapture_uniq) AS autocapture_uniq,
+ sum(screen_count) AS screen_count,
+ uniqMerge(screen_uniq) AS screen_uniq,
+ max(maybe_has_session_replay) AS maybe_has_session_replay,
+ uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,
+ argMinMerge(vitals_lcp) AS vitals_lcp
+FROM posthog.raw_sessions
+GROUP BY
+ session_id_v7, team_id;
+CREATE VIEW posthog.raw_sessions_v3_v AS 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;
+CREATE VIEW posthog.sessions_v AS SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(exit_url) AS exit_url,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ sumMap(event_count_map) AS event_count_map,
+ sum(pageview_count) AS pageview_count,
+ sum(autocapture_count) AS autocapture_count
+FROM posthog.sessions
+GROUP BY
+ session_id, team_id;
diff --git a/posthog/clickhouse/hcl/sql/prod-eu/data.sql b/posthog/clickhouse/hcl/sql/prod-eu/data.sql
new file mode 100644
index 000000000000..e9c63b4547de
--- /dev/null
+++ b/posthog/clickhouse/hcl/sql/prod-eu/data.sql
@@ -0,0 +1,3256 @@
+-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit.
+-- Full CREATE schema for the prod-eu/data node. Apply to a fresh ClickHouse to build it.
+
+CREATE TABLE posthog.adhoc_events_deletion (
+ team_id Int64,
+ uuid UUID,
+ created_at DateTime64(6, 'UTC') DEFAULT now64(),
+ deleted_at DateTime,
+ is_deleted UInt8 DEFAULT 0
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.adhoc_events_deletion', '{replica}-{shard}', deleted_at, is_deleted) ORDER BY (team_id, uuid) TTL deleted_at + toIntervalMonth(3) WHERE is_deleted = 1 SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.ai_events (
+ uuid UUID,
+ event LowCardinality(String),
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ properties String,
+ retention_days Int16 DEFAULT 30,
+ drop_date Date MATERIALIZED toDate(timestamp) + toIntervalDay(retention_days),
+ trace_id String,
+ session_id Nullable(String),
+ parent_id Nullable(String),
+ span_id Nullable(String),
+ span_type LowCardinality(Nullable(String)),
+ generation_id Nullable(String),
+ experiment_id Nullable(String),
+ span_name Nullable(String),
+ trace_name Nullable(String),
+ prompt_name Nullable(String),
+ model LowCardinality(Nullable(String)),
+ provider LowCardinality(Nullable(String)),
+ framework LowCardinality(Nullable(String)),
+ total_tokens Nullable(Int64),
+ input_tokens Nullable(Int64),
+ output_tokens Nullable(Int64),
+ text_input_tokens Nullable(Int64),
+ text_output_tokens Nullable(Int64),
+ image_input_tokens Nullable(Int64),
+ image_output_tokens Nullable(Int64),
+ audio_input_tokens Nullable(Int64),
+ audio_output_tokens Nullable(Int64),
+ video_input_tokens Nullable(Int64),
+ video_output_tokens Nullable(Int64),
+ reasoning_tokens Nullable(Int64),
+ cache_read_input_tokens Nullable(Int64),
+ cache_creation_input_tokens Nullable(Int64),
+ web_search_count Nullable(Int64),
+ input_cost_usd Nullable(Float64),
+ output_cost_usd Nullable(Float64),
+ total_cost_usd Nullable(Float64),
+ request_cost_usd Nullable(Float64),
+ web_search_cost_usd Nullable(Float64),
+ audio_cost_usd Nullable(Float64),
+ image_cost_usd Nullable(Float64),
+ video_cost_usd Nullable(Float64),
+ latency Nullable(Float64),
+ time_to_first_token Nullable(Float64),
+ is_error UInt8,
+ error Nullable(String),
+ error_type LowCardinality(Nullable(String)),
+ error_normalized Nullable(String),
+ input Nullable(String),
+ output Nullable(String),
+ output_choices Nullable(String),
+ input_state Nullable(String),
+ output_state Nullable(String),
+ tools Nullable(String),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('ai_events', 'posthog', 'ai_events', rand());
+CREATE TABLE posthog.async_deletion_run (
+ id UInt64,
+ deletion_type UInt8,
+ key String,
+ group_type_index String,
+ team_id Int64
+) ENGINE = Join(ANY, LEFT, team_id, deletion_type, key);
+CREATE TABLE posthog.asyncdeletion (
+ id UInt64,
+ deletion_type UInt8,
+ key String,
+ group_type_index UInt64,
+ created_at DateTime,
+ delete_verified_at DateTime,
+ created_by_id UInt64,
+ team_id UInt64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/asyncdeletion', '{replica}-{shard}') ORDER BY (deletion_type, delete_verified_at) PARTITION BY toYYYYMM(created_at) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.billing_usage_records (
+ schema_version UInt8,
+ record_id String,
+ producer_id LowCardinality(String),
+ team_id Int64,
+ organization_id UUID,
+ usage_key LowCardinality(String),
+ unit LowCardinality(String),
+ quantity Int64,
+ timestamp DateTime64(6, 'UTC'),
+ inserted_at DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'sharded_billing_usage_records', cityHash64(team_id));
+CREATE TABLE posthog.channel_definition (
+ domain String,
+ kind String,
+ domain_type Nullable(String),
+ type_if_paid Nullable(String),
+ type_if_organic Nullable(String)
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.channel_definition', '{replica}-{shard}') ORDER BY (domain, kind) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.clickhouse_cleanup_deleted_persons (
+ run_id String,
+ team_id Int64,
+ person_id UUID,
+ max_version UInt64,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, person_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.clickhouse_cleanup_orphaned_distinct_ids (
+ run_id String,
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ own_tombstone UInt8,
+ max_version Int64,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, distinct_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.clickhouse_cleanup_revived_distinct_ids (
+ run_id String,
+ team_id Int64,
+ distinct_id String,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, distinct_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.clickhouse_cleanup_revived_persons (
+ run_id String,
+ team_id Int64,
+ person_id UUID,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, person_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.cohort_membership (
+ team_id Int64,
+ cohort_id Int64,
+ person_id UUID,
+ status Enum8('entered'=1, 'left'=2),
+ last_updated DateTime64(6) DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.cohort_membership', '{replica}-{shard}', last_updated) ORDER BY (team_id, cohort_id, person_id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.cohortpeople (
+ person_id UUID,
+ cohort_id Int64,
+ team_id Int64,
+ sign Int8,
+ version UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.cohortpeople_new_partitioned', '{replica}-{shard}', version) ORDER BY (team_id, cohort_id, person_id) PARTITION BY team_id % 16 SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.conversion_goal_attributed_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ person_id UUID,
+ conversion_timestamp DateTime64(6, 'UTC'),
+ conversion_value Float64,
+ touchpoint_timestamp DateTime64(6, 'UTC'),
+ touchpoint_weight Float64,
+ campaign_name String,
+ source_name String,
+ medium_name String,
+ content_name String,
+ term_name String,
+ referring_domain_name String,
+ gclid_name String,
+ fbclid_name String,
+ gad_source_name String,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_conversion_goal_attributed_preaggregated', cityHash64(person_id));
+CREATE TABLE posthog.distributed_events_recent (
+ uuid UUID,
+ event String,
+ properties String CODEC(ZSTD(3)),
+ 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),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ inserted_at DateTime64(6, 'UTC') DEFAULT now64(),
+ _timestamp_ms DateTime64(3)
+) ENGINE = Distributed('batch_exports', 'posthog', 'sharded_events_recent', sipHash64(distinct_id));
+CREATE TABLE posthog.distributed_posthog_document_embeddings (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ model_name LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings', cityHash64(document_id));
+CREATE TABLE posthog.distributed_system_processes (
+ is_initial_query UInt8,
+ user String,
+ query_id String,
+ address IPv6,
+ port UInt16,
+ initial_user String,
+ initial_query_id String,
+ initial_address IPv6,
+ initial_port UInt16,
+ interface UInt8,
+ os_user String,
+ client_hostname String,
+ client_name String,
+ client_revision UInt64,
+ client_version_major UInt64,
+ client_version_minor UInt64,
+ client_version_patch UInt64,
+ http_method UInt8,
+ http_user_agent String,
+ http_referer String,
+ forwarded_for String,
+ quota_key String,
+ distributed_depth UInt64,
+ elapsed Float64,
+ is_cancelled UInt8,
+ is_all_data_sent UInt8,
+ read_rows UInt64,
+ read_bytes UInt64,
+ total_rows_approx UInt64,
+ written_rows UInt64,
+ written_bytes UInt64,
+ memory_usage Int64,
+ peak_memory_usage Int64,
+ query String,
+ query_kind String,
+ thread_ids Array(UInt64),
+ ProfileEvents Map(String, UInt64),
+ Settings Map(String, String),
+ current_database String,
+ ProfileEvents.Names Array(String) ALIAS mapKeys(ProfileEvents),
+ ProfileEvents.Values Array(UInt64) ALIAS mapValues(ProfileEvents),
+ Settings.Names Array(String) ALIAS mapKeys(Settings),
+ Settings.Values Array(String) ALIAS mapValues(Settings)
+) ENGINE = Distributed('posthog', 'system', 'processes') SETTINGS skip_unavailable_shards = 1;
+CREATE TABLE posthog.duplicate_events (
+ team_id Int64,
+ distinct_id String,
+ event String,
+ source_uuid UUID,
+ duplicate_uuid UUID,
+ similarity_score Float64,
+ dedup_type LowCardinality(String),
+ is_confirmed UInt8,
+ reason Nullable(String),
+ version String,
+ different_property_count UInt32,
+ properties_similarity Float64,
+ source_message String,
+ duplicate_message String,
+ distinct_fields Array(Tuple(field_name String, original_value String, new_value String)),
+ inserted_at DateTime64(3, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX kafka_timestamp_minmax_duplicate_events _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.duplicate_events', '{replica}-{shard}') ORDER BY (team_id, distinct_id, event, inserted_at) PARTITION BY toYYYYMMDD(inserted_at) TTL inserted_at + toIntervalDay(7) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.error_tracking_fingerprint_issue_state (
+ team_id Int64,
+ fingerprint String,
+ issue_id UUID,
+ issue_name Nullable(String),
+ issue_description Nullable(String),
+ issue_status String,
+ issue_severity Nullable(String),
+ assigned_user_id Nullable(Int64),
+ assigned_role_id Nullable(UUID),
+ first_seen DateTime64(3, 'UTC'),
+ is_deleted Int8,
+ version Int64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'raw_error_tracking_fingerprint_issue_state');
+CREATE TABLE posthog.error_tracking_issue_fingerprint_overrides (
+ team_id Int64,
+ fingerprint String,
+ issue_id UUID,
+ is_deleted Int8,
+ version Int64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX kafka_timestamp_minmax_error_tracking_issue_fingerprint_overrides _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.error_tracking_issue_fingerprint_overrides', '{replica}-{shard}', version) ORDER BY (team_id, fingerprint) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.events_dead_letter_queue (
+ id UUID,
+ event_uuid UUID,
+ event String,
+ properties String,
+ distinct_id String,
+ team_id Int64,
+ elements_chain String,
+ created_at DateTime64(6, 'UTC'),
+ ip String,
+ site_url String,
+ now DateTime64(6, 'UTC'),
+ raw_payload String,
+ error_timestamp DateTime64(6, 'UTC'),
+ error_location String,
+ error String,
+ tags Array(String),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.events_dead_letter_queue', '{replica}-{shard}', _timestamp) ORDER BY (id, event_uuid, distinct_id, team_id) TTL toDate(_timestamp) + toIntervalWeek(4) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.events_recent (
+ uuid UUID,
+ event String,
+ properties String,
+ 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,
+ group0_properties String,
+ group1_properties String,
+ group2_properties String,
+ group3_properties String,
+ group4_properties String,
+ 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),
+ _timestamp DateTime,
+ _offset UInt64,
+ inserted_at DateTime64(6, 'UTC')
+) ENGINE = Distributed('batch_exports', 'posthog', 'sharded_events_recent', sipHash64(distinct_id));
+CREATE TABLE posthog.exchange_rate (
+ currency String,
+ date Date,
+ rate Decimal(18, 10),
+ version UInt32 DEFAULT toUnixTimestamp(now())
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.exchange_rate', '{replica}-{shard}', version) ORDER BY (date, currency) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.experiment_metric_events_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ entity_id String,
+ timestamp DateTime64(6, 'UTC'),
+ event_uuid UUID,
+ session_id String,
+ numeric_value Float64 DEFAULT 0,
+ steps Array(UInt8) DEFAULT [],
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_experiment_metric_events_preaggregated', cityHash64(entity_id));
+CREATE TABLE posthog.groups (
+ group_type_index UInt8,
+ group_key String,
+ created_at DateTime64(3),
+ team_id Int64,
+ group_properties String,
+ _timestamp DateTime,
+ _offset UInt64,
+ is_deleted Bool,
+ INDEX is_deleted_idx is_deleted TYPE minmax GRANULARITY 1
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.groups', '{replica}-{shard}', _timestamp) ORDER BY (team_id, group_type_index, group_key) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.hog_invocation_results (
+ team_id Int64,
+ function_kind LowCardinality(String),
+ function_id String,
+ invocation_id String,
+ parent_run_id String,
+ status LowCardinality(String),
+ attempts UInt8,
+ is_retry UInt8,
+ scheduled_at DateTime64(6, 'UTC'),
+ first_scheduled_at DateTime64(6, 'UTC'),
+ started_at Nullable(DateTime64(6, 'UTC')),
+ finished_at Nullable(DateTime64(6, 'UTC')),
+ duration_ms Nullable(UInt32),
+ error_kind LowCardinality(String),
+ error_message String,
+ event_uuid String,
+ distinct_id String,
+ person_id String,
+ invocation_globals String,
+ version UInt64,
+ is_deleted UInt8,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'hog_invocation_results_data');
+CREATE TABLE posthog.ingestion_warnings (
+ team_id Int64,
+ source LowCardinality(String),
+ type String,
+ details String CODEC(ZSTD(3)),
+ timestamp DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'sharded_ingestion_warnings', rand());
+CREATE TABLE posthog.ingestion_warnings_v2_distributed (
+ team_id Int64,
+ source LowCardinality(String),
+ type LowCardinality(String),
+ details String,
+ timestamp DateTime64(6, 'UTC'),
+ category LowCardinality(String) DEFAULT coalesce(nullIf(JSONExtractString(details, 'category'), ''), 'unknown'),
+ severity LowCardinality(String) DEFAULT coalesce(nullIf(JSONExtractString(details, 'severity'), ''), 'warning'),
+ pipeline_step LowCardinality(String) DEFAULT coalesce(nullIf(JSONExtractString(details, 'pipelineStep'), ''), 'unknown'),
+ event_uuid Nullable(UUID) DEFAULT toUUIDOrNull(JSONExtractString(details, 'eventUuid')),
+ distinct_id Nullable(String) DEFAULT nullIf(JSONExtractString(details, 'distinctId'), ''),
+ group_key Nullable(String) DEFAULT nullIf(JSONExtractString(details, 'groupKey'), ''),
+ person_id Nullable(UUID) DEFAULT toUUIDOrNull(JSONExtractString(details, 'personId')),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'ingestion_warnings_v2');
+CREATE TABLE posthog.kafka_session_replay_features (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ batch_id String,
+ first_timestamp DateTime64(6, 'UTC'),
+ last_timestamp DateTime64(6, 'UTC'),
+ event_count Int64,
+ mouse_position_count Int64,
+ mouse_sum_x Float64,
+ mouse_sum_x_squared Float64,
+ mouse_sum_y Float64,
+ mouse_sum_y_squared Float64,
+ mouse_distance_traveled Float64,
+ mouse_direction_change_count Int64,
+ mouse_velocity_sum Float64,
+ mouse_velocity_sum_of_squares Float64,
+ mouse_velocity_count Int64,
+ scroll_event_count Int64,
+ total_scroll_magnitude Float64,
+ scroll_direction_reversal_count Int64,
+ rapid_scroll_reversal_count Int64,
+ click_count Int64,
+ keypress_count Int64,
+ mouse_activity_count Int64,
+ rage_click_count Int64,
+ dead_click_count Int64,
+ inter_action_gap_count Int64,
+ inter_action_gap_sum_ms Float64,
+ inter_action_gap_sum_of_squares_ms Float64,
+ max_idle_gap_ms Float64,
+ quick_back_count Int64,
+ page_visit_count Int64,
+ visited_urls Array(String),
+ console_error_count Int64,
+ console_error_after_click_count Int64,
+ network_request_count Int64,
+ network_failed_request_count Int64,
+ network_request_duration_sum Float64,
+ network_request_duration_sum_of_squares Float64,
+ network_request_duration_count Int64,
+ max_scroll_y Float64,
+ click_target_ids Array(Int64),
+ text_selection_count Int64,
+ is_deleted UInt8
+) ENGINE = Kafka(msk_cluster) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'group1', kafka_topic_list = 'clickhouse_session_replay_features';
+CREATE TABLE posthog.llma_metrics_daily (
+ date Date,
+ team_id UInt64,
+ metric_name String,
+ metric_value Float64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.llma_metrics_daily', '{replica}-{shard}') ORDER BY (team_id, date, metric_name) PARTITION BY toYYYYMM(date) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.log_entries_distributed (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('aux', 'posthog', 'log_entries_data');
+CREATE TABLE posthog.marketing_conversions_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ person_id UUID,
+ conversion_timestamp DateTime64(6, 'UTC'),
+ conversion_math_value Float64,
+ session_id String,
+ campaign_name String,
+ source_name String,
+ medium_name String,
+ content_name String,
+ term_name String,
+ referring_domain_name String,
+ gclid_name String,
+ fbclid_name String,
+ gad_source_name String,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_marketing_conversions_preaggregated', cityHash64(person_id));
+CREATE TABLE posthog.marketing_costs_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ source_id String,
+ source_name String,
+ grain LowCardinality(String),
+ match_key String,
+ campaign_id String,
+ campaign_name String,
+ ad_group_id String,
+ ad_group_name String,
+ ad_id String,
+ ad_name String,
+ cost_date Date,
+ cost Float64,
+ clicks Float64,
+ impressions Float64,
+ reported_conversions Float64,
+ reported_conversion_value Float64,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_marketing_costs_preaggregated', cityHash64(source_name, campaign_id));
+CREATE TABLE posthog.marketing_touchpoints_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ person_id UUID,
+ touchpoint_timestamp DateTime64(6, 'UTC'),
+ campaign_name String,
+ source_name String,
+ medium_name String,
+ content_name String,
+ term_name String,
+ referring_domain_name String,
+ gclid_name String,
+ fbclid_name String,
+ gad_source_name String,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_marketing_touchpoints_preaggregated', cityHash64(person_id));
+CREATE TABLE posthog.message_assets (
+ team_id Int64,
+ function_kind LowCardinality(String),
+ function_id String,
+ parent_run_id String,
+ invocation_id String,
+ action_id String,
+ kind LowCardinality(String),
+ distinct_id String,
+ person_id String,
+ recipient String,
+ subject String,
+ status LowCardinality(String),
+ sent_at DateTime64(6, 'UTC'),
+ version UInt64,
+ is_deleted UInt8,
+ html String,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'message_assets_data');
+CREATE TABLE posthog.metrics_query_log (
+ host String,
+ timestamp DateTime,
+ query_duration_ms UInt64,
+ read_rows UInt64,
+ read_bytes UInt64,
+ result_rows UInt64,
+ result_bytes UInt64,
+ memory_usage UInt64,
+ is_initial_query UInt8,
+ exception_code Int32,
+ team_id Int64,
+ team_events_last_month UInt64,
+ user_id Int64,
+ kind String,
+ query_type String,
+ client_query_id String,
+ id String,
+ route_id String,
+ query_time_range_days Int64,
+ has_joins UInt8,
+ has_json_operations UInt8,
+ filter_by_type Array(String),
+ breakdown_by Array(String),
+ entity_math Array(String),
+ filter String,
+ tables Array(LowCardinality(String)),
+ columns Array(LowCardinality(String)),
+ query String,
+ log_comment String,
+ is_exception UInt8
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.metrics_query_log', '{replica}-{shard}') ORDER BY (toDate(timestamp), team_id, query_type) PARTITION BY toYYYYMM(timestamp) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.new_raw_sessions (
+ team_id Int64,
+ session_id_v7 UInt128,
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_browser AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_browser_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_device_type AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_viewport_width AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_viewport_height AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_geoip_country_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_city_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_time_zone AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_irclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ pageview_uniq AggregateFunction(uniq, Nullable(UUID)),
+ autocapture_count SimpleAggregateFunction(sum, Int64),
+ autocapture_uniq AggregateFunction(uniq, Nullable(UUID)),
+ screen_count SimpleAggregateFunction(sum, Int64),
+ screen_uniq AggregateFunction(uniq, Nullable(UUID)),
+ maybe_has_session_replay SimpleAggregateFunction(max, Bool),
+ page_screen_autocapture_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),
+ vitals_lcp AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC')),
+ initial__kx AggregateFunction(argMin, String, DateTime64(6, 'UTC'))
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_raw_sessions', cityHash64(session_id_v7));
+CREATE TABLE posthog.new_sessions (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_sessions', sipHash64(session_id));
+CREATE TABLE posthog.new_writable_raw_sessions (
+ team_id Int64,
+ session_id_v7 UInt128,
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_browser AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_browser_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_device_type AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_viewport_width AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_viewport_height AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_geoip_country_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_city_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_time_zone AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_irclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ pageview_uniq AggregateFunction(uniq, Nullable(UUID)),
+ autocapture_count SimpleAggregateFunction(sum, Int64),
+ autocapture_uniq AggregateFunction(uniq, Nullable(UUID)),
+ screen_count SimpleAggregateFunction(sum, Int64),
+ screen_uniq AggregateFunction(uniq, Nullable(UUID)),
+ maybe_has_session_replay SimpleAggregateFunction(max, Bool),
+ page_screen_autocapture_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),
+ vitals_lcp AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC')),
+ initial__kx AggregateFunction(argMin, String, DateTime64(6, 'UTC'))
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_raw_sessions', cityHash64(session_id_v7));
+CREATE TABLE posthog.new_writable_sessions (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_sessions', sipHash64(session_id));
+CREATE TABLE posthog.pending_person_deletes_reporting (
+ id UInt64,
+ deletion_type UInt8,
+ key String,
+ group_type_index Nullable(String),
+ created_at DateTime,
+ delete_verified_at Nullable(DateTime),
+ created_by_id Nullable(String),
+ team_id Int64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/pending_person_deletes_reporting', '{shard}-{replica}') ORDER BY (team_id, deletion_type, key) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.person (
+ id UUID,
+ created_at DateTime64(3),
+ team_id Int64,
+ properties String,
+ is_identified Int8,
+ is_deleted Int8 DEFAULT 0,
+ version UInt64,
+ _timestamp DateTime,
+ _offset UInt64,
+ last_seen_at Nullable(DateTime64(3))
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person', '{replica}-{shard}', version) ORDER BY (team_id, id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.person_collapsing (
+ id UUID,
+ created_at DateTime64(3),
+ team_id Int64,
+ properties String,
+ is_identified Int8,
+ _timestamp DateTime,
+ _offset UInt64,
+ _sign Int8
+) ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/prod/tables/noshard/posthog.person_collapsing', '{replica}-{shard}', _sign) ORDER BY (team_id, id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.person_distinct_id (
+ distinct_id String COMMENT 'skip_0003_fill_person_distinct_id2',
+ person_id UUID,
+ team_id Int64,
+ _sign Int8 DEFAULT 1,
+ is_deleted Int8 ALIAS if(_sign = -1, 1, 0),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/tables/noshard/posthog.person_distinct_id', '{replica}-{shard}', _sign) ORDER BY (team_id, distinct_id, person_id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.person_distinct_id2 (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ is_deleted Int8,
+ version Int64 DEFAULT 1,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_distinct_id2', '{replica}-{shard}', version) ORDER BY (team_id, distinct_id) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.person_distinct_id_overrides (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ is_deleted Int8,
+ version Int64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX kafka_timestamp_minmax_person_distinct_id_overrides _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_distinct_id_overrides', '{replica}-{shard}', version) ORDER BY (team_id, distinct_id) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.person_overrides (
+ team_id Int32,
+ old_person_id UUID,
+ override_person_id UUID,
+ merged_at DateTime64(6, 'UTC'),
+ oldest_event DateTime64(6, 'UTC'),
+ created_at DateTime64(6, 'UTC') DEFAULT now(),
+ version Int32
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_overrides', '{replica}-{shard}', version) ORDER BY (team_id, old_person_id) PARTITION BY toYYYYMM(oldest_event) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.person_overrides_to_delete (
+ team_id Int64,
+ distinct_id String,
+ partitions Array(String)
+) ENGINE = Join(ANY, LEFT, team_id, distinct_id);
+CREATE TABLE posthog.person_static_cohort (
+ id UUID,
+ person_id UUID,
+ cohort_id Int64,
+ team_id Int64,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_static_cohort', '{replica}-{shard}', _timestamp) ORDER BY (team_id, cohort_id, person_id, id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.pg_embeddings (
+ domain String,
+ team_id Int64,
+ id String,
+ vector Array(Float32),
+ text String,
+ properties String CODEC(ZSTD(3)),
+ timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ is_deleted UInt8
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.pg_embeddings', '{replica}-{shard}', timestamp, is_deleted) ORDER BY (team_id, domain, id) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.plugin_log_entries (
+ id UUID,
+ team_id Int64,
+ plugin_id Int64,
+ plugin_config_id Int64,
+ timestamp DateTime64(6, 'UTC'),
+ source String,
+ type String,
+ message String,
+ instance_id UUID,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.plugin_log_entries.fixed', '{replica}-{shard}', _timestamp) ORDER BY (team_id, plugin_id, plugin_config_id, timestamp) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(timestamp) + toIntervalWeek(1) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.property_definitions (
+ team_id UInt32,
+ project_id Nullable(UInt32),
+ name String,
+ property_type Nullable(String),
+ event Nullable(String),
+ group_type_index Nullable(UInt8),
+ type UInt8 DEFAULT 1,
+ last_seen_at DateTime,
+ version UInt64 MATERIALIZED bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.property_definitions', '{replica}-{shard}', version) ORDER BY (team_id, type, coalesce(event, ''), name, coalesce(group_type_index, 255)) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.property_values_distributed (
+ team_id Int64 CODEC(DoubleDelta, ZSTD(1)),
+ property_type LowCardinality(String),
+ property_key LowCardinality(String),
+ property_value String,
+ property_count SimpleAggregateFunction(sum, UInt64),
+ last_seen SimpleAggregateFunction(max, DateTime) DEFAULT now()
+) ENGINE = Distributed('aux', 'posthog', 'property_values');
+CREATE TABLE posthog.query_log_archive (
+ hostname LowCardinality(String),
+ user LowCardinality(String),
+ query_id String,
+ initial_query_id String,
+ is_initial_query UInt8,
+ type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4),
+ event_date Date,
+ event_time DateTime,
+ event_time_microseconds DateTime64(6),
+ query_start_time DateTime,
+ query_start_time_microseconds DateTime64(6),
+ query_duration_ms UInt64,
+ read_rows UInt64,
+ read_bytes UInt64,
+ written_rows UInt64,
+ written_bytes UInt64,
+ result_rows UInt64,
+ result_bytes UInt64,
+ memory_usage UInt64,
+ peak_threads_usage UInt64,
+ current_database LowCardinality(String),
+ query String,
+ formatted_query String,
+ normalized_query_hash UInt64,
+ query_kind LowCardinality(String),
+ exception_code Int32,
+ exception String,
+ stack_trace String,
+ team_id Int64,
+ log_comment JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email),
+ ProfileEvents Map(String, UInt64),
+ exception_name String ALIAS errorCodeToName(exception_code),
+ ProfileEvents_RealTimeMicroseconds Int64 ALIAS ProfileEvents['RealTimeMicroseconds'],
+ ProfileEvents_OSCPUVirtualTimeMicroseconds Int64 ALIAS ProfileEvents['OSCPUVirtualTimeMicroseconds'],
+ ProfileEvents_S3Clients Int64 ALIAS ProfileEvents['S3Clients'],
+ ProfileEvents_S3DeleteObjects Int64 ALIAS ProfileEvents['S3DeleteObjects'],
+ ProfileEvents_S3CopyObject Int64 ALIAS ProfileEvents['S3CopyObject'],
+ ProfileEvents_S3ListObjects Int64 ALIAS ProfileEvents['S3ListObjects'],
+ ProfileEvents_S3HeadObject Int64 ALIAS ProfileEvents['S3HeadObject'],
+ ProfileEvents_S3GetObjectAttributes Int64 ALIAS ProfileEvents['S3GetObjectAttributes'],
+ ProfileEvents_S3CreateMultipartUpload Int64 ALIAS ProfileEvents['S3CreateMultipartUpload'],
+ ProfileEvents_S3UploadPartCopy Int64 ALIAS ProfileEvents['S3UploadPartCopy'],
+ ProfileEvents_S3UploadPart Int64 ALIAS ProfileEvents['S3UploadPart'],
+ ProfileEvents_S3AbortMultipartUpload Int64 ALIAS ProfileEvents['S3AbortMultipartUpload'],
+ ProfileEvents_S3CompleteMultipartUpload Int64 ALIAS ProfileEvents['S3CompleteMultipartUpload'],
+ ProfileEvents_S3PutObject Int64 ALIAS ProfileEvents['S3PutObject'],
+ ProfileEvents_S3GetObject Int64 ALIAS ProfileEvents['S3GetObject'],
+ ProfileEvents_ReadBufferFromS3Bytes Int64 ALIAS ProfileEvents['ReadBufferFromS3Bytes'],
+ ProfileEvents_WriteBufferFromS3Bytes Int64 ALIAS ProfileEvents['WriteBufferFromS3Bytes'],
+ lc_workflow LowCardinality(String) ALIAS log_comment.workflow,
+ lc_kind LowCardinality(String) ALIAS log_comment.kind,
+ lc_id String ALIAS CAST(log_comment.id, 'String'),
+ lc_route_id String ALIAS CAST(log_comment.route_id, 'String'),
+ lc_access_method LowCardinality(String) ALIAS log_comment.access_method,
+ lc_api_key_label String ALIAS CAST(log_comment.api_key_label, 'String'),
+ lc_api_key_mask String ALIAS CAST(log_comment.api_key_mask, 'String'),
+ lc_query_type LowCardinality(String) ALIAS log_comment.query_type,
+ lc_product LowCardinality(String) ALIAS log_comment.product,
+ lc_chargeable Bool ALIAS log_comment.chargeable,
+ lc_name String ALIAS CAST(log_comment.name, 'String'),
+ lc_request_name String ALIAS CAST(log_comment.request_name, 'String'),
+ lc_client_query_id String ALIAS CAST(log_comment.client_query_id, 'String'),
+ lc_org_id String ALIAS CAST(log_comment.org_id, 'String'),
+ lc_user_id Int64 ALIAS log_comment.user_id,
+ lc_is_impersonated Bool ALIAS log_comment.is_impersonated,
+ lc_session_id String ALIAS CAST(log_comment.session_id, 'String'),
+ lc_dashboard_id Int64 ALIAS log_comment.dashboard_id,
+ lc_insight_id Int64 ALIAS log_comment.insight_id,
+ lc_cohort_id Int64 ALIAS log_comment.cohort_id,
+ lc_batch_export_id String ALIAS CAST(log_comment.batch_export_id, 'String'),
+ lc_experiment_id Int64 ALIAS log_comment.experiment_id,
+ lc_experiment_feature_flag_key String ALIAS CAST(log_comment.experiment_feature_flag_key, 'String'),
+ lc_alert_config_id String ALIAS CAST(log_comment.alert_config_id, 'String'),
+ lc_feature LowCardinality(String) ALIAS log_comment.feature,
+ lc_table_id String ALIAS CAST(log_comment.table_id, 'String'),
+ lc_warehouse_query Bool ALIAS log_comment.warehouse_query,
+ lc_person_on_events_mode LowCardinality(String) ALIAS log_comment.person_on_events_mode,
+ lc_service_name String ALIAS CAST(log_comment.service_name, 'String'),
+ lc_workload LowCardinality(String) ALIAS log_comment.workload,
+ lc_query__kind LowCardinality(String) ALIAS if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind')),
+ lc_query__query String ALIAS multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query')),
+ lc_query String ALIAS if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), ''),
+ lc_temporal__workflow_namespace String ALIAS CAST(log_comment.`temporal.workflow_namespace`, 'String'),
+ lc_temporal__workflow_type String ALIAS CAST(log_comment.`temporal.workflow_type`, 'String'),
+ lc_temporal__workflow_id String ALIAS CAST(log_comment.`temporal.workflow_id`, 'String'),
+ lc_temporal__workflow_run_id String ALIAS CAST(log_comment.`temporal.workflow_run_id`, 'String'),
+ lc_temporal__activity_type String ALIAS CAST(log_comment.`temporal.activity_type`, 'String'),
+ lc_temporal__activity_id String ALIAS CAST(log_comment.`temporal.activity_id`, 'String'),
+ lc_temporal__attempt Int64 ALIAS log_comment.`temporal.attempt`,
+ lc_dagster__job_name String ALIAS CAST(log_comment.`dagster.job_name`, 'String'),
+ lc_dagster__run_id String ALIAS CAST(log_comment.`dagster.run_id`, 'String'),
+ lc_dagster__owner String ALIAS CAST(log_comment.`dagster.tags.owner`, 'String'),
+ lc_modifiers String ALIAS if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')
+) ENGINE = Distributed('ops', 'posthog', 'sharded_query_log_archive');
+CREATE TABLE posthog.raw_sessions (
+ team_id Int64,
+ session_id_v7 UInt128,
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_browser AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_browser_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_device_type AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_viewport_width AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_viewport_height AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_geoip_country_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_city_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_time_zone AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial__kx AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_irclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ pageview_uniq AggregateFunction(uniq, Nullable(UUID)),
+ autocapture_count SimpleAggregateFunction(sum, Int64),
+ autocapture_uniq AggregateFunction(uniq, Nullable(UUID)),
+ screen_count SimpleAggregateFunction(sum, Int64),
+ screen_uniq AggregateFunction(uniq, Nullable(UUID)),
+ maybe_has_session_replay SimpleAggregateFunction(max, Bool),
+ page_screen_autocapture_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),
+ vitals_lcp AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))
+) ENGINE = Distributed('sessions', 'posthog', 'raw_sessions', cityHash64(session_id_v7));
+CREATE TABLE posthog.raw_sessions_v3 (
+ team_id Int64,
+ session_id_v7 UInt128,
+ session_timestamp DateTime64(3) MATERIALIZED fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80))),
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ distinct_ids AggregateFunction(groupUniqArray, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),
+ entry_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ browser AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ browser_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ device_type AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ viewport_width AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ viewport_height AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ geoip_country_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_city_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_time_zone AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_referring_domain AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_campaign AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_medium AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_term AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_content AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gad_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_fbclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_has_gclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_has_fbclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_ad_ids_map AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC')),
+ entry_ad_ids_set AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC')),
+ entry_channel_type_properties AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC')),
+ pageview_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ autocapture_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ 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_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ event_names SimpleAggregateFunction(groupUniqArrayArray, 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 (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ event_count SimpleAggregateFunction(sum, Int64),
+ mouse_position_count SimpleAggregateFunction(sum, Int64),
+ mouse_sum_x SimpleAggregateFunction(sum, Float64),
+ mouse_sum_x_squared SimpleAggregateFunction(sum, Float64),
+ mouse_sum_y SimpleAggregateFunction(sum, Float64),
+ mouse_sum_y_squared SimpleAggregateFunction(sum, Float64),
+ mouse_distance_traveled SimpleAggregateFunction(sum, Float64),
+ mouse_direction_change_count SimpleAggregateFunction(sum, Int64),
+ mouse_velocity_sum SimpleAggregateFunction(sum, Float64),
+ mouse_velocity_sum_of_squares SimpleAggregateFunction(sum, Float64),
+ mouse_velocity_count SimpleAggregateFunction(sum, Int64),
+ scroll_event_count SimpleAggregateFunction(sum, Int64),
+ total_scroll_magnitude SimpleAggregateFunction(sum, Float64),
+ scroll_direction_reversal_count SimpleAggregateFunction(sum, Int64),
+ rapid_scroll_reversal_count SimpleAggregateFunction(sum, Int64),
+ scroll_to_top_count SimpleAggregateFunction(sum, Int64),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ rage_click_count SimpleAggregateFunction(sum, Int64),
+ dead_click_count SimpleAggregateFunction(sum, Int64),
+ backspace_count SimpleAggregateFunction(sum, Int64),
+ inter_action_gap_count SimpleAggregateFunction(sum, Int64),
+ inter_action_gap_sum_ms SimpleAggregateFunction(sum, Float64),
+ inter_action_gap_sum_of_squares_ms SimpleAggregateFunction(sum, Float64),
+ max_idle_gap_ms SimpleAggregateFunction(max, Float64),
+ long_idle_gap_count SimpleAggregateFunction(sum, Int64),
+ quick_back_count SimpleAggregateFunction(sum, Int64),
+ page_visit_count SimpleAggregateFunction(sum, Int64),
+ unique_url_count AggregateFunction(uniqCombined(12), String),
+ login_path_visit_count SimpleAggregateFunction(sum, Int64),
+ signup_path_visit_count SimpleAggregateFunction(sum, Int64),
+ checkout_path_visit_count SimpleAggregateFunction(sum, Int64),
+ cart_path_visit_count SimpleAggregateFunction(sum, Int64),
+ billing_path_visit_count SimpleAggregateFunction(sum, Int64),
+ settings_path_visit_count SimpleAggregateFunction(sum, Int64),
+ account_path_visit_count SimpleAggregateFunction(sum, Int64),
+ error_path_visit_count SimpleAggregateFunction(sum, Int64),
+ not_found_path_visit_count SimpleAggregateFunction(sum, Int64),
+ admin_path_visit_count SimpleAggregateFunction(sum, Int64),
+ dashboard_path_visit_count SimpleAggregateFunction(sum, Int64),
+ onboarding_path_visit_count SimpleAggregateFunction(sum, Int64),
+ cancel_path_visit_count SimpleAggregateFunction(sum, Int64),
+ refund_path_visit_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ console_error_after_click_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ network_request_count SimpleAggregateFunction(sum, Int64),
+ network_failed_request_count SimpleAggregateFunction(sum, Int64),
+ network_4xx_count SimpleAggregateFunction(sum, Int64),
+ network_5xx_count SimpleAggregateFunction(sum, Int64),
+ network_request_duration_sum SimpleAggregateFunction(sum, Float64),
+ network_request_duration_sum_of_squares SimpleAggregateFunction(sum, Float64),
+ network_request_duration_count SimpleAggregateFunction(sum, Int64),
+ mutation_count SimpleAggregateFunction(sum, Int64),
+ viewport_resize_count SimpleAggregateFunction(sum, Int64),
+ touch_event_count SimpleAggregateFunction(sum, Int64),
+ max_scroll_y SimpleAggregateFunction(max, Float64),
+ unique_click_target_count AggregateFunction(uniqCombined(12), Int64),
+ unique_form_field_count AggregateFunction(uniqCombined(12), Int64),
+ text_selection_count SimpleAggregateFunction(sum, Int64),
+ selection_copy_count SimpleAggregateFunction(sum, Int64),
+ is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0
+) ENGINE = Distributed('aux', 'posthog', 'sharded_session_replay_features', sipHash64(session_id));
+CREATE TABLE posthog.sessions (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = Distributed('sessions', 'posthog', 'sessions', sipHash64(session_id));
+CREATE TABLE posthog.sharded_app_metrics2 (
+ team_id Int64,
+ timestamp DateTime64(6, 'UTC'),
+ app_source LowCardinality(String),
+ app_source_id String,
+ instance_id String,
+ metric_kind LowCardinality(String),
+ metric_name LowCardinality(String),
+ count SimpleAggregateFunction(sum, Int64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_app_metrics2', '{replica}') ORDER BY (team_id, app_source, app_source_id, instance_id, toStartOfHour(timestamp), metric_kind, metric_name) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_distinct_id_usage (
+ team_id Int64,
+ distinct_id String,
+ minute DateTime,
+ event_count UInt64
+) ENGINE = ReplicatedSummingMergeTree('/clickhouse/tables/{shard}/posthog.distinct_id_usage', '{replica}', (event_count)) 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;
+CREATE TABLE posthog.sharded_events (
+ uuid UUID,
+ event String,
+ properties String CODEC(ZSTD(3)),
+ 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),
+ $group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0',
+ $group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1',
+ $group_2 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^"|"$', '') COMMENT 'column_materializer::$group_2',
+ $group_3 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^"|"$', '') COMMENT 'column_materializer::$group_3',
+ $group_4 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^"|"$', '') COMMENT 'column_materializer::$group_4',
+ $window_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^"|"$', '') COMMENT 'column_materializer::$window_id',
+ $session_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^"|"$', '') COMMENT 'column_materializer::$session_id',
+ _timestamp DateTime,
+ _offset UInt64,
+ inserted_at Nullable(DateTime64(6, 'UTC')) DEFAULT now64(),
+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),
+ mat_metadata_backend String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, 'metadata.backend'), '^"|"$', ''),
+ mat_metadata_loggedIn String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, 'metadata.loggedIn'), '^"|"$', ''),
+ 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'))), 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)),
+ mat_$ai_trace_id Nullable(String) DEFAULT JSONExtract(properties, '$ai_trace_id', 'Nullable(String)'),
+ $session_id_uuid Nullable(UInt128) MATERIALIZED toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)')),
+ consumer_breadcrumbs Array(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_historical_migration Nullable(String) DEFAULT JSONExtract(properties, 'historical_migration', 'Nullable(String)'),
+ 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_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_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 is_deleted_idx is_deleted TYPE minmax 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 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 minmax_mat_historical_migration mat_historical_migration TYPE minmax GRANULARITY 1,
+ 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_$session_id_uuid `$session_id_uuid` TYPE minmax GRANULARITY 1,
+ INDEX bloom_filter_$session_id nullIf(nullIf(`$session_id`, ''), 'null') TYPE bloom_filter GRANULARITY 1,
+ INDEX minmax_mat_metadata_backend mat_metadata_backend TYPE minmax GRANULARITY 1,
+ INDEX minmax_mat_metadata_loggedIn mat_metadata_loggedIn TYPE minmax GRANULARITY 1,
+ INDEX minmax_mat_$ai_trace_id `mat_$ai_trace_id` 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, max_avg_part_size_for_too_many_parts = 0;
+CREATE TABLE posthog.sharded_experiment_exposures_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ entity_id String,
+ variant String,
+ first_exposure_time DateTime64(6, 'UTC'),
+ last_exposure_time DateTime64(6, 'UTC'),
+ exposure_event_uuid UUID,
+ exposure_session_id String,
+ breakdown_value Array(String),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.experiment_exposures_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, entity_id, breakdown_value) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_flag_evaluations (
+ uuid UUID,
+ event LowCardinality(String),
+ properties String,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ created_at DateTime64(6, 'UTC'),
+ person_id UUID,
+ inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,
+ $group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0',
+ $group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1',
+ $group_2 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^"|"$', '') COMMENT 'column_materializer::$group_2',
+ $group_3 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^"|"$', '') COMMENT 'column_materializer::$group_3',
+ $group_4 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^"|"$', '') COMMENT 'column_materializer::$group_4',
+ flag_key String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag',
+ response LowCardinality(String) DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag_response',
+ session_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^"|"$', '') COMMENT 'column_materializer::properties::$session_id',
+ request_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_request_id'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag_request_id',
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX distinct_id_idx distinct_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX person_id_idx person_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX session_id_idx session_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX request_id_idx request_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX inserted_at_idx inserted_at TYPE minmax GRANULARITY 1
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.flag_evaluations', '{replica}') ORDER BY (team_id, flag_key, toDate(timestamp), cityHash64(distinct_id)) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_heatmaps (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ timestamp DateTime64(6, 'UTC'),
+ x Int16,
+ y Int16,
+ scale_factor Int16,
+ viewport_width Int16,
+ viewport_height Int16,
+ pointer_target_fixed Bool,
+ current_url String,
+ type LowCardinality(String),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.heatmaps', '{replica}') ORDER BY (type, team_id, toDate(timestamp), current_url, viewport_width) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_log_entries (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_log_entries', '{replica}', _timestamp) ORDER BY (team_id, log_source, log_source_id, instance_id, timestamp) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_performance_events (
+ uuid UUID,
+ session_id String,
+ window_id String,
+ pageview_id String,
+ distinct_id String,
+ timestamp DateTime64(3),
+ time_origin DateTime64(3, 'UTC'),
+ entry_type LowCardinality(String),
+ name String,
+ team_id Int64,
+ current_url String,
+ start_time Float64,
+ duration Float64,
+ redirect_start Float64,
+ redirect_end Float64,
+ worker_start Float64,
+ fetch_start Float64,
+ domain_lookup_start Float64,
+ domain_lookup_end Float64,
+ connect_start Float64,
+ secure_connection_start Float64,
+ connect_end Float64,
+ request_start Float64,
+ response_start Float64,
+ response_end Float64,
+ decoded_body_size Int64,
+ encoded_body_size Int64,
+ initiator_type LowCardinality(String),
+ next_hop_protocol LowCardinality(String),
+ render_blocking_status LowCardinality(String),
+ response_status Int64,
+ transfer_size Int64,
+ largest_contentful_paint_element String,
+ largest_contentful_paint_render_time Float64,
+ largest_contentful_paint_load_time Float64,
+ largest_contentful_paint_size Float64,
+ largest_contentful_paint_id String,
+ largest_contentful_paint_url String,
+ dom_complete Float64,
+ dom_content_loaded_event Float64,
+ dom_interactive Float64,
+ load_event_end Float64,
+ load_event_start Float64,
+ redirect_count Int64,
+ navigation_type LowCardinality(String),
+ unload_event_end Float64,
+ unload_event_start Float64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.performance_events', '{replica}') ORDER BY (team_id, toDate(timestamp), session_id, pageview_id, timestamp) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalWeek(3) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_posthog_document_embeddings_buffer (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ model_name LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_buffer', '{replica}', inserted_at) ORDER BY (inserted_at, model_name, cityHash64(document_id)) PARTITION BY toDate(inserted_at) TTL inserted_at + toIntervalDay(1) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ CONSTRAINT embedding_dimension_check CHECK length(embedding) = 3072,
+ INDEX kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_large_3072 _timestamp TYPE minmax GRANULARITY 3,
+ INDEX embedding_idx_l2 embedding TYPE vector_similarity('hnsw', 'L2Distance', 3072) GRANULARITY 100000000,
+ INDEX embedding_idx_cosine embedding TYPE vector_similarity('hnsw', 'cosineDistance', 3072) GRANULARITY 100000000
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072', '{replica}', inserted_at) ORDER BY (team_id, toDate(timestamp), product, document_type, rendering, cityHash64(document_id)) PARTITION BY toMonday(timestamp) TTL timestamp + toIntervalMonth(3) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ CONSTRAINT embedding_dimension_check CHECK length(embedding) = 1536,
+ INDEX kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_small_1536 _timestamp TYPE minmax GRANULARITY 3,
+ INDEX embedding_idx_l2 embedding TYPE vector_similarity('hnsw', 'L2Distance', 1536) GRANULARITY 100000000,
+ INDEX embedding_idx_cosine embedding TYPE vector_similarity('hnsw', 'cosineDistance', 1536) GRANULARITY 100000000
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536', '{replica}', inserted_at) ORDER BY (team_id, toDate(timestamp), product, document_type, rendering, cityHash64(document_id)) PARTITION BY toMonday(timestamp) TTL timestamp + toIntervalMonth(3) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_preaggregation_results (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7),
+ breakdown_value Array(String),
+ uniq_exact_state AggregateFunction(uniqExact, UUID)
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.preaggregation_results', '{replica}') ORDER BY (team_id, job_id, time_window_start, breakdown_value) PARTITION BY toYYYYMM(time_window_start) TTL expires_at SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_precalculated_person_properties (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ condition String,
+ matches Bool,
+ source String,
+ _timestamp DateTime64(6),
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_precalculated_person_properties', '{replica}', _timestamp) ORDER BY (team_id, condition, distinct_id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_raw_sessions_v3 (
+ team_id Int64,
+ session_id_v7 UInt128,
+ session_timestamp DateTime64(3) MATERIALIZED fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80))),
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ distinct_ids AggregateFunction(groupUniqArray, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),
+ entry_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ browser AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ browser_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ device_type AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ viewport_width AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ viewport_height AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ geoip_country_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_city_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_time_zone AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_referring_domain AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_campaign AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_medium AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_term AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_content AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gad_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_fbclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_has_gclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_has_fbclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_ad_ids_map AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC')),
+ entry_ad_ids_set AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC')),
+ entry_channel_type_properties AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC')),
+ pageview_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ autocapture_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ 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_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ event_names SimpleAggregateFunction(groupUniqArrayArray, 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
+) 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,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ session_id String,
+ window_id String,
+ snapshot_data String,
+ created_at DateTime64(6, 'UTC'),
+ has_full_snapshot Int8 MATERIALIZED JSONExtractBool(snapshot_data, 'has_full_snapshot') COMMENT 'column_materializer::has_full_snapshot',
+ _timestamp DateTime,
+ _offset UInt64,
+ events_summary Array(String) MATERIALIZED JSONExtract(JSON_QUERY(snapshot_data, '$.events_summary[*]'), 'Array(String)'),
+ click_count Int8 MATERIALIZED length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 2) AND (JSONExtractInt(x, 'data', 'source') = 2)), events_summary)),
+ keypress_count Int8 MATERIALIZED length(arrayFilter(x -> ((JSONExtractInt(x, 'type') = 3) AND (JSONExtractInt(x, 'data', 'source') = 5)), events_summary)),
+ timestamps_summary Array(DateTime64(6, 'UTC')) MATERIALIZED arraySort(arrayMap(x -> toDateTime(JSONExtractInt(x, 'timestamp') / 1000), events_summary)),
+ first_event_timestamp DateTime64(6, 'UTC') MATERIALIZED arrayReduce('min', timestamps_summary),
+ last_event_timestamp DateTime64(6, 'UTC') MATERIALIZED arrayReduce('max', timestamps_summary),
+ urls Array(String) MATERIALIZED arrayFilter(x -> (x != ''), arrayMap(x -> JSONExtractString(x, 'data', 'href'), events_summary))
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.session_recording_events', '{replica}', _timestamp) ORDER BY (team_id, toHour(timestamp), session_id, timestamp, uuid) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(created_at) + toIntervalWeek(3) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.sharded_session_replay_embeddings (
+ session_id String,
+ team_id Int64,
+ embeddings Array(Float32),
+ generation_timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ source_type LowCardinality(String),
+ input String
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.session_replay_embeddings', '{replica}') ORDER BY (toDate(generation_timestamp), team_id, session_id) PARTITION BY toYYYYMM(generation_timestamp) TTL toDate(generation_timestamp) + toIntervalYear(1) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.sharded_session_replay_events (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ active_milliseconds SimpleAggregateFunction(sum, Int64),
+ console_log_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ size SimpleAggregateFunction(sum, Int64),
+ message_count SimpleAggregateFunction(sum, Int64),
+ event_count SimpleAggregateFunction(sum, Int64),
+ _timestamp SimpleAggregateFunction(max, DateTime),
+ snapshot_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.session_replay_events', '{replica}') ORDER BY (toDate(min_first_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.swap_person_distinct_id (
+ distinct_id String,
+ person_id UUID,
+ team_id Int64,
+ _sign Int8 DEFAULT 1,
+ is_deleted Int8 ALIAS if(_sign = -1, 1, 0),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/prod/tables/noshard/posthog.swap_person_distinct_id', '{replica}-{shard}', _sign) ORDER BY (team_id, distinct_id, person_id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.tophog (
+ timestamp DateTime64(6, 'UTC'),
+ metric LowCardinality(String),
+ type LowCardinality(String) DEFAULT 'sum',
+ key Map(LowCardinality(String), String),
+ value Float64,
+ count UInt64 DEFAULT 0,
+ pipeline LowCardinality(String),
+ lane LowCardinality(String),
+ labels Map(LowCardinality(String), String)
+) ENGINE = Distributed('ops', 'posthog', 'sharded_tophog', cityHash64(toString(key)));
+CREATE TABLE posthog.usage_report_events_preagg (
+ date Date,
+ team_id Int64,
+ person_mode LowCardinality(String),
+ lib LowCardinality(String),
+ event String,
+ distinct_events_unique AggregateFunction(uniqExact, Tuple(UInt64, UInt64, UInt64)),
+ event_count AggregateFunction(sum, UInt64)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_usage_report_events_preagg', sipHash64(date));
+CREATE TABLE posthog.web_bot_definition (
+ id UInt64,
+ parent_id UInt64,
+ regexp String,
+ keys Array(String),
+ values Array(String)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_bot_definition', sipHash64(id));
+CREATE TABLE posthog.web_bounces_daily_distributed (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ updated_at DateTime64(6, 'UTC') DEFAULT now(),
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64),
+ bounces_count_state AggregateFunction(sum, UInt64),
+ total_session_duration_state AggregateFunction(sum, Int64),
+ total_session_count_state AggregateFunction(sum, UInt64)
+) ENGINE = Distributed('posthog', 'posthog', 'web_bounces_daily', rand());
+CREATE TABLE posthog.web_bounces_dimensional_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ period_bucket DateTime,
+ host String,
+ device_type String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ mat_metadata_loggedIn Nullable(Bool),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, Int64),
+ bounces_count_state AggregateFunction(sum, Int64),
+ total_session_duration_state AggregateFunction(sum, Int64),
+ total_session_count_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_bounces_dimensional_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_bounces_hourly_distributed (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ updated_at DateTime64(6, 'UTC') DEFAULT now(),
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64),
+ bounces_count_state AggregateFunction(sum, UInt64),
+ total_session_duration_state AggregateFunction(sum, Int64),
+ total_session_count_state AggregateFunction(sum, UInt64)
+) ENGINE = Distributed('posthog', 'posthog', 'web_bounces_hourly', rand());
+CREATE TABLE posthog.web_goals_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ action_id Int64,
+ count_state AggregateFunction(sum, Int64),
+ unique_persons_state AggregateFunction(uniq, UUID),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_goals_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_overview_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ uniq_users_state AggregateFunction(uniq, UUID),
+ uniq_sessions_state AggregateFunction(uniq, String),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ avg_duration_state AggregateFunction(avg, Float64),
+ avg_bounce_state AggregateFunction(avg, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_overview_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_pre_aggregated_bounces (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64),
+ bounces_count_state AggregateFunction(sum, UInt64),
+ total_session_duration_state AggregateFunction(sum, Int64),
+ total_session_count_state AggregateFunction(sum, UInt64),
+ mat_metadata_loggedIn Nullable(Bool)
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces', '{replica}-{shard}') ORDER BY (team_id, period_bucket, host, device_type, entry_pathname, end_pathname, browser, os, viewport_width, viewport_height, referring_domain, utm_source, utm_medium, utm_campaign, utm_term, utm_content, country_code, city_name, region_code, region_name, has_gclid, has_gad_source_paid_search, has_fbclid) PARTITION BY toYYYYMMDD(period_bucket) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.web_pre_aggregated_stats (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ pathname String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64),
+ mat_metadata_loggedIn Nullable(Bool)
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats', '{replica}-{shard}') ORDER BY (team_id, period_bucket, host, device_type, pathname, entry_pathname, end_pathname, browser, os, viewport_width, viewport_height, referring_domain, utm_source, utm_medium, utm_campaign, utm_term, utm_content, country_code, city_name, region_code, region_name, has_gclid, has_gad_source_paid_search, has_fbclid) PARTITION BY toYYYYMMDD(period_bucket) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.web_pre_aggregated_teams (
+ team_id UInt64,
+ enabled_by String DEFAULT 'system',
+ version UInt32 DEFAULT toUnixTimestamp(now())
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.web_analytics_team_selection', '{replica}-{shard}', version) ORDER BY (team_id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.web_stats_daily_distributed (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ updated_at DateTime64(6, 'UTC') DEFAULT now(),
+ pathname String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64)
+) ENGINE = Distributed('posthog', 'posthog', 'web_stats_daily', rand());
+CREATE TABLE posthog.web_stats_dimensional_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ period_bucket DateTime,
+ host String,
+ device_type String,
+ pathname String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ mat_metadata_loggedIn Nullable(Bool),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_dimensional_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_stats_frustration_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_value String,
+ sum_rage_clicks_state AggregateFunction(sum, Int64),
+ sum_dead_clicks_state AggregateFunction(sum, Int64),
+ sum_errors_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_frustration_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_stats_hourly_distributed (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ updated_at DateTime64(6, 'UTC') DEFAULT now(),
+ pathname String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64)
+) ENGINE = Distributed('posthog', 'posthog', 'web_stats_hourly', rand());
+CREATE TABLE posthog.web_stats_paths_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_value String,
+ uniq_users_state AggregateFunction(uniq, UUID),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ avg_bounce_state AggregateFunction(avg, Nullable(Float64)),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_paths_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_stats_paths_preaggregated_pathkey (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_value String,
+ uniq_users_state AggregateFunction(uniq, UUID),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ avg_bounce_state AggregateFunction(avg, Nullable(Float64)),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_paths_preaggregated_pathkey', sipHash64(breakdown_value));
+CREATE TABLE posthog.web_stats_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_by String,
+ breakdown_value String,
+ uniq_users_state AggregateFunction(uniq, UUID),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_vitals_paths_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ path String,
+ inp_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ lcp_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ cls_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ fcp_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_vitals_paths_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.writable_events (
+ uuid UUID,
+ event String,
+ properties String CODEC(ZSTD(3)),
+ 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),
+ _timestamp DateTime,
+ _offset UInt64,
+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),
+ consumer_breadcrumbs Array(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)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_events', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_events_dead_letter_queue (
+ id UUID,
+ event_uuid UUID,
+ event String,
+ properties String,
+ distinct_id String,
+ team_id Int64,
+ elements_chain String,
+ created_at DateTime64(6, 'UTC'),
+ ip String,
+ site_url String,
+ now DateTime64(6, 'UTC'),
+ raw_payload String,
+ error_timestamp DateTime64(6, 'UTC'),
+ error_location String,
+ error String,
+ tags Array(String),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog_single_shard', 'posthog', 'events_dead_letter_queue');
+CREATE TABLE posthog.writable_events_recent (
+ uuid UUID,
+ event String,
+ properties String CODEC(ZSTD(3)),
+ 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,
+ _timestamp DateTime,
+ _offset UInt64,
+ inserted_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = Distributed('batch_exports_writable', 'posthog', 'sharded_events_recent', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_log_entries (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_log_entries', rand());
+CREATE TABLE posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_large_3072', cityHash64(document_id));
+CREATE TABLE posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_small_1536', cityHash64(document_id));
+CREATE TABLE posthog.writable_query_log_archive (
+ hostname LowCardinality(String),
+ user LowCardinality(String),
+ query_id String,
+ initial_query_id String,
+ is_initial_query UInt8,
+ type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4),
+ event_date Date,
+ event_time DateTime,
+ event_time_microseconds DateTime64(6),
+ query_start_time DateTime,
+ query_start_time_microseconds DateTime64(6),
+ query_duration_ms UInt64,
+ read_rows UInt64,
+ read_bytes UInt64,
+ written_rows UInt64,
+ written_bytes UInt64,
+ result_rows UInt64,
+ result_bytes UInt64,
+ memory_usage UInt64,
+ peak_threads_usage UInt64,
+ current_database LowCardinality(String),
+ query String,
+ formatted_query String,
+ normalized_query_hash UInt64,
+ query_kind LowCardinality(String),
+ exception_code Int32,
+ exception String,
+ stack_trace String,
+ team_id Int64,
+ log_comment JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email),
+ ProfileEvents Map(String, UInt64)
+) ENGINE = Distributed('ops', 'posthog', 'query_log_archive_buffer');
+CREATE TABLE posthog.writable_raw_sessions (
+ team_id Int64,
+ session_id_v7 UInt128,
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_browser AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_browser_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_device_type AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_viewport_width AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_viewport_height AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_geoip_country_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_city_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_time_zone AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_irclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ pageview_uniq AggregateFunction(uniq, Nullable(UUID)),
+ autocapture_count SimpleAggregateFunction(sum, Int64),
+ autocapture_uniq AggregateFunction(uniq, Nullable(UUID)),
+ screen_count SimpleAggregateFunction(sum, Int64),
+ screen_uniq AggregateFunction(uniq, Nullable(UUID)),
+ maybe_has_session_replay SimpleAggregateFunction(max, Bool),
+ page_screen_autocapture_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),
+ vitals_lcp AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC')),
+ initial__kx AggregateFunction(argMin, String, DateTime64(6, 'UTC'))
+) ENGINE = Distributed('sessions', 'posthog', 'raw_sessions', cityHash64(session_id_v7));
+CREATE TABLE posthog.writable_raw_sessions_v3 (
+ team_id Int64,
+ session_id_v7 UInt128,
+ session_timestamp DateTime64(3) MATERIALIZED fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80))),
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ distinct_ids AggregateFunction(groupUniqArray, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),
+ entry_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ browser AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ browser_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ device_type AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ viewport_width AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ viewport_height AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ geoip_country_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_city_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_time_zone AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_referring_domain AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_campaign AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_medium AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_term AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_content AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gad_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_fbclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_has_gclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_has_fbclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_ad_ids_map AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC')),
+ entry_ad_ids_set AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC')),
+ entry_channel_type_properties AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC')),
+ pageview_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ autocapture_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ 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_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.writable_session_recording_events (
+ uuid UUID,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ session_id String,
+ window_id String,
+ snapshot_data String,
+ created_at DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_recording_events', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_session_replay_embeddings (
+ session_id String,
+ team_id Int64,
+ embeddings Array(Float32),
+ generation_timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ source_type LowCardinality(String),
+ input String
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_embeddings', sipHash64(session_id));
+CREATE TABLE posthog.writable_session_replay_events (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
+ first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ active_milliseconds SimpleAggregateFunction(sum, Int64),
+ console_log_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ size SimpleAggregateFunction(sum, Int64),
+ message_count SimpleAggregateFunction(sum, Int64),
+ event_count SimpleAggregateFunction(sum, Int64),
+ snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
+ snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ _timestamp SimpleAggregateFunction(max, DateTime),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_sessions (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = Distributed('sessions', 'posthog', 'sessions', sipHash64(session_id));
+CREATE TABLE posthog.writeable_performance_events (
+ uuid UUID,
+ session_id String,
+ window_id String,
+ pageview_id String,
+ distinct_id String,
+ timestamp DateTime64(3),
+ time_origin DateTime64(3, 'UTC'),
+ entry_type LowCardinality(String),
+ name String,
+ team_id Int64,
+ current_url String,
+ start_time Float64,
+ duration Float64,
+ redirect_start Float64,
+ redirect_end Float64,
+ worker_start Float64,
+ fetch_start Float64,
+ domain_lookup_start Float64,
+ domain_lookup_end Float64,
+ connect_start Float64,
+ secure_connection_start Float64,
+ connect_end Float64,
+ request_start Float64,
+ response_start Float64,
+ response_end Float64,
+ decoded_body_size Int64,
+ encoded_body_size Int64,
+ initiator_type LowCardinality(String),
+ next_hop_protocol LowCardinality(String),
+ render_blocking_status LowCardinality(String),
+ response_status Int64,
+ transfer_size Int64,
+ largest_contentful_paint_element String,
+ largest_contentful_paint_render_time Float64,
+ largest_contentful_paint_load_time Float64,
+ largest_contentful_paint_size Float64,
+ largest_contentful_paint_id String,
+ largest_contentful_paint_url String,
+ dom_complete Float64,
+ dom_content_loaded_event Float64,
+ dom_interactive Float64,
+ load_event_end Float64,
+ load_event_start Float64,
+ redirect_count Int64,
+ navigation_type LowCardinality(String),
+ unload_event_end Float64,
+ unload_event_start Float64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_performance_events', sipHash64(session_id));
+CREATE MATERIALIZED VIEW posthog.ops_query_log_archive_mv TO posthog.writable_query_log_archive (hostname LowCardinality(String), user LowCardinality(String), query_id String, initial_query_id String, is_initial_query UInt8, type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4), event_date Date, event_time DateTime, event_time_microseconds DateTime64(6), query_start_time DateTime, query_start_time_microseconds DateTime64(6), query_duration_ms UInt64, read_rows UInt64, read_bytes UInt64, written_rows UInt64, written_bytes UInt64, result_rows UInt64, result_bytes UInt64, memory_usage UInt64, peak_threads_usage UInt64, current_database LowCardinality(String), query String, formatted_query String, normalized_query_hash UInt64, query_kind LowCardinality(String), exception_code Int32, exception String, stack_trace String, team_id Int64, log_comment String, ProfileEvents Map(LowCardinality(String), UInt64)) AS SELECT
+ hostname,
+ user,
+ query_id,
+ initial_query_id,
+ is_initial_query,
+ type,
+ event_date,
+ event_time,
+ event_time_microseconds,
+ query_start_time,
+ query_start_time_microseconds,
+ query_duration_ms,
+ read_rows,
+ read_bytes,
+ written_rows,
+ written_bytes,
+ result_rows,
+ result_bytes,
+ memory_usage,
+ peak_threads_usage,
+ current_database,
+ query,
+ formatted_query,
+ normalized_query_hash,
+ query_kind,
+ exception_code,
+ exception,
+ stack_trace,
+ JSONExtractInt(log_comment, 'team_id') AS team_id,
+ if(isValidJSON(log_comment), log_comment, '{}') AS log_comment,
+ ProfileEvents
+FROM system.query_log
+WHERE type != 'QueryStart';
+CREATE MATERIALIZED VIEW posthog.posthog_document_embeddings_text_embedding_3_large_3072_mv TO posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072 (team_id Int64, product LowCardinality(String), document_type LowCardinality(String), rendering LowCardinality(String), document_id String, timestamp DateTime64(3, 'UTC'), inserted_at DateTime64(3, 'UTC'), content String, metadata String, embedding Array(Float64), _timestamp DateTime, _offset UInt64, _partition UInt64) AS SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-large-3072';
+CREATE MATERIALIZED VIEW posthog.posthog_document_embeddings_text_embedding_3_small_1536_mv TO posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536 (team_id Int64, product LowCardinality(String), document_type LowCardinality(String), rendering LowCardinality(String), document_id String, timestamp DateTime64(3, 'UTC'), inserted_at DateTime64(3, 'UTC'), content String, metadata String, embedding Array(Float64), _timestamp DateTime, _offset UInt64, _partition UInt64) AS SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-small-1536';
+CREATE MATERIALIZED VIEW posthog.session_replay_features_mv TO posthog.writable_session_replay_features (session_id String, team_id Int64, distinct_id String, min_first_timestamp DateTime64(6, 'UTC'), max_last_timestamp DateTime64(6, 'UTC'), event_count Int64, mouse_position_count Int64, mouse_sum_x Float64, mouse_sum_x_squared Float64, mouse_sum_y Float64, mouse_sum_y_squared Float64, mouse_distance_traveled Float64, mouse_direction_change_count Int64, mouse_velocity_sum Float64, mouse_velocity_sum_of_squares Float64, mouse_velocity_count Int64, scroll_event_count Int64, total_scroll_magnitude Float64, scroll_direction_reversal_count Int64, rapid_scroll_reversal_count Int64, click_count Int64, keypress_count Int64, mouse_activity_count Int64, rage_click_count Int64, dead_click_count Int64, inter_action_gap_count Int64, inter_action_gap_sum_ms Float64, inter_action_gap_sum_of_squares_ms Float64, max_idle_gap_ms Float64, quick_back_count Int64, page_visit_count Int64, unique_url_count AggregateFunction(uniqExactArray, Array(String)), console_error_count Int64, console_error_after_click_count Int64, network_request_count Int64, network_failed_request_count Int64, network_request_duration_sum Float64, network_request_duration_sum_of_squares Float64, network_request_duration_count Int64, max_scroll_y Float64, unique_click_target_count AggregateFunction(uniqExactArray, Array(Int64)), text_selection_count Int64, is_deleted UInt8) AS SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(first_timestamp) AS min_first_timestamp,
+ max(last_timestamp) AS max_last_timestamp,
+ sum(event_count) AS event_count,
+ sum(mouse_position_count) AS mouse_position_count,
+ sum(mouse_sum_x) AS mouse_sum_x,
+ sum(mouse_sum_x_squared) AS mouse_sum_x_squared,
+ sum(mouse_sum_y) AS mouse_sum_y,
+ sum(mouse_sum_y_squared) AS mouse_sum_y_squared,
+ sum(mouse_distance_traveled) AS mouse_distance_traveled,
+ sum(mouse_direction_change_count) AS mouse_direction_change_count,
+ sum(mouse_velocity_sum) AS mouse_velocity_sum,
+ sum(mouse_velocity_sum_of_squares) AS mouse_velocity_sum_of_squares,
+ sum(mouse_velocity_count) AS mouse_velocity_count,
+ sum(scroll_event_count) AS scroll_event_count,
+ sum(total_scroll_magnitude) AS total_scroll_magnitude,
+ sum(scroll_direction_reversal_count) AS scroll_direction_reversal_count,
+ sum(rapid_scroll_reversal_count) AS rapid_scroll_reversal_count,
+ sum(click_count) AS click_count,
+ sum(keypress_count) AS keypress_count,
+ sum(mouse_activity_count) AS mouse_activity_count,
+ sum(rage_click_count) AS rage_click_count,
+ sum(dead_click_count) AS dead_click_count,
+ sum(inter_action_gap_count) AS inter_action_gap_count,
+ sum(inter_action_gap_sum_ms) AS inter_action_gap_sum_ms,
+ sum(inter_action_gap_sum_of_squares_ms) AS inter_action_gap_sum_of_squares_ms,
+ max(max_idle_gap_ms) AS max_idle_gap_ms,
+ sum(quick_back_count) AS quick_back_count,
+ sum(page_visit_count) AS page_visit_count,
+ uniqExactArrayState(visited_urls) AS unique_url_count,
+ sum(console_error_count) AS console_error_count,
+ sum(console_error_after_click_count) AS console_error_after_click_count,
+ sum(network_request_count) AS network_request_count,
+ sum(network_failed_request_count) AS network_failed_request_count,
+ sum(network_request_duration_sum) AS network_request_duration_sum,
+ sum(network_request_duration_sum_of_squares) AS network_request_duration_sum_of_squares,
+ sum(network_request_duration_count) AS network_request_duration_count,
+ max(max_scroll_y) AS max_scroll_y,
+ uniqExactArrayState(click_target_ids) AS unique_click_target_count,
+ sum(text_selection_count) AS text_selection_count,
+ max(is_deleted) AS is_deleted
+FROM posthog.kafka_session_replay_features
+GROUP BY
+ session_id, team_id;
+CREATE VIEW posthog.custom_metrics_backups AS WITH
+ ['ClickHouseCustomMetric_BackupFailed', 'ClickHouseCustomMetric_BackupSuccess', 'ClickHouseCustomMetric_BackupCancelled', 'ClickHouseCustomMetric_BackupAttempts'] AS names,
+ [toInt64(countIf(status = 'BACKUP_FAILED')), toInt64(countIf(status = 'BACKUP_CREATED')), toInt64(countIf(status = 'BACKUP_CANCELLED')), toInt64(countIf(status = 'CREATING_BACKUP'))] AS `values`,
+ ['Number of failed backups', 'Number of successful backups', 'Number of cancelled backups', 'Number of backup attempts'] AS descriptions,
+ ['gauge', 'gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.backup_log
+WHERE event_date = today()
+GROUP BY
+ event_date;
+CREATE VIEW posthog.custom_metrics_dictionaries AS SELECT
+ 'ClickHouseCustomMetric_DictionariesFailed' AS name,
+ map(
+ 'instance',
+ hostname(),
+ 'database',
+ d.database,
+ 'dictionary',
+ d.dict_name,
+ 'uuid',
+ toString(d.uuid),
+ 'status',
+ toString(d.status)
+ ) AS labels,
+ toUInt64(1) AS value,
+ 'Dictionary is in FAILED or FAILED_AND_RELOADING status' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT name AS dict_name, database, uuid, status
+ FROM system.dictionaries
+ WHERE status IN ('FAILED', 'FAILED_AND_RELOADING')
+ ) AS d;
+CREATE VIEW posthog.custom_metrics_part_counts AS SELECT
+ 'ClickHouseCustomMetric_MaxPartCountPerPartition' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`, 'partition', partition) AS labels,
+ part_count AS value,
+ 'Maximum number of active parts for any partition in a PostHog table' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT database, `table`, partition, count() AS part_count
+ FROM system.parts
+ WHERE
+ active
+ AND
+ (database = 'posthog')
+ GROUP BY
+ database, `table`, partition
+ ORDER BY database ASC, `table` ASC, part_count DESC, partition ASC
+ LIMIT 1 BY database, `table`
+ );
+CREATE VIEW posthog.custom_metrics_replication_queue AS WITH
+ ['ClickHouseCustomMetric_ReplicationQueueStuckEntries', 'ClickHouseCustomMetric_ReplicationQueueMaxPostponedEntrySeconds', 'ClickHouseCustomMetric_ReplicationQueueMaxErrorEntrySeconds'] AS names,
+ [toInt64(countIf(create_time < (now() - toIntervalDay(15)))), maxIf(dateDiff('seconds', create_time, last_postpone_time), last_postpone_time != '1970-01-01'), maxIf(dateDiff('seconds', create_time, last_exception_time), (last_exception_time != '1970-01-01') AND (last_exception_time > (now() - toIntervalMinute(5))))] AS `values`,
+ ['Number of entries that have been in the replication queue for more than 15 days', 'Maximum number of seconds that an entry has been postponed', 'Maximum number of seconds that an entry has been in error'] AS descriptions,
+ ['gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('table', `table`, 'instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.replication_queue
+GROUP BY
+ `table`
+HAVING
+ value > 0;
+CREATE VIEW posthog.custom_metrics_server_crash AS SELECT
+ 'ClickHouseCustomMetric_ServerCrash' AS name,
+ map('instance', hostname()) AS labels,
+ count() AS value,
+ 'Number of server crashes for current date' AS help,
+ 'gauge' AS type
+FROM system.crash_log
+WHERE event_date = today()
+GROUP BY
+ hostname();
+CREATE VIEW posthog.custom_metrics_table_sizes AS SELECT
+ 'ClickHouseCustomMetric_TableTotalBytes' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`) AS labels,
+ CAST(total_bytes, 'Float64') AS value,
+ 'Size of a database table on a given node (need a sum for sharded)' AS help,
+ 'gauge' AS type
+FROM system.tables
+WHERE
+ (database NOT IN ('INFORMATION_SCHEMA', 'information_schema'))
+AND
+ (total_bytes IS NOT NULL);
+CREATE VIEW posthog.custom_metrics_test AS SELECT
+ 'ClickHouseCustomMetric_Test' AS name,
+ map('instance', hostname()) AS labels,
+ 1 AS value,
+ 'Test to check that the metric endpoint is working' AS help,
+ 'gauge' AS type;
+CREATE VIEW posthog.events_batch_export_recent AS SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ inserted_at AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events_recent
+PREWHERE
+ (events_recent.inserted_at >= {interval_start: DateTime64}) AND (events_recent.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events_recent.distinct_id), cityHash64(events_recent.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1;
+CREATE VIEW posthog.persons_batch_export AS WITH
+ new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
+ new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
+ all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
+SELECT
+ p.team_id AS team_id,
+ pd.distinct_id AS distinct_id,
+ toString(p.id) AS person_id,
+ p.properties AS properties,
+ pd.version AS person_distinct_id_version,
+ p.version AS person_version,
+ p.created_at AS created_at,
+ multiIf(
+ ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
+ pd._timestamp,
+ ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
+ p._timestamp,
+ least(p._timestamp, pd._timestamp)
+ ) AS _inserted_at
+FROM
+ posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((id, version) IN (all_new_persons))
+ORDER BY _inserted_at ASC;
+CREATE VIEW posthog.raw_sessions_v AS SELECT
+ session_id_v7,
+ fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)) AS session_timestamp,
+ team_id,
+ argMaxMerge(distinct_id) AS distinct_id,
+ 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(initial_browser) AS initial_browser,
+ argMinMerge(initial_browser_version) AS initial_browser_version,
+ argMinMerge(initial_os) AS initial_os,
+ argMinMerge(initial_os_version) AS initial_os_version,
+ argMinMerge(initial_device_type) AS initial_device_type,
+ argMinMerge(initial_viewport_width) AS initial_viewport_width,
+ argMinMerge(initial_viewport_height) AS initial_viewport_height,
+ argMinMerge(initial_geoip_country_code) AS initial_geoip_country_code,
+ argMinMerge(initial_geoip_subdivision_1_code) AS initial_geoip_subdivision_1_code,
+ argMinMerge(initial_geoip_subdivision_1_name) AS initial_geoip_subdivision_1_name,
+ argMinMerge(initial_geoip_subdivision_city_name) AS initial_geoip_subdivision_city_name,
+ argMinMerge(initial_geoip_time_zone) AS initial_geoip_time_zone,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ argMinMerge(initial__kx) AS initial__kx,
+ argMinMerge(initial_irclid) AS initial_irclid,
+ sum(pageview_count) AS pageview_count,
+ uniqMerge(pageview_uniq) AS pageview_uniq,
+ sum(autocapture_count) AS autocapture_count,
+ uniqMerge(autocapture_uniq) AS autocapture_uniq,
+ sum(screen_count) AS screen_count,
+ uniqMerge(screen_uniq) AS screen_uniq,
+ max(maybe_has_session_replay) AS maybe_has_session_replay,
+ uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,
+ argMinMerge(vitals_lcp) AS vitals_lcp
+FROM posthog.raw_sessions
+GROUP BY
+ session_id_v7, team_id;
+CREATE VIEW posthog.raw_sessions_v3_v AS 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;
+CREATE VIEW posthog.sessions_v AS SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(exit_url) AS exit_url,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ sumMap(event_count_map) AS event_count_map,
+ sum(pageview_count) AS pageview_count,
+ sum(autocapture_count) AS autocapture_count
+FROM posthog.sessions
+GROUP BY
+ session_id, team_id;
+CREATE OR REPLACE DICTIONARY posthog.channel_definition_dict (`domain` String, `kind` String, `domain_type` Nullable(String), `type_if_paid` Nullable(String), `type_if_organic` Nullable(String)) PRIMARY KEY domain, kind SOURCE(CLICKHOUSE(USER 'dict_reader' TABLE 'channel_definition')) LAYOUT(COMPLEX_KEY_HASHED()) LIFETIME(MIN 3000 MAX 3600);
+CREATE OR REPLACE DICTIONARY posthog.web_bot_definition_dict (`regexp` String, `name` String, `category` String, `traffic_type` String, `operator` String) PRIMARY KEY regexp SOURCE(CLICKHOUSE(USER 'default' DB 'posthog' TABLE 'web_bot_definition')) LAYOUT(REGEXP_TREE()) LIFETIME(MIN 3000 MAX 3600);
+CREATE OR REPLACE DICTIONARY posthog.web_pre_aggregated_teams_dict (`team_id` UInt64) PRIMARY KEY team_id SOURCE(CLICKHOUSE(USER 'dict_reader' QUERY 'SELECT team_id FROM `web_pre_aggregated_teams` FINAL WHERE version > 0')) LAYOUT(HASHED()) LIFETIME(MIN 3000 MAX 3600);
+CREATE TABLE posthog.app_metrics2 (
+ team_id Int64,
+ timestamp DateTime64(6, 'UTC'),
+ app_source LowCardinality(String),
+ app_source_id String,
+ instance_id String,
+ metric_kind LowCardinality(String),
+ metric_name LowCardinality(String),
+ count SimpleAggregateFunction(sum, Int64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_app_metrics2', rand());
+CREATE TABLE posthog.distinct_id_usage (
+ team_id Int64,
+ distinct_id String,
+ minute DateTime,
+ event_count UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_distinct_id_usage', sipHash64(distinct_id));
+CREATE TABLE posthog.distributed_posthog_document_embeddings_text_embedding_3_large_3072 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_large_3072', cityHash64(document_id));
+CREATE TABLE posthog.distributed_posthog_document_embeddings_text_embedding_3_small_1536 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_small_1536', cityHash64(document_id));
+CREATE TABLE posthog.events (
+ uuid UUID,
+ event String,
+ properties String CODEC(ZSTD(3)),
+ 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),
+ $group_0 String COMMENT 'column_materializer::$group_0',
+ $group_1 String COMMENT 'column_materializer::$group_1',
+ $group_2 String COMMENT 'column_materializer::$group_2',
+ $group_3 String COMMENT 'column_materializer::$group_3',
+ $group_4 String COMMENT 'column_materializer::$group_4',
+ $window_id String COMMENT 'column_materializer::$window_id',
+ $session_id String COMMENT 'column_materializer::$session_id',
+ _timestamp DateTime,
+ _offset UInt64,
+ inserted_at Nullable(DateTime64(6, 'UTC')) DEFAULT now64(),
+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),
+ mat_metadata_backend String COMMENT 'column_materializer::properties::metadata.backend',
+ mat_metadata_loggedIn String COMMENT 'column_materializer::properties::metadata.loggedIn',
+ 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_feature_flags Map(String, String),
+ is_deleted Bool,
+ person_properties_map_custom Map(String, String),
+ mat_$ai_trace_id Nullable(String) COMMENT 'column_materializer::properties::$ai_trace_id',
+ $session_id_uuid Nullable(UInt128),
+ consumer_breadcrumbs Array(String),
+ properties_group_ai Map(String, String),
+ mat_historical_migration Nullable(String) COMMENT 'column_materializer::properties::historical_migration',
+ 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',
+ 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.experiment_exposures_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ entity_id String,
+ variant String,
+ first_exposure_time DateTime64(6, 'UTC'),
+ last_exposure_time DateTime64(6, 'UTC'),
+ exposure_event_uuid UUID,
+ exposure_session_id String,
+ breakdown_value Array(String),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_experiment_exposures_preaggregated', cityHash64(entity_id));
+CREATE TABLE posthog.flag_evaluations (
+ uuid UUID,
+ event LowCardinality(String),
+ properties String,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ created_at DateTime64(6, 'UTC'),
+ person_id UUID,
+ inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,
+ $group_0 String COMMENT 'column_materializer::$group_0',
+ $group_1 String COMMENT 'column_materializer::$group_1',
+ $group_2 String COMMENT 'column_materializer::$group_2',
+ $group_3 String COMMENT 'column_materializer::$group_3',
+ $group_4 String COMMENT 'column_materializer::$group_4',
+ flag_key String COMMENT 'column_materializer::properties::$feature_flag',
+ response LowCardinality(String) COMMENT 'column_materializer::properties::$feature_flag_response',
+ session_id String COMMENT 'column_materializer::properties::$session_id',
+ request_id String COMMENT 'column_materializer::properties::$feature_flag_request_id',
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_flag_evaluations', sipHash64(distinct_id));
+CREATE TABLE posthog.heatmaps (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ timestamp DateTime64(6, 'UTC'),
+ x Int16,
+ y Int16,
+ scale_factor Int16,
+ viewport_width Int16,
+ viewport_height Int16,
+ pointer_target_fixed Bool,
+ current_url String,
+ type LowCardinality(String),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_heatmaps', cityHash64(concat(toString(team_id), '-', session_id, '-', toString(toDate(timestamp)))));
+CREATE TABLE posthog.log_entries (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_log_entries', rand());
+CREATE TABLE posthog.performance_events (
+ uuid UUID,
+ session_id String,
+ window_id String,
+ pageview_id String,
+ distinct_id String,
+ timestamp DateTime64(3),
+ time_origin DateTime64(3, 'UTC'),
+ entry_type LowCardinality(String),
+ name String,
+ team_id Int64,
+ current_url String,
+ start_time Float64,
+ duration Float64,
+ redirect_start Float64,
+ redirect_end Float64,
+ worker_start Float64,
+ fetch_start Float64,
+ domain_lookup_start Float64,
+ domain_lookup_end Float64,
+ connect_start Float64,
+ secure_connection_start Float64,
+ connect_end Float64,
+ request_start Float64,
+ response_start Float64,
+ response_end Float64,
+ decoded_body_size Int64,
+ encoded_body_size Int64,
+ initiator_type LowCardinality(String),
+ next_hop_protocol LowCardinality(String),
+ render_blocking_status LowCardinality(String),
+ response_status Int64,
+ transfer_size Int64,
+ largest_contentful_paint_element String,
+ largest_contentful_paint_render_time Float64,
+ largest_contentful_paint_load_time Float64,
+ largest_contentful_paint_size Float64,
+ largest_contentful_paint_id String,
+ largest_contentful_paint_url String,
+ dom_complete Float64,
+ dom_content_loaded_event Float64,
+ dom_interactive Float64,
+ load_event_end Float64,
+ load_event_start Float64,
+ redirect_count Int64,
+ navigation_type LowCardinality(String),
+ unload_event_end Float64,
+ unload_event_start Float64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_performance_events', sipHash64(session_id));
+CREATE TABLE posthog.preaggregation_results (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7),
+ breakdown_value Array(String),
+ uniq_exact_state AggregateFunction(uniqExact, UUID)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_preaggregation_results', sipHash64(job_id));
+CREATE TABLE posthog.session_recording_events (
+ uuid UUID,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ session_id String,
+ window_id String,
+ snapshot_data String,
+ created_at DateTime64(6, 'UTC'),
+ has_full_snapshot Int8 COMMENT 'column_materializer::has_full_snapshot',
+ _timestamp DateTime,
+ _offset UInt64,
+ events_summary Array(String) COMMENT 'column_materializer::events_summary',
+ click_count Int8 COMMENT 'column_materializer::click_count',
+ keypress_count Int8 COMMENT 'column_materializer::keypress_count',
+ timestamps_summary Array(DateTime64(6, 'UTC')) COMMENT 'column_materializer::timestamps_summary',
+ first_event_timestamp DateTime64(6, 'UTC') COMMENT 'column_materializer::first_event_timestamp',
+ last_event_timestamp DateTime64(6, 'UTC') COMMENT 'column_materializer::last_event_timestamp',
+ urls Array(String) COMMENT 'column_materializer::urls'
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_recording_events', sipHash64(distinct_id));
+CREATE TABLE posthog.session_replay_embeddings (
+ session_id String,
+ team_id Int64,
+ embeddings Array(Float32),
+ generation_timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ source_type LowCardinality(String),
+ input String
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_embeddings', sipHash64(session_id));
+CREATE TABLE posthog.session_replay_events (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ active_milliseconds SimpleAggregateFunction(sum, Int64),
+ console_log_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ size SimpleAggregateFunction(sum, Int64),
+ message_count SimpleAggregateFunction(sum, Int64),
+ event_count SimpleAggregateFunction(sum, Int64),
+ _timestamp SimpleAggregateFunction(max, DateTime),
+ snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
+CREATE VIEW posthog.custom_metrics AS SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_test
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_replication_queue
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_server_crash
+UNION ALL
+SELECT *
+FROM posthog.custom_metrics_table_sizes
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_part_counts
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_dictionaries
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_S3DiskBytesUsed' AS name,
+ map('instance', hostname(), 'disk', disk_name) AS labels,
+ toFloat64(sum(bytes_on_disk)) AS value,
+ 'Bytes currently used by ClickHouse parts on S3-backed disks on this node' AS help,
+ 'gauge' AS type
+FROM system.parts
+WHERE disk_name IN ('s3disk', 'cache')
+GROUP BY
+ disk_name
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeFailures15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(count()) AS value,
+ 'Number of failed merge operations in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM system.part_log
+WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+AND
+ (event_type = 'MergeParts')
+AND
+ (error > 0)
+AND
+ (merge_reason != 'NotAMerge')
+AND
+ (error != 40)
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeRetriesMaxPerTable15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(max(cnt)) AS value,
+ 'Max failed merge retries for any single table in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT count() AS cnt
+ FROM system.part_log
+ WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+ AND
+ (event_type = 'MergeParts')
+ AND
+ (error > 0)
+ AND
+ (merge_reason != 'NotAMerge')
+ AND
+ (error != 40)
+ GROUP BY
+ database, `table`, partition_id
+ );
+CREATE VIEW posthog.events_batch_export AS SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ (events.timestamp >= ({interval_start: DateTime64} - toIntervalDay({lookback_days: Int32})))
+AND
+ (events.timestamp < ({interval_end: DateTime64} + toIntervalDay(1)))
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1;
+CREATE VIEW posthog.events_batch_export_unbounded AS SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1;
+CREATE VIEW posthog.posthog_document_embeddings_union_view AS SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-small-1536' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_small_1536
+UNION ALL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-large-3072' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_large_3072;
diff --git a/posthog/clickhouse/hcl/sql/prod-us/data.sql b/posthog/clickhouse/hcl/sql/prod-us/data.sql
new file mode 100644
index 000000000000..fcef5b8f24c9
--- /dev/null
+++ b/posthog/clickhouse/hcl/sql/prod-us/data.sql
@@ -0,0 +1,3215 @@
+-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit.
+-- Full CREATE schema for the prod-us/data node. Apply to a fresh ClickHouse to build it.
+
+CREATE TABLE posthog.adhoc_events_deletion (
+ team_id Int64,
+ uuid UUID,
+ created_at DateTime64(6, 'UTC') DEFAULT now64(),
+ deleted_at DateTime,
+ is_deleted UInt8 DEFAULT 0
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.adhoc_events_deletion', '{replica}-{shard}', deleted_at, is_deleted) ORDER BY (team_id, uuid) TTL deleted_at + toIntervalMonth(3) WHERE is_deleted = 1 SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.ai_events (
+ uuid UUID,
+ event LowCardinality(String),
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ properties String,
+ retention_days Int16 DEFAULT 30,
+ drop_date Date MATERIALIZED toDate(timestamp) + toIntervalDay(retention_days),
+ trace_id String,
+ session_id Nullable(String),
+ parent_id Nullable(String),
+ span_id Nullable(String),
+ span_type LowCardinality(Nullable(String)),
+ generation_id Nullable(String),
+ experiment_id Nullable(String),
+ span_name Nullable(String),
+ trace_name Nullable(String),
+ prompt_name Nullable(String),
+ model LowCardinality(Nullable(String)),
+ provider LowCardinality(Nullable(String)),
+ framework LowCardinality(Nullable(String)),
+ total_tokens Nullable(Int64),
+ input_tokens Nullable(Int64),
+ output_tokens Nullable(Int64),
+ text_input_tokens Nullable(Int64),
+ text_output_tokens Nullable(Int64),
+ image_input_tokens Nullable(Int64),
+ image_output_tokens Nullable(Int64),
+ audio_input_tokens Nullable(Int64),
+ audio_output_tokens Nullable(Int64),
+ video_input_tokens Nullable(Int64),
+ video_output_tokens Nullable(Int64),
+ reasoning_tokens Nullable(Int64),
+ cache_read_input_tokens Nullable(Int64),
+ cache_creation_input_tokens Nullable(Int64),
+ web_search_count Nullable(Int64),
+ input_cost_usd Nullable(Float64),
+ output_cost_usd Nullable(Float64),
+ total_cost_usd Nullable(Float64),
+ request_cost_usd Nullable(Float64),
+ web_search_cost_usd Nullable(Float64),
+ audio_cost_usd Nullable(Float64),
+ image_cost_usd Nullable(Float64),
+ video_cost_usd Nullable(Float64),
+ latency Nullable(Float64),
+ time_to_first_token Nullable(Float64),
+ is_error UInt8,
+ error Nullable(String),
+ error_type LowCardinality(Nullable(String)),
+ error_normalized Nullable(String),
+ input Nullable(String),
+ output Nullable(String),
+ output_choices Nullable(String),
+ input_state Nullable(String),
+ output_state Nullable(String),
+ tools Nullable(String),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('ai_events', 'posthog', 'ai_events', rand());
+CREATE TABLE posthog.async_deletion_run (
+ id UInt64,
+ deletion_type UInt8,
+ key String,
+ group_type_index String,
+ team_id Int64
+) ENGINE = Join(ANY, LEFT, team_id, deletion_type, key);
+CREATE TABLE posthog.asyncdeletion (
+ id UInt64,
+ deletion_type UInt8,
+ key String,
+ group_type_index UInt64,
+ created_at DateTime,
+ delete_verified_at DateTime,
+ created_by_id UInt64,
+ team_id UInt64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/asyncdeletion', '{replica}-{shard}') ORDER BY (deletion_type, delete_verified_at) PARTITION BY toYYYYMM(created_at) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.asyncdeletion_join (
+ id UInt64,
+ deletion_type UInt8,
+ key String,
+ group_type_index UInt64,
+ created_at DateTime,
+ delete_verified_at DateTime,
+ created_by_id UInt64,
+ team_id UInt64
+) ENGINE = Join(ANY, LEFT, team_id, key);
+CREATE TABLE posthog.billing_usage_records (
+ schema_version UInt8,
+ record_id String,
+ producer_id LowCardinality(String),
+ team_id Int64,
+ organization_id UUID,
+ usage_key LowCardinality(String),
+ unit LowCardinality(String),
+ quantity Int64,
+ timestamp DateTime64(6, 'UTC'),
+ inserted_at DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'sharded_billing_usage_records', cityHash64(team_id));
+CREATE TABLE posthog.channel_definition (
+ domain String,
+ kind String,
+ domain_type Nullable(String),
+ type_if_paid Nullable(String),
+ type_if_organic Nullable(String)
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.channel_definition', '{replica}-{shard}') ORDER BY (domain, kind) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.clickhouse_cleanup_deleted_persons (
+ run_id String,
+ team_id Int64,
+ person_id UUID,
+ max_version UInt64,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, person_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.clickhouse_cleanup_orphaned_distinct_ids (
+ run_id String,
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ own_tombstone UInt8,
+ max_version Int64,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, distinct_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.clickhouse_cleanup_revived_distinct_ids (
+ run_id String,
+ team_id Int64,
+ distinct_id String,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, distinct_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.clickhouse_cleanup_revived_persons (
+ run_id String,
+ team_id Int64,
+ person_id UUID,
+ created_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons', '{replica}-{shard}', created_at) ORDER BY (run_id, team_id, person_id) PARTITION BY run_id TTL created_at + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.cohort_membership (
+ team_id Int64,
+ cohort_id Int64,
+ person_id UUID,
+ status Enum8('entered'=1, 'left'=2),
+ last_updated DateTime64(6) DEFAULT now64()
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/prod/tables/posthog.cohort_membership', '{replica}-{shard}', last_updated) ORDER BY (team_id, cohort_id, person_id) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.cohortpeople (
+ person_id UUID,
+ cohort_id Int64,
+ team_id Int64,
+ sign Int8,
+ version UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.cohortpeople_new_partitioned', '{replica}-{shard}', version) ORDER BY (team_id, cohort_id, person_id) PARTITION BY team_id % 16 SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.conversion_goal_attributed_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ person_id UUID,
+ conversion_timestamp DateTime64(6, 'UTC'),
+ conversion_value Float64,
+ touchpoint_timestamp DateTime64(6, 'UTC'),
+ touchpoint_weight Float64,
+ campaign_name String,
+ source_name String,
+ medium_name String,
+ content_name String,
+ term_name String,
+ referring_domain_name String,
+ gclid_name String,
+ fbclid_name String,
+ gad_source_name String,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_conversion_goal_attributed_preaggregated', cityHash64(person_id));
+CREATE TABLE posthog.distributed_events_recent (
+ uuid UUID,
+ event String,
+ properties String CODEC(ZSTD(3)),
+ 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),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ inserted_at DateTime64(6, 'UTC') DEFAULT now64(),
+ _timestamp_ms DateTime64(3)
+) ENGINE = Distributed('batch_exports', 'posthog', 'sharded_events_recent', sipHash64(distinct_id));
+CREATE TABLE posthog.distributed_posthog_document_embeddings (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ model_name LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings', cityHash64(document_id));
+CREATE TABLE posthog.distributed_system_processes (
+ is_initial_query UInt8,
+ user String,
+ query_id String,
+ address IPv6,
+ port UInt16,
+ initial_user String,
+ initial_query_id String,
+ initial_address IPv6,
+ initial_port UInt16,
+ interface UInt8,
+ os_user String,
+ client_hostname String,
+ client_name String,
+ client_revision UInt64,
+ client_version_major UInt64,
+ client_version_minor UInt64,
+ client_version_patch UInt64,
+ http_method UInt8,
+ http_user_agent String,
+ http_referer String,
+ forwarded_for String,
+ quota_key String,
+ distributed_depth UInt64,
+ elapsed Float64,
+ is_cancelled UInt8,
+ is_all_data_sent UInt8,
+ read_rows UInt64,
+ read_bytes UInt64,
+ total_rows_approx UInt64,
+ written_rows UInt64,
+ written_bytes UInt64,
+ memory_usage Int64,
+ peak_memory_usage Int64,
+ query String,
+ query_kind String,
+ thread_ids Array(UInt64),
+ ProfileEvents Map(String, UInt64),
+ Settings Map(String, String),
+ current_database String,
+ ProfileEvents.Names Array(String) ALIAS mapKeys(ProfileEvents),
+ ProfileEvents.Values Array(UInt64) ALIAS mapValues(ProfileEvents),
+ Settings.Names Array(String) ALIAS mapKeys(Settings),
+ Settings.Values Array(String) ALIAS mapValues(Settings)
+) ENGINE = Distributed('posthog', 'system', 'processes') SETTINGS skip_unavailable_shards = 1;
+CREATE TABLE posthog.duplicate_events (
+ team_id Int64,
+ distinct_id String,
+ event String,
+ source_uuid UUID,
+ duplicate_uuid UUID,
+ similarity_score Float64,
+ dedup_type LowCardinality(String),
+ is_confirmed UInt8,
+ reason Nullable(String),
+ version String,
+ different_property_count UInt32,
+ properties_similarity Float64,
+ source_message String,
+ duplicate_message String,
+ distinct_fields Array(Tuple(field_name String, original_value String, new_value String)),
+ inserted_at DateTime64(3, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX kafka_timestamp_minmax_duplicate_events _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.duplicate_events', '{replica}-{shard}') ORDER BY (team_id, distinct_id, event, inserted_at) PARTITION BY toYYYYMMDD(inserted_at) TTL inserted_at + toIntervalDay(7) SETTINGS default_compression_codec = 'lz4', index_granularity = 512;
+CREATE TABLE posthog.error_tracking_fingerprint_issue_state (
+ team_id Int64,
+ fingerprint String,
+ issue_id UUID,
+ issue_name Nullable(String),
+ issue_description Nullable(String),
+ issue_status String,
+ issue_severity Nullable(String),
+ assigned_user_id Nullable(Int64),
+ assigned_role_id Nullable(UUID),
+ first_seen DateTime64(3, 'UTC'),
+ is_deleted Int8,
+ version Int64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'raw_error_tracking_fingerprint_issue_state');
+CREATE TABLE posthog.error_tracking_issue_fingerprint_overrides (
+ team_id Int64,
+ fingerprint String,
+ issue_id UUID,
+ is_deleted Int8,
+ version Int64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX kafka_timestamp_minmax_error_tracking_issue_fingerprint_overrides _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.error_tracking_issue_fingerprint_overrides', '{replica}-{shard}', version) ORDER BY (team_id, fingerprint) SETTINGS default_compression_codec = 'lz4', index_granularity = 512;
+CREATE TABLE posthog.events_dead_letter_queue (
+ id UUID,
+ event_uuid UUID,
+ event String,
+ properties String,
+ distinct_id String,
+ team_id Int64,
+ elements_chain String,
+ created_at DateTime64(6, 'UTC'),
+ ip String,
+ site_url String,
+ now DateTime64(6, 'UTC'),
+ raw_payload String,
+ error_timestamp DateTime64(6, 'UTC'),
+ error_location String,
+ error String,
+ tags Array(String),
+ _timestamp DateTime,
+ _offset UInt64,
+ INDEX kafka_timestamp_minmax _timestamp TYPE minmax GRANULARITY 3,
+ INDEX kafka_timestamp_minmax_events_dead_letter_queue _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.new_events_dead_letter_queue_2', '{replica}-{shard}', _timestamp) ORDER BY (id, event_uuid, distinct_id, team_id) TTL toDate(_timestamp) + toIntervalWeek(4) SETTINGS default_compression_codec = 'lz4', index_granularity = 512;
+CREATE TABLE posthog.events_recent (
+ uuid UUID,
+ event String,
+ properties String,
+ 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,
+ group0_properties String,
+ group1_properties String,
+ group2_properties String,
+ group3_properties String,
+ group4_properties String,
+ 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),
+ _timestamp DateTime,
+ _offset UInt64,
+ inserted_at DateTime64(6, 'UTC')
+) ENGINE = Distributed('batch_exports', 'posthog', 'sharded_events_recent', sipHash64(distinct_id));
+CREATE TABLE posthog.exchange_rate (
+ currency String,
+ date Date,
+ rate Decimal(18, 10),
+ version UInt32 DEFAULT toUnixTimestamp(now())
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.exchange_rate', '{replica}-{shard}', version) ORDER BY (date, currency) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.experiment_metric_events_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ entity_id String,
+ timestamp DateTime64(6, 'UTC'),
+ event_uuid UUID,
+ session_id String,
+ numeric_value Float64 DEFAULT 0,
+ steps Array(UInt8) DEFAULT [],
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_experiment_metric_events_preaggregated', cityHash64(entity_id));
+CREATE TABLE posthog.groups (
+ group_type_index UInt8,
+ group_key String,
+ created_at DateTime64(3),
+ team_id Int64,
+ group_properties String,
+ _timestamp DateTime,
+ _offset UInt64,
+ is_deleted Bool,
+ INDEX is_deleted_idx is_deleted TYPE minmax GRANULARITY 1
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.groups', '{replica}-{shard}', _timestamp) ORDER BY (team_id, group_type_index, group_key) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.hog_invocation_results (
+ team_id Int64,
+ function_kind LowCardinality(String),
+ function_id String,
+ invocation_id String,
+ parent_run_id String,
+ status LowCardinality(String),
+ attempts UInt8,
+ is_retry UInt8,
+ scheduled_at DateTime64(6, 'UTC'),
+ first_scheduled_at DateTime64(6, 'UTC'),
+ started_at Nullable(DateTime64(6, 'UTC')),
+ finished_at Nullable(DateTime64(6, 'UTC')),
+ duration_ms Nullable(UInt32),
+ error_kind LowCardinality(String),
+ error_message String,
+ event_uuid String,
+ distinct_id String,
+ person_id String,
+ invocation_globals String,
+ version UInt64,
+ is_deleted UInt8,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'hog_invocation_results_data');
+CREATE TABLE posthog.ingestion_warnings (
+ team_id Int64,
+ source LowCardinality(String),
+ type String,
+ details String CODEC(ZSTD(3)),
+ timestamp DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'sharded_ingestion_warnings', rand());
+CREATE TABLE posthog.ingestion_warnings_v2_distributed (
+ team_id Int64,
+ source LowCardinality(String),
+ type LowCardinality(String),
+ details String,
+ timestamp DateTime64(6, 'UTC'),
+ category LowCardinality(String) DEFAULT coalesce(nullIf(JSONExtractString(details, 'category'), ''), 'unknown'),
+ severity LowCardinality(String) DEFAULT coalesce(nullIf(JSONExtractString(details, 'severity'), ''), 'warning'),
+ pipeline_step LowCardinality(String) DEFAULT coalesce(nullIf(JSONExtractString(details, 'pipelineStep'), ''), 'unknown'),
+ event_uuid Nullable(UUID) DEFAULT toUUIDOrNull(JSONExtractString(details, 'eventUuid')),
+ distinct_id Nullable(String) DEFAULT nullIf(JSONExtractString(details, 'distinctId'), ''),
+ group_key Nullable(String) DEFAULT nullIf(JSONExtractString(details, 'groupKey'), ''),
+ person_id Nullable(UUID) DEFAULT toUUIDOrNull(JSONExtractString(details, 'personId')),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'ingestion_warnings_v2');
+CREATE TABLE posthog.llma_metrics_daily (
+ date Date,
+ team_id UInt64,
+ metric_name String,
+ metric_value Float64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.llma_metrics_daily', '{replica}-{shard}') ORDER BY (team_id, date, metric_name) PARTITION BY toYYYYMM(date) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.log_entries_distributed (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('aux', 'posthog', 'log_entries_data');
+CREATE TABLE posthog.marketing_conversions_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ person_id UUID,
+ conversion_timestamp DateTime64(6, 'UTC'),
+ conversion_math_value Float64,
+ session_id String,
+ campaign_name String,
+ source_name String,
+ medium_name String,
+ content_name String,
+ term_name String,
+ referring_domain_name String,
+ gclid_name String,
+ fbclid_name String,
+ gad_source_name String,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_marketing_conversions_preaggregated', cityHash64(person_id));
+CREATE TABLE posthog.marketing_costs_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ source_id String,
+ source_name String,
+ grain LowCardinality(String),
+ match_key String,
+ campaign_id String,
+ campaign_name String,
+ ad_group_id String,
+ ad_group_name String,
+ ad_id String,
+ ad_name String,
+ cost_date Date,
+ cost Float64,
+ clicks Float64,
+ impressions Float64,
+ reported_conversions Float64,
+ reported_conversion_value Float64,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_marketing_costs_preaggregated', cityHash64(source_name, campaign_id));
+CREATE TABLE posthog.marketing_touchpoints_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ person_id UUID,
+ touchpoint_timestamp DateTime64(6, 'UTC'),
+ campaign_name String,
+ source_name String,
+ medium_name String,
+ content_name String,
+ term_name String,
+ referring_domain_name String,
+ gclid_name String,
+ fbclid_name String,
+ gad_source_name String,
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_marketing_touchpoints_preaggregated', cityHash64(person_id));
+CREATE TABLE posthog.message_assets (
+ team_id Int64,
+ function_kind LowCardinality(String),
+ function_id String,
+ parent_run_id String,
+ invocation_id String,
+ action_id String,
+ kind LowCardinality(String),
+ distinct_id String,
+ person_id String,
+ recipient String,
+ subject String,
+ status LowCardinality(String),
+ sent_at DateTime64(6, 'UTC'),
+ version UInt64,
+ is_deleted UInt8,
+ html String,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('aux', 'posthog', 'message_assets_data');
+CREATE TABLE posthog.new_raw_sessions (
+ team_id Int64,
+ session_id_v7 UInt128,
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_browser AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_browser_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_device_type AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_viewport_width AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_viewport_height AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_geoip_country_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_city_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_time_zone AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_irclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ pageview_uniq AggregateFunction(uniq, Nullable(UUID)),
+ autocapture_count SimpleAggregateFunction(sum, Int64),
+ autocapture_uniq AggregateFunction(uniq, Nullable(UUID)),
+ screen_count SimpleAggregateFunction(sum, Int64),
+ screen_uniq AggregateFunction(uniq, Nullable(UUID)),
+ maybe_has_session_replay SimpleAggregateFunction(max, Bool),
+ page_screen_autocapture_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),
+ vitals_lcp AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC')),
+ initial__kx AggregateFunction(argMin, String, DateTime64(6, 'UTC'))
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_raw_sessions', cityHash64(session_id_v7));
+CREATE TABLE posthog.new_sessions (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_sessions', sipHash64(session_id));
+CREATE TABLE posthog.pending_person_deletes_reporting (
+ id UInt64,
+ deletion_type UInt8,
+ key String,
+ group_type_index Nullable(String),
+ created_at DateTime,
+ delete_verified_at Nullable(DateTime),
+ created_by_id Nullable(String),
+ team_id Int64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/pending_person_deletes_reporting', '{shard}-{replica}') ORDER BY (team_id, deletion_type, key) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.person (
+ id UUID,
+ created_at DateTime,
+ team_id Int64,
+ properties String,
+ is_identified Int8,
+ _timestamp DateTime,
+ _offset UInt64,
+ is_deleted Int8 DEFAULT 0,
+ version UInt64,
+ _partition UInt32,
+ last_seen_at Nullable(DateTime64(3))
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/am0005_20220623103132_noshard/posthog.person', '{replica}-{shard}', version) ORDER BY (team_id, id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.person_collapsing (
+ id UUID,
+ created_at DateTime64(3),
+ team_id Int64,
+ properties String,
+ is_identified Int8,
+ _timestamp DateTime,
+ _offset UInt64,
+ _sign Int8
+) ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/prod/tables/noshard/posthog.person_collapsing', '{replica}-{shard}', _sign) ORDER BY (team_id, id) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.person_distinct_id (
+ distinct_id String COMMENT 'skip_0003_fill_person_distinct_id2',
+ person_id UUID,
+ team_id Int64,
+ _sign Int8 DEFAULT 1,
+ is_deleted Int8 ALIAS if(_sign = -1, 1, 0),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/tables/noshard/posthog.person_distinct_id-swap2-2021-08-18', '{replica}-{shard}', _sign) ORDER BY (team_id, distinct_id, person_id) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.person_distinct_id2 (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ is_deleted Int8,
+ version Int64 DEFAULT 1,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_distinct_id2', '{replica}-{shard}', version) ORDER BY (team_id, distinct_id) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.person_distinct_id_overrides (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ is_deleted Int8,
+ version Int64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX kafka_timestamp_minmax_person_distinct_id_overrides _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_distinct_id_overrides', '{replica}-{shard}', version) ORDER BY (team_id, distinct_id) SETTINGS default_compression_codec = 'lz4', index_granularity = 512;
+CREATE TABLE posthog.person_distinct_id_overrides_join_table (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID
+) ENGINE = Join(ANY, LEFT, team_id, distinct_id);
+CREATE TABLE posthog.person_distinct_id_overrides_to_delete (
+ team_id Int64,
+ distinct_id String,
+ version Int64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_distinct_id_overrides_to_delete', '{replica}-{shard}', version) ORDER BY (team_id, distinct_id) SETTINGS default_compression_codec = 'lz4', index_granularity = 512;
+CREATE TABLE posthog.person_distinct_id_overrides_to_delete_join (
+ team_id Int64,
+ distinct_id String,
+ version Int64
+) ENGINE = Join(ANY, LEFT, team_id, distinct_id);
+CREATE TABLE posthog.person_overrides (
+ team_id Int32,
+ old_person_id UUID,
+ override_person_id UUID,
+ merged_at DateTime64(6, 'UTC'),
+ oldest_event DateTime64(6, 'UTC'),
+ created_at DateTime64(6, 'UTC') DEFAULT now(),
+ version Int32
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_overrides', '{replica}-{shard}', version) ORDER BY (team_id, old_person_id) PARTITION BY toYYYYMM(oldest_event) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.person_overrides_join_table (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID
+) ENGINE = Join(ANY, LEFT, team_id, distinct_id);
+CREATE TABLE posthog.person_overrides_to_delete (
+ team_id Int64,
+ distinct_id String,
+ partitions Array(String)
+) ENGINE = Join(ANY, LEFT, team_id, distinct_id);
+CREATE TABLE posthog.person_static_cohort (
+ id UUID,
+ person_id UUID,
+ cohort_id Int64,
+ team_id Int64,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/prod/tables/noshard/person_static_cohort', '{replica}-{shard}', _timestamp) ORDER BY (team_id, cohort_id, person_id, id) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.pg_embeddings (
+ domain String,
+ team_id Int64,
+ id String,
+ vector Array(Float32),
+ text String,
+ properties String CODEC(ZSTD(3)),
+ timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ is_deleted UInt8
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.pg_embeddings', '{replica}-{shard}', timestamp, is_deleted) ORDER BY (team_id, domain, id) SETTINGS default_compression_codec = 'lz4', index_granularity = 512;
+CREATE TABLE posthog.plugin_log_entries (
+ id UUID,
+ team_id Int64,
+ plugin_id Int64,
+ plugin_config_id Int64,
+ timestamp DateTime64(6, 'UTC'),
+ source String,
+ type String,
+ message String,
+ instance_id UUID,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.plugin_log_entries', '{replica}-{shard}', _timestamp) ORDER BY (team_id, plugin_id, plugin_config_id, timestamp) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(timestamp) + toIntervalWeek(1) SETTINGS default_compression_codec = 'lz4', index_granularity = 512;
+CREATE TABLE posthog.property_definitions (
+ team_id UInt32,
+ project_id Nullable(UInt32),
+ name String,
+ property_type Nullable(String),
+ event Nullable(String),
+ group_type_index Nullable(UInt8),
+ type UInt8 DEFAULT 1,
+ last_seen_at DateTime,
+ version UInt64 MATERIALIZED bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.property_definitions', '{replica}-{shard}', version) ORDER BY (team_id, type, coalesce(event, ''), name, coalesce(group_type_index, 255)) SETTINGS always_fetch_merged_part = 0, default_compression_codec = 'lz4', index_granularity = 8192, replicated_can_become_leader = 1;
+CREATE TABLE posthog.property_values_distributed (
+ team_id Int64 CODEC(DoubleDelta, ZSTD(1)),
+ property_type LowCardinality(String),
+ property_key LowCardinality(String),
+ property_value String,
+ property_count SimpleAggregateFunction(sum, UInt64),
+ last_seen SimpleAggregateFunction(max, DateTime) DEFAULT now()
+) ENGINE = Distributed('aux', 'posthog', 'property_values');
+CREATE TABLE posthog.query_log_archive (
+ hostname LowCardinality(String),
+ user LowCardinality(String),
+ query_id String,
+ initial_query_id String,
+ is_initial_query UInt8,
+ type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4),
+ event_date Date,
+ event_time DateTime,
+ event_time_microseconds DateTime64(6),
+ query_start_time DateTime,
+ query_start_time_microseconds DateTime64(6),
+ query_duration_ms UInt64,
+ read_rows UInt64,
+ read_bytes UInt64,
+ written_rows UInt64,
+ written_bytes UInt64,
+ result_rows UInt64,
+ result_bytes UInt64,
+ memory_usage UInt64,
+ peak_threads_usage UInt64,
+ current_database LowCardinality(String),
+ query String,
+ formatted_query String,
+ normalized_query_hash UInt64,
+ query_kind LowCardinality(String),
+ exception_code Int32,
+ exception String,
+ stack_trace String,
+ team_id Int64,
+ log_comment JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email),
+ ProfileEvents Map(String, UInt64),
+ exception_name String ALIAS errorCodeToName(exception_code),
+ ProfileEvents_RealTimeMicroseconds Int64 ALIAS ProfileEvents['RealTimeMicroseconds'],
+ ProfileEvents_OSCPUVirtualTimeMicroseconds Int64 ALIAS ProfileEvents['OSCPUVirtualTimeMicroseconds'],
+ ProfileEvents_S3Clients Int64 ALIAS ProfileEvents['S3Clients'],
+ ProfileEvents_S3DeleteObjects Int64 ALIAS ProfileEvents['S3DeleteObjects'],
+ ProfileEvents_S3CopyObject Int64 ALIAS ProfileEvents['S3CopyObject'],
+ ProfileEvents_S3ListObjects Int64 ALIAS ProfileEvents['S3ListObjects'],
+ ProfileEvents_S3HeadObject Int64 ALIAS ProfileEvents['S3HeadObject'],
+ ProfileEvents_S3GetObjectAttributes Int64 ALIAS ProfileEvents['S3GetObjectAttributes'],
+ ProfileEvents_S3CreateMultipartUpload Int64 ALIAS ProfileEvents['S3CreateMultipartUpload'],
+ ProfileEvents_S3UploadPartCopy Int64 ALIAS ProfileEvents['S3UploadPartCopy'],
+ ProfileEvents_S3UploadPart Int64 ALIAS ProfileEvents['S3UploadPart'],
+ ProfileEvents_S3AbortMultipartUpload Int64 ALIAS ProfileEvents['S3AbortMultipartUpload'],
+ ProfileEvents_S3CompleteMultipartUpload Int64 ALIAS ProfileEvents['S3CompleteMultipartUpload'],
+ ProfileEvents_S3PutObject Int64 ALIAS ProfileEvents['S3PutObject'],
+ ProfileEvents_S3GetObject Int64 ALIAS ProfileEvents['S3GetObject'],
+ ProfileEvents_ReadBufferFromS3Bytes Int64 ALIAS ProfileEvents['ReadBufferFromS3Bytes'],
+ ProfileEvents_WriteBufferFromS3Bytes Int64 ALIAS ProfileEvents['WriteBufferFromS3Bytes'],
+ lc_workflow LowCardinality(String) ALIAS log_comment.workflow,
+ lc_kind LowCardinality(String) ALIAS log_comment.kind,
+ lc_id String ALIAS CAST(log_comment.id, 'String'),
+ lc_route_id String ALIAS CAST(log_comment.route_id, 'String'),
+ lc_access_method LowCardinality(String) ALIAS log_comment.access_method,
+ lc_api_key_label String ALIAS CAST(log_comment.api_key_label, 'String'),
+ lc_api_key_mask String ALIAS CAST(log_comment.api_key_mask, 'String'),
+ lc_query_type LowCardinality(String) ALIAS log_comment.query_type,
+ lc_product LowCardinality(String) ALIAS log_comment.product,
+ lc_chargeable Bool ALIAS log_comment.chargeable,
+ lc_name String ALIAS CAST(log_comment.name, 'String'),
+ lc_request_name String ALIAS CAST(log_comment.request_name, 'String'),
+ lc_client_query_id String ALIAS CAST(log_comment.client_query_id, 'String'),
+ lc_org_id String ALIAS CAST(log_comment.org_id, 'String'),
+ lc_user_id Int64 ALIAS log_comment.user_id,
+ lc_is_impersonated Bool ALIAS log_comment.is_impersonated,
+ lc_session_id String ALIAS CAST(log_comment.session_id, 'String'),
+ lc_dashboard_id Int64 ALIAS log_comment.dashboard_id,
+ lc_insight_id Int64 ALIAS log_comment.insight_id,
+ lc_cohort_id Int64 ALIAS log_comment.cohort_id,
+ lc_batch_export_id String ALIAS CAST(log_comment.batch_export_id, 'String'),
+ lc_experiment_id Int64 ALIAS log_comment.experiment_id,
+ lc_experiment_feature_flag_key String ALIAS CAST(log_comment.experiment_feature_flag_key, 'String'),
+ lc_alert_config_id String ALIAS CAST(log_comment.alert_config_id, 'String'),
+ lc_feature LowCardinality(String) ALIAS log_comment.feature,
+ lc_table_id String ALIAS CAST(log_comment.table_id, 'String'),
+ lc_warehouse_query Bool ALIAS log_comment.warehouse_query,
+ lc_person_on_events_mode LowCardinality(String) ALIAS log_comment.person_on_events_mode,
+ lc_service_name String ALIAS CAST(log_comment.service_name, 'String'),
+ lc_workload LowCardinality(String) ALIAS log_comment.workload,
+ lc_query__kind LowCardinality(String) ALIAS if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind')),
+ lc_query__query String ALIAS multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query')),
+ lc_query String ALIAS if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), ''),
+ lc_temporal__workflow_namespace String ALIAS CAST(log_comment.`temporal.workflow_namespace`, 'String'),
+ lc_temporal__workflow_type String ALIAS CAST(log_comment.`temporal.workflow_type`, 'String'),
+ lc_temporal__workflow_id String ALIAS CAST(log_comment.`temporal.workflow_id`, 'String'),
+ lc_temporal__workflow_run_id String ALIAS CAST(log_comment.`temporal.workflow_run_id`, 'String'),
+ lc_temporal__activity_type String ALIAS CAST(log_comment.`temporal.activity_type`, 'String'),
+ lc_temporal__activity_id String ALIAS CAST(log_comment.`temporal.activity_id`, 'String'),
+ lc_temporal__attempt Int64 ALIAS log_comment.`temporal.attempt`,
+ lc_dagster__job_name String ALIAS CAST(log_comment.`dagster.job_name`, 'String'),
+ lc_dagster__run_id String ALIAS CAST(log_comment.`dagster.run_id`, 'String'),
+ lc_dagster__owner String ALIAS CAST(log_comment.`dagster.tags.owner`, 'String'),
+ lc_modifiers String ALIAS if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')
+) ENGINE = Distributed('ops', 'posthog', 'sharded_query_log_archive');
+CREATE TABLE posthog.raw_sessions (
+ team_id Int64,
+ session_id_v7 UInt128,
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_browser AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_browser_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_device_type AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_viewport_width AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_viewport_height AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_geoip_country_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_city_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_time_zone AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial__kx AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_irclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ pageview_uniq AggregateFunction(uniq, Nullable(UUID)),
+ autocapture_count SimpleAggregateFunction(sum, Int64),
+ autocapture_uniq AggregateFunction(uniq, Nullable(UUID)),
+ screen_count SimpleAggregateFunction(sum, Int64),
+ screen_uniq AggregateFunction(uniq, Nullable(UUID)),
+ maybe_has_session_replay SimpleAggregateFunction(max, Bool),
+ page_screen_autocapture_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),
+ vitals_lcp AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))
+) ENGINE = Distributed('sessions', 'posthog', 'raw_sessions', cityHash64(session_id_v7));
+CREATE TABLE posthog.session_recording_events (
+ uuid UUID,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ session_id String,
+ window_id String,
+ snapshot_data String,
+ created_at DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ has_full_snapshot Int8 COMMENT 'column_materializer::has_full_snapshot',
+ events_summary Array(String) COMMENT 'column_materializer::events_summary',
+ click_count Int8 COMMENT 'column_materializer::click_count',
+ keypress_count Int8 COMMENT 'column_materializer::keypress_count',
+ timestamps_summary Array(DateTime64(6, 'UTC')) COMMENT 'column_materializer::timestamps_summary',
+ first_event_timestamp DateTime64(6, 'UTC') COMMENT 'column_materializer::first_event_timestamp',
+ last_event_timestamp DateTime64(6, 'UTC') COMMENT 'column_materializer::last_event_timestamp',
+ urls Array(String) COMMENT 'column_materializer::urls'
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_recording_events', sipHash64(distinct_id));
+CREATE TABLE posthog.session_replay_features (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ event_count SimpleAggregateFunction(sum, Int64),
+ mouse_position_count SimpleAggregateFunction(sum, Int64),
+ mouse_sum_x SimpleAggregateFunction(sum, Float64),
+ mouse_sum_x_squared SimpleAggregateFunction(sum, Float64),
+ mouse_sum_y SimpleAggregateFunction(sum, Float64),
+ mouse_sum_y_squared SimpleAggregateFunction(sum, Float64),
+ mouse_distance_traveled SimpleAggregateFunction(sum, Float64),
+ mouse_direction_change_count SimpleAggregateFunction(sum, Int64),
+ mouse_velocity_sum SimpleAggregateFunction(sum, Float64),
+ mouse_velocity_sum_of_squares SimpleAggregateFunction(sum, Float64),
+ mouse_velocity_count SimpleAggregateFunction(sum, Int64),
+ scroll_event_count SimpleAggregateFunction(sum, Int64),
+ total_scroll_magnitude SimpleAggregateFunction(sum, Float64),
+ scroll_direction_reversal_count SimpleAggregateFunction(sum, Int64),
+ rapid_scroll_reversal_count SimpleAggregateFunction(sum, Int64),
+ scroll_to_top_count SimpleAggregateFunction(sum, Int64),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ rage_click_count SimpleAggregateFunction(sum, Int64),
+ dead_click_count SimpleAggregateFunction(sum, Int64),
+ backspace_count SimpleAggregateFunction(sum, Int64),
+ inter_action_gap_count SimpleAggregateFunction(sum, Int64),
+ inter_action_gap_sum_ms SimpleAggregateFunction(sum, Float64),
+ inter_action_gap_sum_of_squares_ms SimpleAggregateFunction(sum, Float64),
+ max_idle_gap_ms SimpleAggregateFunction(max, Float64),
+ long_idle_gap_count SimpleAggregateFunction(sum, Int64),
+ quick_back_count SimpleAggregateFunction(sum, Int64),
+ page_visit_count SimpleAggregateFunction(sum, Int64),
+ unique_url_count AggregateFunction(uniqCombined(12), String),
+ login_path_visit_count SimpleAggregateFunction(sum, Int64),
+ signup_path_visit_count SimpleAggregateFunction(sum, Int64),
+ checkout_path_visit_count SimpleAggregateFunction(sum, Int64),
+ cart_path_visit_count SimpleAggregateFunction(sum, Int64),
+ billing_path_visit_count SimpleAggregateFunction(sum, Int64),
+ settings_path_visit_count SimpleAggregateFunction(sum, Int64),
+ account_path_visit_count SimpleAggregateFunction(sum, Int64),
+ error_path_visit_count SimpleAggregateFunction(sum, Int64),
+ not_found_path_visit_count SimpleAggregateFunction(sum, Int64),
+ admin_path_visit_count SimpleAggregateFunction(sum, Int64),
+ dashboard_path_visit_count SimpleAggregateFunction(sum, Int64),
+ onboarding_path_visit_count SimpleAggregateFunction(sum, Int64),
+ cancel_path_visit_count SimpleAggregateFunction(sum, Int64),
+ refund_path_visit_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ console_error_after_click_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ network_request_count SimpleAggregateFunction(sum, Int64),
+ network_failed_request_count SimpleAggregateFunction(sum, Int64),
+ network_4xx_count SimpleAggregateFunction(sum, Int64),
+ network_5xx_count SimpleAggregateFunction(sum, Int64),
+ network_request_duration_sum SimpleAggregateFunction(sum, Float64),
+ network_request_duration_sum_of_squares SimpleAggregateFunction(sum, Float64),
+ network_request_duration_count SimpleAggregateFunction(sum, Int64),
+ mutation_count SimpleAggregateFunction(sum, Int64),
+ viewport_resize_count SimpleAggregateFunction(sum, Int64),
+ touch_event_count SimpleAggregateFunction(sum, Int64),
+ max_scroll_y SimpleAggregateFunction(max, Float64),
+ unique_click_target_count AggregateFunction(uniqCombined(12), Int64),
+ unique_form_field_count AggregateFunction(uniqCombined(12), Int64),
+ text_selection_count SimpleAggregateFunction(sum, Int64),
+ selection_copy_count SimpleAggregateFunction(sum, Int64),
+ is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0
+) ENGINE = Distributed('aux', 'posthog', 'sharded_session_replay_features', sipHash64(session_id));
+CREATE TABLE posthog.sessions (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = Distributed('sessions', 'posthog', 'sessions', sipHash64(session_id));
+CREATE TABLE posthog.sharded_app_metrics2 (
+ team_id Int64,
+ timestamp DateTime64(6, 'UTC'),
+ app_source LowCardinality(String),
+ app_source_id String,
+ instance_id String,
+ metric_kind LowCardinality(String),
+ metric_name LowCardinality(String),
+ count SimpleAggregateFunction(sum, Int64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.sharded_app_metrics2', '{replica}') ORDER BY (team_id, app_source, app_source_id, instance_id, toStartOfHour(timestamp), metric_kind, metric_name) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_distinct_id_usage (
+ team_id Int64,
+ distinct_id String,
+ minute DateTime,
+ event_count UInt64
+) ENGINE = ReplicatedSummingMergeTree('/clickhouse/tables/{shard}/posthog.distinct_id_usage', '{replica}', (event_count)) 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;
+CREATE TABLE posthog.sharded_events (
+ uuid UUID,
+ event String,
+ properties String CODEC(Default),
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ elements_hash String,
+ created_at DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ elements_chain String,
+ $group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), concat('^[', regexpQuoteMeta('"'), ']*|[', regexpQuoteMeta('"'), ']*$'), ''),
+ $group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), concat('^[', regexpQuoteMeta('"'), ']*|[', regexpQuoteMeta('"'), ']*$'), ''),
+ $group_2 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), concat('^[', regexpQuoteMeta('"'), ']*|[', regexpQuoteMeta('"'), ']*$'), ''),
+ $group_3 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), concat('^[', regexpQuoteMeta('"'), ']*|[', regexpQuoteMeta('"'), ']*$'), ''),
+ $group_4 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), concat('^[', regexpQuoteMeta('"'), ']*|[', regexpQuoteMeta('"'), ']*$'), ''),
+ $window_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), concat('^[', regexpQuoteMeta('"'), ']*|[', regexpQuoteMeta('"'), ']*$'), ''),
+ $session_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), concat('^[', regexpQuoteMeta('"'), ']*|[', regexpQuoteMeta('"'), ']*$'), ''),
+ person_id UUID,
+ person_properties String CODEC(Default),
+ group0_properties String CODEC(Default),
+ group1_properties String CODEC(Default),
+ group2_properties String CODEC(Default),
+ group3_properties String CODEC(Default),
+ group4_properties String CODEC(Default),
+ person_created_at DateTime64(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),
+ 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_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)(?:\\.|$|:)')),
+ elements_chain_ids Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")attr_id="(.*?)"')),
+ 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'))), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)'))) CODEC(Default),
+ properties_group_feature_flags Map(String, String) MATERIALIZED mapSort(mapFilter((key, _) -> (key LIKE '$feature/%'), CAST(JSONExtractKeysAndValues(properties, 'String'), 'Map(String, String)'))) CODEC(Default),
+ 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(Default),
+ mat_$ai_trace_id Nullable(String) DEFAULT JSONExtract(properties, '$ai_trace_id', 'Nullable(String)'),
+ $session_id_uuid Nullable(UInt128) MATERIALIZED toUInt128(JSONExtract(properties, '$session_id', 'Nullable(UUID)')),
+ consumer_breadcrumbs Array(String),
+ properties_map_ephemeral Map(String, String),
+ person_properties_map_ephemeral Map(String, 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(Default),
+ mat_historical_migration Nullable(String) DEFAULT JSONExtract(properties, 'historical_migration', 'Nullable(String)'),
+ 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)'),
+ mat_$ai_experiment_id Nullable(String) MATERIALIZED JSONExtract(properties, '$ai_experiment_id', 'Nullable(String)'),
+ INDEX kafka_timestamp_minmax_sharded_events _timestamp TYPE minmax GRANULARITY 3,
+ 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_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_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 is_deleted_idx is_deleted TYPE minmax 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 minmax_mat_$ai_trace_id `mat_$ai_trace_id` 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 minmax_mat_historical_migration mat_historical_migration TYPE minmax GRANULARITY 1,
+ 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_$session_id_uuid `$session_id_uuid` TYPE minmax GRANULARITY 1,
+ INDEX bloom_filter_$session_id nullIf(nullIf(`$session_id`, ''), 'null') TYPE bloom_filter GRANULARITY 1
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/reshard3/{shard}/posthog.sharded_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, max_avg_part_size_for_too_many_parts = 0;
+CREATE TABLE posthog.sharded_experiment_exposures_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ entity_id String,
+ variant String,
+ first_exposure_time DateTime64(6, 'UTC'),
+ last_exposure_time DateTime64(6, 'UTC'),
+ exposure_event_uuid UUID,
+ exposure_session_id String,
+ breakdown_value Array(String),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.experiment_exposures_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, entity_id, breakdown_value) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_flag_evaluations (
+ uuid UUID,
+ event LowCardinality(String),
+ properties String,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ created_at DateTime64(6, 'UTC'),
+ person_id UUID,
+ inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,
+ $group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0',
+ $group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1',
+ $group_2 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^"|"$', '') COMMENT 'column_materializer::$group_2',
+ $group_3 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_3'), '^"|"$', '') COMMENT 'column_materializer::$group_3',
+ $group_4 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^"|"$', '') COMMENT 'column_materializer::$group_4',
+ flag_key String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag',
+ response LowCardinality(String) DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag_response',
+ session_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^"|"$', '') COMMENT 'column_materializer::properties::$session_id',
+ request_id String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_request_id'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag_request_id',
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX distinct_id_idx distinct_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX person_id_idx person_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX session_id_idx session_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX request_id_idx request_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX inserted_at_idx inserted_at TYPE minmax GRANULARITY 1
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.flag_evaluations', '{replica}') ORDER BY (team_id, flag_key, toDate(timestamp), cityHash64(distinct_id)) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_heatmaps (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ timestamp DateTime64(6, 'UTC'),
+ x Int16,
+ y Int16,
+ scale_factor Int16,
+ viewport_width Int16,
+ viewport_height Int16,
+ pointer_target_fixed Bool,
+ current_url String,
+ type LowCardinality(String),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/reshard/{shard}/posthog.heatmaps', '{replica}') ORDER BY (type, team_id, toDate(timestamp), current_url, viewport_width) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_log_entries (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.sharded_log_entries', '{replica}', _timestamp) ORDER BY (team_id, log_source, log_source_id, instance_id, timestamp) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_performance_events (
+ uuid UUID,
+ session_id String,
+ window_id String,
+ pageview_id String,
+ distinct_id String,
+ timestamp DateTime64(3),
+ time_origin DateTime64(3, 'UTC'),
+ entry_type LowCardinality(String),
+ name String,
+ team_id Int64,
+ current_url String,
+ start_time Float64,
+ duration Float64,
+ redirect_start Float64,
+ redirect_end Float64,
+ worker_start Float64,
+ fetch_start Float64,
+ domain_lookup_start Float64,
+ domain_lookup_end Float64,
+ connect_start Float64,
+ secure_connection_start Float64,
+ connect_end Float64,
+ request_start Float64,
+ response_start Float64,
+ response_end Float64,
+ decoded_body_size Int64,
+ encoded_body_size Int64,
+ initiator_type LowCardinality(String),
+ next_hop_protocol LowCardinality(String),
+ render_blocking_status LowCardinality(String),
+ response_status Int64,
+ transfer_size Int64,
+ largest_contentful_paint_element String,
+ largest_contentful_paint_render_time Float64,
+ largest_contentful_paint_load_time Float64,
+ largest_contentful_paint_size Float64,
+ largest_contentful_paint_id String,
+ largest_contentful_paint_url String,
+ dom_complete Float64,
+ dom_content_loaded_event Float64,
+ dom_interactive Float64,
+ load_event_end Float64,
+ load_event_start Float64,
+ redirect_count Int64,
+ navigation_type LowCardinality(String),
+ unload_event_end Float64,
+ unload_event_start Float64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/reshard/{shard}/posthog.performance_events', '{replica}') ORDER BY (team_id, toDate(timestamp), session_id, pageview_id, timestamp) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalWeek(3) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_person (
+ id UUID,
+ created_at DateTime,
+ team_id Int64,
+ properties String,
+ is_identified Int8,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.sharded_person', '{replica}', _timestamp) ORDER BY (team_id, id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_person_distinct_id (
+ id Int64,
+ distinct_id String,
+ person_id UUID,
+ team_id Int64,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.sharded_person_distinct_id', '{replica}', _timestamp) ORDER BY (team_id, distinct_id, person_id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_posthog_document_embeddings_buffer (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ model_name LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.sharded_posthog_document_embeddings_buffer', '{replica}', inserted_at) ORDER BY (inserted_at, model_name, cityHash64(document_id)) PARTITION BY toDate(inserted_at) TTL inserted_at + toIntervalDay(1) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ CONSTRAINT embedding_dimension_check CHECK length(embedding) = 3072,
+ INDEX kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_large_3072 _timestamp TYPE minmax GRANULARITY 3,
+ INDEX embedding_idx_l2 embedding TYPE vector_similarity('hnsw', 'L2Distance', 3072) GRANULARITY 100000000,
+ INDEX embedding_idx_cosine embedding TYPE vector_similarity('hnsw', 'cosineDistance', 3072) GRANULARITY 100000000
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_large_3072', '{replica}', inserted_at) ORDER BY (team_id, toDate(timestamp), product, document_type, rendering, cityHash64(document_id)) PARTITION BY toMonday(timestamp) TTL timestamp + toIntervalMonth(3) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ CONSTRAINT embedding_dimension_check CHECK length(embedding) = 1536,
+ INDEX kafka_timestamp_minmax_sharded_posthog_document_embeddings_text_embedding_3_small_1536 _timestamp TYPE minmax GRANULARITY 3,
+ INDEX embedding_idx_l2 embedding TYPE vector_similarity('hnsw', 'L2Distance', 1536) GRANULARITY 100000000,
+ INDEX embedding_idx_cosine embedding TYPE vector_similarity('hnsw', 'cosineDistance', 1536) GRANULARITY 100000000
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.sharded_posthog_document_embeddings_text_embedding_3_small_1536', '{replica}', inserted_at) ORDER BY (team_id, toDate(timestamp), product, document_type, rendering, cityHash64(document_id)) PARTITION BY toMonday(timestamp) TTL timestamp + toIntervalMonth(3) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_preaggregation_results (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7),
+ breakdown_value Array(String),
+ uniq_exact_state AggregateFunction(uniqExact, UUID)
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.preaggregation_results', '{replica}') ORDER BY (team_id, job_id, time_window_start, breakdown_value) PARTITION BY toYYYYMM(time_window_start) TTL expires_at SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_raw_sessions_v3 (
+ team_id Int64,
+ session_id_v7 UInt128,
+ session_timestamp DateTime64(3) DEFAULT fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80))),
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ distinct_ids AggregateFunction(groupUniqArray, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),
+ entry_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ browser AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ browser_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ device_type AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ viewport_width AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ viewport_height AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ geoip_country_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_city_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_time_zone AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_referring_domain AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_campaign AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_medium AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_term AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_content AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gad_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_fbclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_has_gclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_has_fbclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_ad_ids_map AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC')),
+ entry_ad_ids_set AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC')),
+ entry_channel_type_properties AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC')),
+ pageview_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ autocapture_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ 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_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ event_names SimpleAggregateFunction(groupUniqArrayArray, 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
+) 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,
+ team_id Int64,
+ embeddings Array(Float32),
+ generation_timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ source_type LowCardinality(String),
+ input String
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/reshard/{shard}/posthog.session_replay_embeddings', '{replica}') ORDER BY (toDate(generation_timestamp), team_id, session_id) PARTITION BY toYYYYMM(generation_timestamp) TTL toDate(generation_timestamp) + toIntervalYear(1) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.sharded_session_replay_events (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ active_milliseconds SimpleAggregateFunction(sum, Int64),
+ console_log_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ size SimpleAggregateFunction(sum, Int64),
+ message_count SimpleAggregateFunction(sum, Int64),
+ event_count SimpleAggregateFunction(sum, Int64),
+ _timestamp SimpleAggregateFunction(max, DateTime),
+ snapshot_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.session_replay_events', '{replica}') ORDER BY (toDate(min_first_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.swap_person_distinct_id (
+ distinct_id String,
+ person_id UUID,
+ team_id Int64,
+ _sign Int8 DEFAULT 1,
+ is_deleted Int8 ALIAS if(_sign = -1, 1, 0),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/prod/tables/noshard/posthog.person_distinct_id_', '{replica}-{shard}', _sign) ORDER BY (team_id, distinct_id, person_id) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.tophog (
+ timestamp DateTime64(6, 'UTC'),
+ metric LowCardinality(String),
+ type LowCardinality(String) DEFAULT 'sum',
+ key Map(LowCardinality(String), String),
+ value Float64,
+ count UInt64 DEFAULT 0,
+ pipeline LowCardinality(String),
+ lane LowCardinality(String),
+ labels Map(LowCardinality(String), String)
+) ENGINE = Distributed('ops', 'posthog', 'sharded_tophog', cityHash64(toString(key)));
+CREATE TABLE posthog.usage_report_events_preagg (
+ date Date,
+ team_id Int64,
+ person_mode LowCardinality(String),
+ lib LowCardinality(String),
+ event String,
+ distinct_events_unique AggregateFunction(uniqExact, Tuple(UInt64, UInt64, UInt64)),
+ event_count AggregateFunction(sum, UInt64)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_usage_report_events_preagg', sipHash64(date));
+CREATE TABLE posthog.web_bot_definition (
+ id UInt64,
+ parent_id UInt64,
+ regexp String,
+ keys Array(String),
+ values Array(String)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_bot_definition', sipHash64(id));
+CREATE TABLE posthog.web_bounces_daily_distributed (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64),
+ bounces_count_state AggregateFunction(sum, UInt64),
+ total_session_duration_state AggregateFunction(sum, Int64),
+ total_session_count_state AggregateFunction(sum, UInt64)
+) ENGINE = Distributed('posthog', 'posthog', 'web_bounces_daily', rand());
+CREATE TABLE posthog.web_bounces_dimensional_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ period_bucket DateTime,
+ host String,
+ device_type String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ mat_metadata_loggedIn Nullable(Bool),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, Int64),
+ bounces_count_state AggregateFunction(sum, Int64),
+ total_session_duration_state AggregateFunction(sum, Int64),
+ total_session_count_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_bounces_dimensional_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_bounces_hourly_distributed (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64),
+ bounces_count_state AggregateFunction(sum, UInt64),
+ total_session_duration_state AggregateFunction(sum, Int64),
+ total_session_count_state AggregateFunction(sum, UInt64)
+) ENGINE = Distributed('posthog', 'posthog', 'web_bounces_hourly', rand());
+CREATE TABLE posthog.web_goals_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ action_id Int64,
+ count_state AggregateFunction(sum, Int64),
+ unique_persons_state AggregateFunction(uniq, UUID),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_goals_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_overview_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ uniq_users_state AggregateFunction(uniq, UUID),
+ uniq_sessions_state AggregateFunction(uniq, String),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ avg_duration_state AggregateFunction(avg, Float64),
+ avg_bounce_state AggregateFunction(avg, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_overview_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_pre_aggregated_bounces (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64),
+ bounces_count_state AggregateFunction(sum, UInt64),
+ total_session_duration_state AggregateFunction(sum, Int64),
+ total_session_count_state AggregateFunction(sum, UInt64),
+ mat_metadata_loggedIn Nullable(Bool)
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces', '{replica}-{shard}') ORDER BY (team_id, period_bucket, host, device_type, entry_pathname, end_pathname, browser, os, viewport_width, viewport_height, referring_domain, utm_source, utm_medium, utm_campaign, utm_term, utm_content, country_code, city_name, region_code, region_name, has_gclid, has_gad_source_paid_search, has_fbclid) PARTITION BY toYYYYMMDD(period_bucket) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.web_pre_aggregated_stats (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ pathname String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64),
+ mat_metadata_loggedIn Nullable(Bool)
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats', '{replica}-{shard}') ORDER BY (team_id, period_bucket, host, device_type, pathname, entry_pathname, end_pathname, browser, os, viewport_width, viewport_height, referring_domain, utm_source, utm_medium, utm_campaign, utm_term, utm_content, country_code, city_name, region_code, region_name, has_gclid, has_gad_source_paid_search, has_fbclid) PARTITION BY toYYYYMMDD(period_bucket) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.web_pre_aggregated_teams (
+ team_id UInt64,
+ enabled_by String DEFAULT 'system',
+ version UInt32 DEFAULT toUnixTimestamp(now())
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.web_analytics_team_selection', '{replica}-{shard}', version) ORDER BY (team_id) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;
+CREATE TABLE posthog.web_stats_daily_distributed (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ pathname String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64)
+) ENGINE = Distributed('posthog', 'posthog', 'web_stats_daily', rand());
+CREATE TABLE posthog.web_stats_dimensional_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ period_bucket DateTime,
+ host String,
+ device_type String,
+ pathname String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ has_gclid Bool,
+ has_gad_source_paid_search Bool,
+ has_fbclid Bool,
+ mat_metadata_backend Nullable(String),
+ mat_metadata_loggedIn Nullable(Bool),
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_dimensional_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_stats_frustration_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_value String,
+ sum_rage_clicks_state AggregateFunction(sum, Int64),
+ sum_dead_clicks_state AggregateFunction(sum, Int64),
+ sum_errors_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_frustration_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_stats_hourly_distributed (
+ period_bucket DateTime,
+ team_id UInt64,
+ host String,
+ device_type String,
+ pathname String,
+ entry_pathname String,
+ end_pathname String,
+ browser String,
+ os String,
+ viewport_width Int64,
+ viewport_height Int64,
+ referring_domain String,
+ utm_source String,
+ utm_medium String,
+ utm_campaign String,
+ utm_term String,
+ utm_content String,
+ country_code String,
+ city_name String,
+ region_code String,
+ region_name String,
+ persons_uniq_state AggregateFunction(uniq, UUID),
+ sessions_uniq_state AggregateFunction(uniq, String),
+ pageviews_count_state AggregateFunction(sum, UInt64)
+) ENGINE = Distributed('posthog', 'posthog', 'web_stats_hourly', rand());
+CREATE TABLE posthog.web_stats_paths_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_value String,
+ uniq_users_state AggregateFunction(uniq, UUID),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ avg_bounce_state AggregateFunction(avg, Nullable(Float64)),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_paths_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_stats_paths_preaggregated_pathkey (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_value String,
+ uniq_users_state AggregateFunction(uniq, UUID),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ avg_bounce_state AggregateFunction(avg, Nullable(Float64)),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_paths_preaggregated_pathkey', sipHash64(breakdown_value));
+CREATE TABLE posthog.web_stats_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ breakdown_by String,
+ breakdown_value String,
+ uniq_users_state AggregateFunction(uniq, UUID),
+ sum_pageviews_state AggregateFunction(sum, Int64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_stats_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.web_vitals_paths_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ path String,
+ inp_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ lcp_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ cls_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ fcp_quantiles_state AggregateFunction(quantiles(0.75, 0.9, 0.99), Float64),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)
+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_vitals_paths_preaggregated', sipHash64(job_id));
+CREATE TABLE posthog.writable_events_recent (
+ uuid UUID,
+ event String,
+ properties String,
+ 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,
+ group0_properties String,
+ group1_properties String,
+ group2_properties String,
+ group3_properties String,
+ group4_properties String,
+ 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),
+ _timestamp DateTime,
+ _offset UInt64,
+ inserted_at DateTime64(6, 'UTC') DEFAULT now64()
+) ENGINE = Distributed('batch_exports_writable', 'posthog', 'sharded_events_recent', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_ingestion_warnings (
+ team_id Int64,
+ source LowCardinality(String),
+ type String,
+ details String CODEC(ZSTD(3)),
+ timestamp DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_ingestion_warnings', rand());
+CREATE TABLE posthog.writable_posthog_document_embeddings (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ model_name LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings', cityHash64(document_id));
+CREATE TABLE posthog.writable_posthog_document_embeddings_buffer (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ model_name LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_buffer', cityHash64(document_id));
+CREATE TABLE posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_large_3072', cityHash64(document_id));
+CREATE TABLE posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_small_1536', cityHash64(document_id));
+CREATE TABLE posthog.writable_query_log_archive (
+ hostname LowCardinality(String),
+ user LowCardinality(String),
+ query_id String,
+ initial_query_id String,
+ is_initial_query UInt8,
+ type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4),
+ event_date Date,
+ event_time DateTime,
+ event_time_microseconds DateTime64(6),
+ query_start_time DateTime,
+ query_start_time_microseconds DateTime64(6),
+ query_duration_ms UInt64,
+ read_rows UInt64,
+ read_bytes UInt64,
+ written_rows UInt64,
+ written_bytes UInt64,
+ result_rows UInt64,
+ result_bytes UInt64,
+ memory_usage UInt64,
+ peak_threads_usage UInt64,
+ current_database LowCardinality(String),
+ query String,
+ formatted_query String,
+ normalized_query_hash UInt64,
+ query_kind LowCardinality(String),
+ exception_code Int32,
+ exception String,
+ stack_trace String,
+ team_id Int64,
+ log_comment JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email),
+ ProfileEvents Map(String, UInt64)
+) ENGINE = Distributed('ops', 'posthog', 'query_log_archive_buffer');
+CREATE TABLE posthog.writable_raw_sessions (
+ team_id Int64,
+ session_id_v7 UInt128,
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_browser AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_browser_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_device_type AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_viewport_width AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_viewport_height AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_geoip_country_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_city_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_time_zone AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_irclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ pageview_uniq AggregateFunction(uniq, Nullable(UUID)),
+ autocapture_count SimpleAggregateFunction(sum, Int64),
+ autocapture_uniq AggregateFunction(uniq, Nullable(UUID)),
+ screen_count SimpleAggregateFunction(sum, Int64),
+ screen_uniq AggregateFunction(uniq, Nullable(UUID)),
+ maybe_has_session_replay SimpleAggregateFunction(max, Bool),
+ page_screen_autocapture_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),
+ vitals_lcp AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC')),
+ initial__kx AggregateFunction(argMin, String, DateTime64(6, 'UTC'))
+) ENGINE = Distributed('sessions', 'posthog', 'raw_sessions', cityHash64(session_id_v7));
+CREATE TABLE posthog.writable_raw_sessions_primary (
+ team_id Int64,
+ session_id_v7 UInt128,
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_browser AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_browser_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_os_version AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_device_type AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_viewport_width AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_viewport_height AggregateFunction(argMin, Int64, DateTime64(6, 'UTC')),
+ initial_geoip_country_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_code AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_1_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_subdivision_city_name AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_geoip_time_zone AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_irclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ pageview_uniq AggregateFunction(uniq, Nullable(UUID)),
+ autocapture_count SimpleAggregateFunction(sum, Int64),
+ autocapture_uniq AggregateFunction(uniq, Nullable(UUID)),
+ screen_count SimpleAggregateFunction(sum, Int64),
+ screen_uniq AggregateFunction(uniq, Nullable(UUID)),
+ maybe_has_session_replay SimpleAggregateFunction(max, Bool),
+ page_screen_autocapture_uniq_up_to AggregateFunction(uniqUpTo(1), Nullable(UUID)),
+ vitals_lcp AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC')),
+ initial__kx AggregateFunction(argMin, String, DateTime64(6, 'UTC'))
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_raw_sessions', cityHash64(session_id_v7));
+CREATE TABLE posthog.writable_session_recording_events (
+ uuid UUID,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ session_id String,
+ window_id String,
+ snapshot_data String,
+ created_at DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_recording_events', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_session_replay_embeddings (
+ session_id String,
+ team_id Int64,
+ embeddings Array(Float32),
+ generation_timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ source_type LowCardinality(String),
+ input String
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_embeddings', sipHash64(session_id));
+CREATE TABLE posthog.writable_session_replay_events (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
+ first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ active_milliseconds SimpleAggregateFunction(sum, Int64),
+ console_log_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ size SimpleAggregateFunction(sum, Int64),
+ message_count SimpleAggregateFunction(sum, Int64),
+ event_count SimpleAggregateFunction(sum, Int64),
+ snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
+ snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ _timestamp SimpleAggregateFunction(max, DateTime),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+) ENGINE = Distributed('posthog_writable', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_sessions (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = Distributed('posthog_writable', 'posthog', 'sharded_sessions', sipHash64(session_id));
+CREATE TABLE posthog.writable_sessions_background (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_sessions', sipHash64(session_id));
+CREATE TABLE posthog.writeable_performance_events (
+ uuid UUID,
+ session_id String,
+ window_id String,
+ pageview_id String,
+ distinct_id String,
+ timestamp DateTime64(3),
+ time_origin DateTime64(3, 'UTC'),
+ entry_type LowCardinality(String),
+ name String,
+ team_id Int64,
+ current_url String,
+ start_time Float64,
+ duration Float64,
+ redirect_start Float64,
+ redirect_end Float64,
+ worker_start Float64,
+ fetch_start Float64,
+ domain_lookup_start Float64,
+ domain_lookup_end Float64,
+ connect_start Float64,
+ secure_connection_start Float64,
+ connect_end Float64,
+ request_start Float64,
+ response_start Float64,
+ response_end Float64,
+ decoded_body_size Int64,
+ encoded_body_size Int64,
+ initiator_type LowCardinality(String),
+ next_hop_protocol LowCardinality(String),
+ render_blocking_status LowCardinality(String),
+ response_status Int64,
+ transfer_size Int64,
+ largest_contentful_paint_element String,
+ largest_contentful_paint_render_time Float64,
+ largest_contentful_paint_load_time Float64,
+ largest_contentful_paint_size Float64,
+ largest_contentful_paint_id String,
+ largest_contentful_paint_url String,
+ dom_complete Float64,
+ dom_content_loaded_event Float64,
+ dom_interactive Float64,
+ load_event_end Float64,
+ load_event_start Float64,
+ redirect_count Int64,
+ navigation_type LowCardinality(String),
+ unload_event_end Float64,
+ unload_event_start Float64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_performance_events', sipHash64(session_id));
+CREATE MATERIALIZED VIEW posthog.ops_query_log_archive_mv TO posthog.writable_query_log_archive (hostname LowCardinality(String), user LowCardinality(String), query_id String, initial_query_id String, is_initial_query UInt8, type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4), event_date Date, event_time DateTime, event_time_microseconds DateTime64(6), query_start_time DateTime, query_start_time_microseconds DateTime64(6), query_duration_ms UInt64, read_rows UInt64, read_bytes UInt64, written_rows UInt64, written_bytes UInt64, result_rows UInt64, result_bytes UInt64, memory_usage UInt64, peak_threads_usage UInt64, current_database LowCardinality(String), query String, formatted_query String, normalized_query_hash UInt64, query_kind LowCardinality(String), exception_code Int32, exception String, stack_trace String, team_id Int64, log_comment String, ProfileEvents Map(LowCardinality(String), UInt64)) AS SELECT
+ hostname,
+ user,
+ query_id,
+ initial_query_id,
+ is_initial_query,
+ type,
+ event_date,
+ event_time,
+ event_time_microseconds,
+ query_start_time,
+ query_start_time_microseconds,
+ query_duration_ms,
+ read_rows,
+ read_bytes,
+ written_rows,
+ written_bytes,
+ result_rows,
+ result_bytes,
+ memory_usage,
+ peak_threads_usage,
+ current_database,
+ query,
+ formatted_query,
+ normalized_query_hash,
+ query_kind,
+ exception_code,
+ exception,
+ stack_trace,
+ JSONExtractInt(log_comment, 'team_id') AS team_id,
+ if(isValidJSON(log_comment), log_comment, '{}') AS log_comment,
+ ProfileEvents
+FROM system.query_log
+WHERE type != 'QueryStart';
+CREATE MATERIALIZED VIEW posthog.posthog_document_embeddings_text_embedding_3_large_3072_mv TO posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072 (team_id Int64, product LowCardinality(String), document_type LowCardinality(String), rendering LowCardinality(String), document_id String, timestamp DateTime64(3, 'UTC'), inserted_at DateTime64(3, 'UTC'), content String, metadata String, embedding Array(Float64), _timestamp DateTime, _offset UInt64, _partition UInt64) AS SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-large-3072';
+CREATE MATERIALIZED VIEW posthog.posthog_document_embeddings_text_embedding_3_small_1536_mv TO posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536 (team_id Int64, product LowCardinality(String), document_type LowCardinality(String), rendering LowCardinality(String), document_id String, timestamp DateTime64(3, 'UTC'), inserted_at DateTime64(3, 'UTC'), content String, metadata String, embedding Array(Float64), _timestamp DateTime, _offset UInt64, _partition UInt64) AS SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.sharded_posthog_document_embeddings_buffer
+WHERE model_name = 'text-embedding-3-small-1536';
+CREATE VIEW posthog.custom_metrics_backups AS WITH
+ ['ClickHouseCustomMetric_BackupFailed', 'ClickHouseCustomMetric_BackupSuccess', 'ClickHouseCustomMetric_BackupCancelled', 'ClickHouseCustomMetric_BackupAttempts'] AS names,
+ [toInt64(countIf(status = 'BACKUP_FAILED')), toInt64(countIf(status = 'BACKUP_CREATED')), toInt64(countIf(status = 'BACKUP_CANCELLED')), toInt64(countIf(status = 'CREATING_BACKUP'))] AS `values`,
+ ['Number of failed backups', 'Number of successful backups', 'Number of cancelled backups', 'Number of backup attempts'] AS descriptions,
+ ['gauge', 'gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.backup_log
+WHERE event_date = today()
+GROUP BY
+ event_date;
+CREATE VIEW posthog.custom_metrics_dictionaries AS SELECT
+ 'ClickHouseCustomMetric_DictionariesFailed' AS name,
+ map(
+ 'instance',
+ hostname(),
+ 'database',
+ d.database,
+ 'dictionary',
+ d.dict_name,
+ 'uuid',
+ toString(d.uuid),
+ 'status',
+ toString(d.status)
+ ) AS labels,
+ toUInt64(1) AS value,
+ 'Dictionary is in FAILED or FAILED_AND_RELOADING status' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT name AS dict_name, database, uuid, status
+ FROM system.dictionaries
+ WHERE status IN ('FAILED', 'FAILED_AND_RELOADING')
+ ) AS d;
+CREATE VIEW posthog.custom_metrics_part_counts AS SELECT
+ 'ClickHouseCustomMetric_MaxPartCountPerPartition' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`, 'partition', partition) AS labels,
+ part_count AS value,
+ 'Maximum number of active parts for any partition in a PostHog table' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT database, `table`, partition, count() AS part_count
+ FROM system.parts
+ WHERE
+ active
+ AND
+ (database = 'posthog')
+ GROUP BY
+ database, `table`, partition
+ ORDER BY database ASC, `table` ASC, part_count DESC, partition ASC
+ LIMIT 1 BY database, `table`
+ );
+CREATE VIEW posthog.custom_metrics_replication_queue AS WITH
+ ['ClickHouseCustomMetric_ReplicationQueueStuckEntries', 'ClickHouseCustomMetric_ReplicationQueueMaxPostponedEntrySeconds', 'ClickHouseCustomMetric_ReplicationQueueMaxErrorEntrySeconds'] AS names,
+ [toInt64(countIf(create_time < (now() - toIntervalDay(15)))), maxIf(dateDiff('seconds', create_time, last_postpone_time), last_postpone_time != '1970-01-01'), maxIf(dateDiff('seconds', create_time, last_exception_time), (last_exception_time != '1970-01-01') AND (last_exception_time > (now() - toIntervalMinute(5))))] AS `values`,
+ ['Number of entries that have been in the replication queue for more than 15 days', 'Maximum number of seconds that an entry has been postponed', 'Maximum number of seconds that an entry has been in error'] AS descriptions,
+ ['gauge', 'gauge', 'gauge'] AS types,
+ arrayJoin(arrayZip(names, `values`, descriptions, types)) AS tpl
+SELECT
+ tpl.1 AS name,
+ map('table', `table`, 'instance', hostname()) AS labels,
+ tpl.2 AS value,
+ tpl.3 AS help,
+ tpl.4 AS type
+FROM system.replication_queue
+GROUP BY
+ `table`
+HAVING
+ value > 0;
+CREATE VIEW posthog.custom_metrics_server_crash AS SELECT
+ 'ClickHouseCustomMetric_ServerCrash' AS name,
+ map('instance', hostname()) AS labels,
+ count() AS value,
+ 'Number of server crashes for current date' AS help,
+ 'gauge' AS type
+FROM system.crash_log
+WHERE event_date = today()
+GROUP BY
+ hostname();
+CREATE VIEW posthog.custom_metrics_table_sizes AS SELECT
+ 'ClickHouseCustomMetric_TableTotalBytes' AS name,
+ map('instance', hostname(), 'database', database, 'table', `table`) AS labels,
+ CAST(total_bytes, 'Float64') AS value,
+ 'Size of a database table on a given node (need a sum for sharded)' AS help,
+ 'gauge' AS type
+FROM system.tables
+WHERE
+ (database NOT IN ('INFORMATION_SCHEMA', 'information_schema'))
+AND
+ (total_bytes IS NOT NULL);
+CREATE VIEW posthog.custom_metrics_test AS SELECT
+ 'ClickHouseCustomMetric_Test' AS name,
+ map('instance', hostname()) AS labels,
+ 1 AS value,
+ 'Test to check that the metric endpoint is working' AS help,
+ 'gauge' AS type;
+CREATE VIEW posthog.events_batch_export_recent AS SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ inserted_at AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events_recent
+PREWHERE
+ (events_recent.inserted_at >= {interval_start: DateTime64}) AND (events_recent.inserted_at < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events_recent.distinct_id), cityHash64(events_recent.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1;
+CREATE VIEW posthog.persons_batch_export AS WITH
+ new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
+ new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
+ all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
+SELECT
+ p.team_id AS team_id,
+ pd.distinct_id AS distinct_id,
+ toString(p.id) AS person_id,
+ p.properties AS properties,
+ pd.version AS person_distinct_id_version,
+ p.version AS person_version,
+ p.created_at AS created_at,
+ multiIf(
+ ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
+ pd._timestamp,
+ ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
+ AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
+ p._timestamp,
+ least(p._timestamp, pd._timestamp)
+ ) AS _inserted_at
+FROM
+ posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((id, version) IN (all_new_persons))
+ORDER BY _inserted_at ASC;
+CREATE VIEW posthog.persons_properties_up_to_date_view AS SELECT *
+FROM posthog.persons_properties_view
+WHERE
+ (id, created_at)
+ IN (SELECT id, maxMerge(updated_at) AS latest FROM posthog.persons_up_to_date GROUP BY id);
+CREATE VIEW posthog.persons_up_to_date_view AS SELECT
+ id,
+ minMerge(created_at_) AS created_at,
+ argMaxMerge(team_id) AS team_id,
+ argMaxMerge(properties) AS properties,
+ argMaxMerge(is_identified) AS is_identified,
+ maxMerge(updated_at) AS updated_at
+FROM posthog.persons_up_to_date
+GROUP BY
+ id;
+CREATE VIEW posthog.raw_sessions_v AS SELECT
+ session_id_v7,
+ fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000)) AS session_timestamp,
+ team_id,
+ argMaxMerge(distinct_id) AS distinct_id,
+ 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(initial_browser) AS initial_browser,
+ argMinMerge(initial_browser_version) AS initial_browser_version,
+ argMinMerge(initial_os) AS initial_os,
+ argMinMerge(initial_os_version) AS initial_os_version,
+ argMinMerge(initial_device_type) AS initial_device_type,
+ argMinMerge(initial_viewport_width) AS initial_viewport_width,
+ argMinMerge(initial_viewport_height) AS initial_viewport_height,
+ argMinMerge(initial_geoip_country_code) AS initial_geoip_country_code,
+ argMinMerge(initial_geoip_subdivision_1_code) AS initial_geoip_subdivision_1_code,
+ argMinMerge(initial_geoip_subdivision_1_name) AS initial_geoip_subdivision_1_name,
+ argMinMerge(initial_geoip_subdivision_city_name) AS initial_geoip_subdivision_city_name,
+ argMinMerge(initial_geoip_time_zone) AS initial_geoip_time_zone,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ argMinMerge(initial__kx) AS initial__kx,
+ argMinMerge(initial_irclid) AS initial_irclid,
+ sum(pageview_count) AS pageview_count,
+ uniqMerge(pageview_uniq) AS pageview_uniq,
+ sum(autocapture_count) AS autocapture_count,
+ uniqMerge(autocapture_uniq) AS autocapture_uniq,
+ sum(screen_count) AS screen_count,
+ uniqMerge(screen_uniq) AS screen_uniq,
+ max(maybe_has_session_replay) AS maybe_has_session_replay,
+ uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,
+ argMinMerge(vitals_lcp) AS vitals_lcp
+FROM posthog.raw_sessions
+GROUP BY
+ session_id_v7, team_id;
+CREATE VIEW posthog.sessions_v AS SELECT
+ session_id,
+ team_id,
+ any(distinct_id) AS distinct_id,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(exit_url) AS exit_url,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ sumMap(event_count_map) AS event_count_map,
+ sum(pageview_count) AS pageview_count,
+ sum(autocapture_count) AS autocapture_count
+FROM posthog.sessions
+GROUP BY
+ session_id, team_id;
+CREATE OR REPLACE DICTIONARY posthog.channel_definition_dict (`domain` String, `kind` String, `domain_type` Nullable(String), `type_if_paid` Nullable(String), `type_if_organic` Nullable(String)) PRIMARY KEY domain, kind SOURCE(CLICKHOUSE(USER 'dict_reader' TABLE 'channel_definition')) LAYOUT(COMPLEX_KEY_HASHED()) LIFETIME(MIN 3000 MAX 3600);
+CREATE OR REPLACE DICTIONARY posthog.web_bot_definition_dict (`regexp` String, `name` String, `category` String, `traffic_type` String, `operator` String) PRIMARY KEY regexp SOURCE(CLICKHOUSE(USER 'default' DB 'posthog' TABLE 'web_bot_definition')) LAYOUT(REGEXP_TREE()) LIFETIME(MIN 3000 MAX 3600);
+CREATE OR REPLACE DICTIONARY posthog.web_pre_aggregated_teams_dict (`team_id` UInt64) PRIMARY KEY team_id SOURCE(CLICKHOUSE(USER 'dict_reader' QUERY 'SELECT team_id FROM `web_pre_aggregated_teams` FINAL WHERE version > 0')) LAYOUT(HASHED()) LIFETIME(MIN 3000 MAX 3600);
+CREATE TABLE posthog.app_metrics2 (
+ team_id Int64,
+ timestamp DateTime64(6, 'UTC'),
+ app_source LowCardinality(String),
+ app_source_id String,
+ instance_id String,
+ metric_kind LowCardinality(String),
+ metric_name LowCardinality(String),
+ count SimpleAggregateFunction(sum, Int64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_app_metrics2', rand());
+CREATE TABLE posthog.distinct_id_usage (
+ team_id Int64,
+ distinct_id String,
+ minute DateTime,
+ event_count UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_distinct_id_usage', sipHash64(distinct_id));
+CREATE TABLE posthog.distributed_person (
+ id UUID,
+ created_at DateTime,
+ team_id Int64,
+ properties String,
+ is_identified Int8,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_person', sipHash64(id));
+CREATE TABLE posthog.distributed_person_distinct_id (
+ id Int64,
+ distinct_id String,
+ person_id UUID,
+ team_id Int64,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_person_distinct_id', sipHash64(distinct_id));
+CREATE TABLE posthog.distributed_posthog_document_embeddings_text_embedding_3_large_3072 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_large_3072', cityHash64(document_id));
+CREATE TABLE posthog.distributed_posthog_document_embeddings_text_embedding_3_small_1536 (
+ team_id Int64,
+ product LowCardinality(String),
+ document_type LowCardinality(String),
+ rendering LowCardinality(String),
+ document_id String,
+ timestamp DateTime64(3, 'UTC'),
+ inserted_at DateTime64(3, 'UTC'),
+ content String DEFAULT '',
+ metadata String DEFAULT '{}',
+ embedding Array(Float64),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_posthog_document_embeddings_text_embedding_3_small_1536', cityHash64(document_id));
+CREATE TABLE posthog.events (
+ uuid UUID,
+ event String,
+ properties String,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ elements_hash String,
+ created_at DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ elements_chain 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',
+ $group_3 String COMMENT 'column_materializer::$group_3',
+ $group_4 String COMMENT 'column_materializer::$group_4',
+ $window_id String COMMENT 'column_materializer::$window_id',
+ $session_id String COMMENT 'column_materializer::$session_id',
+ group_0 String ALIAS `$group_0`,
+ group_1 String ALIAS `$group_1`,
+ group_2 String ALIAS `$group_2`,
+ group_3 String ALIAS `$group_3`,
+ group_4 String ALIAS `$group_4`,
+ person_id UUID,
+ person_properties String,
+ group0_properties String,
+ group1_properties String,
+ group2_properties String,
+ group3_properties String,
+ group4_properties String,
+ person_created_at DateTime64(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),
+ 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_feature_flags Map(String, String),
+ is_deleted Bool,
+ person_properties_map_custom Map(String, String),
+ mat_$ai_trace_id Nullable(String) COMMENT 'column_materializer::properties::$ai_trace_id',
+ $session_id_uuid Nullable(UInt128),
+ consumer_breadcrumbs Array(String),
+ properties_group_ai Map(String, String),
+ mat_historical_migration Nullable(String) COMMENT 'column_materializer::properties::historical_migration',
+ 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',
+ 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.experiment_exposures_preaggregated (
+ team_id Int64,
+ job_id UUID,
+ entity_id String,
+ variant String,
+ first_exposure_time DateTime64(6, 'UTC'),
+ last_exposure_time DateTime64(6, 'UTC'),
+ exposure_event_uuid UUID,
+ exposure_session_id String,
+ breakdown_value Array(String),
+ computed_at DateTime64(6, 'UTC') DEFAULT now(),
+ expires_at Date DEFAULT today() + toIntervalDay(7)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_experiment_exposures_preaggregated', cityHash64(entity_id));
+CREATE TABLE posthog.flag_evaluations (
+ uuid UUID,
+ event LowCardinality(String),
+ properties String,
+ timestamp DateTime64(6, 'UTC'),
+ team_id Int64,
+ distinct_id String,
+ created_at DateTime64(6, 'UTC'),
+ person_id UUID,
+ inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,
+ $group_0 String COMMENT 'column_materializer::$group_0',
+ $group_1 String COMMENT 'column_materializer::$group_1',
+ $group_2 String COMMENT 'column_materializer::$group_2',
+ $group_3 String COMMENT 'column_materializer::$group_3',
+ $group_4 String COMMENT 'column_materializer::$group_4',
+ flag_key String COMMENT 'column_materializer::properties::$feature_flag',
+ response LowCardinality(String) COMMENT 'column_materializer::properties::$feature_flag_response',
+ session_id String COMMENT 'column_materializer::properties::$session_id',
+ request_id String COMMENT 'column_materializer::properties::$feature_flag_request_id',
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_flag_evaluations', sipHash64(distinct_id));
+CREATE TABLE posthog.heatmaps (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ timestamp DateTime64(6, 'UTC'),
+ x Int16,
+ y Int16,
+ scale_factor Int16,
+ viewport_width Int16,
+ viewport_height Int16,
+ pointer_target_fixed Bool,
+ current_url String,
+ type LowCardinality(String),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_heatmaps', cityHash64(concat(toString(team_id), '-', session_id, '-', toString(toDate(timestamp)))));
+CREATE TABLE posthog.log_entries (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_log_entries', rand());
+CREATE TABLE posthog.new_writable_sessions (
+ session_id String,
+ team_id Int64,
+ distinct_id SimpleAggregateFunction(any, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ entry_url AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ exit_url AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ initial_referring_domain AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_campaign AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_medium AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_term AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_utm_content AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gad_source AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gclsrc AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_dclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_gbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_wbraid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_fbclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_msclkid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_twclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_li_fat_id AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_mc_cid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_igshid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ initial_ttclid AggregateFunction(argMin, String, DateTime64(6, 'UTC')),
+ event_count_map SimpleAggregateFunction(sumMap, Map(String, Int64)),
+ pageview_count SimpleAggregateFunction(sum, Int64),
+ autocapture_count SimpleAggregateFunction(sum, Int64)
+) ENGINE = Distributed('sessions', 'posthog', 'sessions', sipHash64(session_id));
+CREATE TABLE posthog.performance_events (
+ uuid UUID,
+ session_id String,
+ window_id String,
+ pageview_id String,
+ distinct_id String,
+ timestamp DateTime64(3),
+ time_origin DateTime64(3, 'UTC'),
+ entry_type LowCardinality(String),
+ name String,
+ team_id Int64,
+ current_url String,
+ start_time Float64,
+ duration Float64,
+ redirect_start Float64,
+ redirect_end Float64,
+ worker_start Float64,
+ fetch_start Float64,
+ domain_lookup_start Float64,
+ domain_lookup_end Float64,
+ connect_start Float64,
+ secure_connection_start Float64,
+ connect_end Float64,
+ request_start Float64,
+ response_start Float64,
+ response_end Float64,
+ decoded_body_size Int64,
+ encoded_body_size Int64,
+ initiator_type LowCardinality(String),
+ next_hop_protocol LowCardinality(String),
+ render_blocking_status LowCardinality(String),
+ response_status Int64,
+ transfer_size Int64,
+ largest_contentful_paint_element String,
+ largest_contentful_paint_render_time Float64,
+ largest_contentful_paint_load_time Float64,
+ largest_contentful_paint_size Float64,
+ largest_contentful_paint_id String,
+ largest_contentful_paint_url String,
+ dom_complete Float64,
+ dom_content_loaded_event Float64,
+ dom_interactive Float64,
+ load_event_end Float64,
+ load_event_start Float64,
+ redirect_count Int64,
+ navigation_type LowCardinality(String),
+ unload_event_end Float64,
+ unload_event_start Float64,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_performance_events', sipHash64(session_id));
+CREATE TABLE posthog.preaggregation_results (
+ team_id Int64,
+ job_id UUID,
+ time_window_start DateTime64(6, 'UTC'),
+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7),
+ breakdown_value Array(String),
+ uniq_exact_state AggregateFunction(uniqExact, UUID)
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_preaggregation_results', sipHash64(job_id));
+CREATE TABLE posthog.raw_sessions_v3 (
+ team_id Int64,
+ session_id_v7 UInt128,
+ session_timestamp DateTime64(3) MATERIALIZED fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80))),
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ distinct_ids AggregateFunction(groupUniqArray, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),
+ entry_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ browser AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ browser_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ device_type AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ viewport_width AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ viewport_height AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ geoip_country_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_city_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_time_zone AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_referring_domain AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_campaign AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_medium AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_term AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_content AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gad_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_fbclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_has_gclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_has_fbclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_ad_ids_map AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC')),
+ entry_ad_ids_set AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC')),
+ entry_channel_type_properties AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC')),
+ pageview_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ autocapture_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ 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_keys SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ event_names SimpleAggregateFunction(groupUniqArrayArray, 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 (
+ session_id String,
+ team_id Int64,
+ embeddings Array(Float32),
+ generation_timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),
+ source_type LowCardinality(String),
+ input String
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_embeddings', sipHash64(session_id));
+CREATE TABLE posthog.session_replay_events (
+ session_id String,
+ team_id Int64,
+ distinct_id String,
+ min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ click_count SimpleAggregateFunction(sum, Int64),
+ keypress_count SimpleAggregateFunction(sum, Int64),
+ mouse_activity_count SimpleAggregateFunction(sum, Int64),
+ active_milliseconds SimpleAggregateFunction(sum, Int64),
+ console_log_count SimpleAggregateFunction(sum, Int64),
+ console_warn_count SimpleAggregateFunction(sum, Int64),
+ console_error_count SimpleAggregateFunction(sum, Int64),
+ size SimpleAggregateFunction(sum, Int64),
+ message_count SimpleAggregateFunction(sum, Int64),
+ event_count SimpleAggregateFunction(sum, Int64),
+ _timestamp SimpleAggregateFunction(max, DateTime),
+ snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
+ ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
+CREATE TABLE posthog.writable_raw_sessions_v3 (
+ team_id Int64,
+ session_id_v7 UInt128,
+ session_timestamp DateTime64(3) MATERIALIZED fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80))),
+ distinct_id AggregateFunction(argMax, String, DateTime64(6, 'UTC')),
+ distinct_ids AggregateFunction(groupUniqArray, String),
+ min_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
+ max_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ max_inserted_at SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ urls SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String)),
+ entry_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ end_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ last_external_click_url AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC')),
+ browser AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ browser_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ os_version AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ device_type AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ viewport_width AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ viewport_height AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC')),
+ geoip_country_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_code AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_1_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_subdivision_city_name AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ geoip_time_zone AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_referring_domain AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_campaign AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_medium AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_term AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_utm_content AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_gad_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_fbclid AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ entry_has_gclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_has_fbclid AggregateFunction(argMin, Bool, DateTime64(6, 'UTC')),
+ entry_ad_ids_map AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC')),
+ entry_ad_ids_set AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC')),
+ entry_channel_type_properties AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC')),
+ pageview_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ autocapture_uniq AggregateFunction(uniqExact, Nullable(UUID)),
+ 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_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 VIEW posthog.custom_metrics AS SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_test
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_replication_queue
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_server_crash
+UNION ALL
+SELECT *
+FROM posthog.custom_metrics_table_sizes
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_part_counts
+UNION ALL
+SELECT * REPLACE(toFloat64(value) AS value)
+FROM posthog.custom_metrics_dictionaries
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_S3DiskBytesUsed' AS name,
+ map('instance', hostname(), 'disk', disk_name) AS labels,
+ toFloat64(sum(bytes_on_disk)) AS value,
+ 'Bytes currently used by ClickHouse parts on S3-backed disks on this node' AS help,
+ 'gauge' AS type
+FROM system.parts
+WHERE disk_name IN ('s3disk', 'cache')
+GROUP BY
+ disk_name
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeFailures15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(count()) AS value,
+ 'Number of failed merge operations in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM system.part_log
+WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+AND
+ (event_type = 'MergeParts')
+AND
+ (error > 0)
+AND
+ (merge_reason != 'NotAMerge')
+AND
+ (error != 40)
+UNION ALL
+SELECT
+ 'ClickHouseCustomMetric_MergeRetriesMaxPerTable15m' AS name,
+ map('instance', hostname()) AS labels,
+ toFloat64(max(cnt)) AS value,
+ 'Max failed merge retries for any single table in the last 15 minutes' AS help,
+ 'gauge' AS type
+FROM
+ (
+ SELECT count() AS cnt
+ FROM system.part_log
+ WHERE
+ (event_time >= (now() - toIntervalMinute(15)))
+ AND
+ (event_type = 'MergeParts')
+ AND
+ (error > 0)
+ AND
+ (merge_reason != 'NotAMerge')
+ AND
+ (error != 40)
+ GROUP BY
+ database, `table`, partition_id
+ );
+CREATE VIEW posthog.events_batch_export AS SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ (events.timestamp >= ({interval_start: DateTime64} - toIntervalDay({lookback_days: Int32})))
+AND
+ (events.timestamp < ({interval_end: DateTime64} + toIntervalDay(1)))
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1;
+CREATE VIEW posthog.events_batch_export_unbounded AS SELECT
+ team_id AS team_id,
+ timestamp AS timestamp,
+ event AS event,
+ distinct_id AS distinct_id,
+ toString(uuid) AS uuid,
+ coalesce(inserted_at, _timestamp) AS _inserted_at,
+ created_at AS created_at,
+ elements_chain AS elements_chain,
+ toString(person_id) AS person_id,
+ nullIf(properties, '') AS properties,
+ nullIf(person_properties, '') AS person_properties,
+ nullIf(JSONExtractString(properties, '$set'), '') AS set,
+ nullIf(JSONExtractString(properties, '$set_once'), '') AS set_once
+FROM posthog.events
+PREWHERE
+ (coalesce(events.inserted_at, events._timestamp) >= {interval_start: DateTime64}) AND (coalesce(events.inserted_at, events._timestamp) < {interval_end: DateTime64})
+WHERE
+ (team_id = {team_id: Int64})
+AND
+ ((length({include_events: Array(String)}) = 0) OR (event IN ({include_events: Array(String)})))
+AND
+ ((length({exclude_events: Array(String)}) = 0) OR (event NOT IN ({exclude_events: Array(String)})))
+ORDER BY _inserted_at ASC, event ASC
+LIMIT 1 BY team_id, event, cityHash64(events.distinct_id), cityHash64(events.uuid)
+SETTINGS
+ optimize_aggregation_in_order = 1;
+CREATE VIEW posthog.events_with_array_props_view AS SELECT
+ uuid,
+ event,
+ properties,
+ timestamp,
+ team_id,
+ distinct_id,
+ elements_chain,
+ created_at,
+ arrayMap(k -> toString(k.1), JSONExtractKeysAndValuesRaw(properties)) AS array_property_keys,
+ arrayMap(k -> toString(k.2), JSONExtractKeysAndValuesRaw(properties)) AS array_property_values,
+ _timestamp,
+ _offset
+FROM posthog.events;
+CREATE VIEW posthog.posthog_document_embeddings_union_view AS SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-small-1536' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_small_1536
+UNION ALL
+SELECT
+ team_id,
+ product,
+ document_type,
+ rendering,
+ document_id,
+ timestamp,
+ inserted_at,
+ content,
+ metadata,
+ embedding,
+ _timestamp,
+ _offset,
+ _partition,
+ 'text-embedding-3-large-3072' AS model_name
+FROM posthog.distributed_posthog_document_embeddings_text_embedding_3_large_3072;
+CREATE VIEW posthog.raw_sessions_v3_v AS 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;
+CREATE VIEW posthog.team_events_last_month_view AS SELECT team_id, count() AS event_count
+FROM posthog.events
+WHERE
+ (timestamp > (now() - toIntervalMonth(1)))
+AND
+ (timestamp < now())
+GROUP BY
+ team_id
+ORDER BY event_count DESC;