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): model dev satellites in hcl, add batch_exports role (#84958)

Bryan Ciaraldi9e21a9093675
diff --git a/.agents/skills/clickhouse-migrations/SKILL.md b/.agents/skills/clickhouse-migrations/SKILL.md
index 067dd3a85da7..d8022de6d934 100644
--- a/.agents/skills/clickhouse-migrations/SKILL.md
+++ b/.agents/skills/clickhouse-migrations/SKILL.md
@@ -26,18 +26,19 @@ operations = [
Only the members of `NodeRole` in `posthog/clickhouse/client/connection.py` are valid: `ALL`, `DATA`,
`INGESTION_EVENTS`, `INGESTION_SMALL`, `INGESTION_MEDIUM`, `ENDPOINTS`, `LOGS`, `AI_EVENTS`, `AUX`,
-`OPS`, `SESSIONS`. A name that is not in that enum fails at import, which aborts migration discovery
-and takes every job that runs migrations down with it.
+`BATCH_EXPORTS`, `OPS`, `SESSIONS`. A name that is not in that enum fails at import, which aborts
+migration discovery and takes every job that runs migrations down with it.
Pick the role by **which cluster owns the object**, not by its type alone:
- `[NodeRole.DATA]`: anything on the main cluster — sharded tables, non-sharded replicated tables,
distributed read tables, views, dictionaries. The default, and right for most migrations.
- `[NodeRole.INGESTION_SMALL]`: writable tables, Kafka tables, materialized views on the ingestion layer
-- `[NodeRole.OPS]`, `[NodeRole.LOGS]`, `[NodeRole.AUX]`, `[NodeRole.AI_EVENTS]`, `[NodeRole.SESSIONS]`:
- objects that live on a satellite cluster. A table for one of those on `DATA` lands on the wrong
- nodes and leaves the intended cluster without it, so check where the object is read and written
- before defaulting to `DATA`.
+- `[NodeRole.OPS]`, `[NodeRole.LOGS]`, `[NodeRole.AUX]`, `[NodeRole.AI_EVENTS]`, `[NodeRole.SESSIONS]`,
+ `[NodeRole.BATCH_EXPORTS]`: objects that live on a satellite cluster. A table for one of those on
+ `DATA` lands on the wrong nodes and leaves the intended cluster without it, so check where the
+ object is read and written before defaulting to `DATA`. Dev runs the same satellite clusters as
+ US/EU prod — never branch on `CLOUD_DEPLOYMENT` to give dev a different layout.
- `[NodeRole.ALL]`: rarely used
### Table engines quick reference
diff --git a/posthog/clickhouse/client/connection.py b/posthog/clickhouse/client/connection.py
index 2baad1519150..75356728f318 100644
--- a/posthog/clickhouse/client/connection.py
+++ b/posthog/clickhouse/client/connection.py
@@ -36,6 +36,7 @@ class NodeRole(StrEnum):
# Below nodes are part of separate clusters.
AI_EVENTS = "ai_events"
AUX = "aux"
+ BATCH_EXPORTS = "batch_exports"
OPS = "ops"
SESSIONS = "sessions"
@@ -44,11 +45,19 @@ class NodeRole(StrEnum):
# LOGS hosts replicated tables too (metric_series1/metric_samples1 via migration
# 0283); non-sharded ALTERs on it run via any_host_by_roles like the satellites.
DATA_NODE_ROLES: frozenset[NodeRole] = frozenset(
- {NodeRole.DATA, NodeRole.AI_EVENTS, NodeRole.AUX, NodeRole.LOGS, NodeRole.OPS, NodeRole.SESSIONS}
+ {
+ NodeRole.DATA,
+ NodeRole.AI_EVENTS,
+ NodeRole.AUX,
+ NodeRole.BATCH_EXPORTS,
+ NodeRole.LOGS,
+ NodeRole.OPS,
+ NodeRole.SESSIONS,
+ }
)
# Single-shard data clusters: ALTER runs on one host, replication propagates.
SINGLE_SHARD_DATA_NODE_ROLES: frozenset[NodeRole] = frozenset(
- {NodeRole.AI_EVENTS, NodeRole.AUX, NodeRole.OPS, NodeRole.SESSIONS}
+ {NodeRole.AI_EVENTS, NodeRole.AUX, NodeRole.BATCH_EXPORTS, NodeRole.OPS, NodeRole.SESSIONS}
)
diff --git a/posthog/clickhouse/hcl/golden/dev/ai_events.hcl b/posthog/clickhouse/hcl/golden/dev/ai_events.hcl
index 659228d54d89..b4ebccf8e54b 100644
--- a/posthog/clickhouse/hcl/golden/dev/ai_events.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/ai_events.hcl
@@ -1,4 +1,355 @@
database "posthog" {
+ table "ai_events" {
+ order_by = ["team_id", "trace_id", "timestamp"]
+ partition_by = "toYYYYMM(drop_date)"
+ ttl = "drop_date"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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"
+ }
+ index "idx_trace_id" {
+ expr = "trace_id"
+ type = "bloom_filter(0.001)"
+ granularity = 1
+ }
+ index "idx_session_id" {
+ expr = "session_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "idx_parent_id" {
+ expr = "parent_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "idx_span_id" {
+ expr = "span_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "idx_prompt_name" {
+ expr = "prompt_name"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "idx_model" {
+ expr = "model"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "idx_experiment_id" {
+ expr = "experiment_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "idx_event" {
+ expr = "event"
+ type = "set(20)"
+ granularity = 1
+ }
+ index "idx_is_error" {
+ expr = "is_error"
+ type = "set(2)"
+ granularity = 1
+ }
+ index "idx_provider" {
+ expr = "provider"
+ type = "set(50)"
+ granularity = 1
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ai_events/tables/{shard}/posthog.ai_events"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "kafka_ai_events_json_ws" {
+ 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 "person_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ engine "kafka" {
+ broker_list = "warpstream_ingestion"
+ topic_list = "kafka_topic_list = 'clickhouse_ai_events_json'"
+ group_name = "kafka_group_name = 'clickhouse_ai_events_ws'"
+ format = "kafka_format = 'JSONEachRow'"
+ num_consumers = 1
+ max_block_size = 5000
+ skip_broken_messages = 100
+ poll_timeout_ms = 10000
+ thread_per_consumer = true
+ }
+ }
+
+ table "person" {
+ 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"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ column "last_seen_at" {
+ type = "Nullable(DateTime64(3))"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "person"
+ }
+ }
+
+ table "person_distinct_id2" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "is_deleted" {
+ type = "Int8"
+ }
+ column "version" {
+ type = "Int64"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "person_distinct_id2"
+ }
+ }
+
table "query_log_archive" {
column "hostname" {
type = "LowCardinality(String)"
@@ -449,6 +800,260 @@ database "posthog" {
}
}
+ materialized_view "ai_events_json_ws_mv" {
+ to_table = "posthog.ai_events"
+ query = <<SQL
+SELECT
+ uuid,
+ event,
+ timestamp,
+ team_id,
+ distinct_id,
+ person_id,
+ concat(
+ '{',
+ arrayStringConcat(
+ arrayMap(
+ x -> concat('"', x.1, '":', x.2),
+ arrayFilter(
+ x -> ((x.1) NOT IN ('$ai_input', '$ai_output', '$ai_output_choices', '$ai_input_state', '$ai_output_state', '$ai_tools')),
+ JSONExtractKeysAndValuesRaw(src.properties)
+ )
+ ),
+ ','
+ ),
+ '}'
+ ) AS properties,
+ JSONExtractString(src.properties, '$ai_trace_id') AS trace_id,
+ JSONExtract(src.properties, '$ai_session_id', 'Nullable(String)') AS session_id,
+ JSONExtract(src.properties, '$ai_parent_id', 'Nullable(String)') AS parent_id,
+ JSONExtract(src.properties, '$ai_span_id', 'Nullable(String)') AS span_id,
+ JSONExtract(src.properties, '$ai_span_type', 'Nullable(String)') AS span_type,
+ JSONExtract(src.properties, '$ai_generation_id', 'Nullable(String)') AS generation_id,
+ JSONExtract(src.properties, '$ai_experiment_id', 'Nullable(String)') AS experiment_id,
+ JSONExtract(src.properties, '$ai_span_name', 'Nullable(String)') AS span_name,
+ JSONExtract(src.properties, '$ai_trace_name', 'Nullable(String)') AS trace_name,
+ JSONExtract(src.properties, '$ai_prompt_name', 'Nullable(String)') AS prompt_name,
+ JSONExtract(src.properties, '$ai_model', 'Nullable(String)') AS model,
+ JSONExtract(src.properties, '$ai_provider', 'Nullable(String)') AS provider,
+ JSONExtract(src.properties, '$ai_framework', 'Nullable(String)') AS framework,
+ JSONExtract(src.properties, '$ai_total_tokens', 'Nullable(Int64)') AS total_tokens,
+ JSONExtract(src.properties, '$ai_input_tokens', 'Nullable(Int64)') AS input_tokens,
+ JSONExtract(src.properties, '$ai_output_tokens', 'Nullable(Int64)') AS output_tokens,
+ JSONExtract(src.properties, '$ai_text_input_tokens', 'Nullable(Int64)') AS text_input_tokens,
+ JSONExtract(src.properties, '$ai_text_output_tokens', 'Nullable(Int64)') AS text_output_tokens,
+ JSONExtract(src.properties, '$ai_image_input_tokens', 'Nullable(Int64)') AS image_input_tokens,
+ JSONExtract(src.properties, '$ai_image_output_tokens', 'Nullable(Int64)') AS image_output_tokens,
+ JSONExtract(src.properties, '$ai_audio_input_tokens', 'Nullable(Int64)') AS audio_input_tokens,
+ JSONExtract(src.properties, '$ai_audio_output_tokens', 'Nullable(Int64)') AS audio_output_tokens,
+ JSONExtract(src.properties, '$ai_video_input_tokens', 'Nullable(Int64)') AS video_input_tokens,
+ JSONExtract(src.properties, '$ai_video_output_tokens', 'Nullable(Int64)') AS video_output_tokens,
+ JSONExtract(src.properties, '$ai_reasoning_tokens', 'Nullable(Int64)') AS reasoning_tokens,
+ JSONExtract(src.properties, '$ai_cache_read_input_tokens', 'Nullable(Int64)') AS cache_read_input_tokens,
+ JSONExtract(src.properties, '$ai_cache_creation_input_tokens', 'Nullable(Int64)') AS cache_creation_input_tokens,
+ JSONExtract(src.properties, '$ai_web_search_count', 'Nullable(Int64)') AS web_search_count,
+ JSONExtract(src.properties, '$ai_input_cost_usd', 'Nullable(Float64)') AS input_cost_usd,
+ JSONExtract(src.properties, '$ai_output_cost_usd', 'Nullable(Float64)') AS output_cost_usd,
+ JSONExtract(src.properties, '$ai_total_cost_usd', 'Nullable(Float64)') AS total_cost_usd,
+ JSONExtract(src.properties, '$ai_request_cost_usd', 'Nullable(Float64)') AS request_cost_usd,
+ JSONExtract(src.properties, '$ai_web_search_cost_usd', 'Nullable(Float64)') AS web_search_cost_usd,
+ JSONExtract(src.properties, '$ai_audio_cost_usd', 'Nullable(Float64)') AS audio_cost_usd,
+ JSONExtract(src.properties, '$ai_image_cost_usd', 'Nullable(Float64)') AS image_cost_usd,
+ JSONExtract(src.properties, '$ai_video_cost_usd', 'Nullable(Float64)') AS video_cost_usd,
+ JSONExtract(src.properties, '$ai_latency', 'Nullable(Float64)') AS latency,
+ JSONExtract(src.properties, '$ai_time_to_first_token', 'Nullable(Float64)') AS time_to_first_token,
+ if((JSONExtractRaw(src.properties, '$ai_is_error') IN ('true', '"true"')), 1, 0) AS is_error,
+ JSONExtract(src.properties, '$ai_error', 'Nullable(String)') AS error,
+ JSONExtract(src.properties, '$ai_error_type', 'Nullable(String)') AS error_type,
+ JSONExtract(src.properties, '$ai_error_normalized', 'Nullable(String)') AS error_normalized,
+ nullIf(JSONExtractRaw(src.properties, '$ai_input'), '') AS input,
+ nullIf(JSONExtractRaw(src.properties, '$ai_output'), '') AS output,
+ nullIf(JSONExtractRaw(src.properties, '$ai_output_choices'), '') AS output_choices,
+ nullIf(JSONExtractRaw(src.properties, '$ai_input_state'), '') AS input_state,
+ nullIf(JSONExtractRaw(src.properties, '$ai_output_state'), '') AS output_state,
+ nullIf(JSONExtractRaw(src.properties, '$ai_tools'), '') AS tools,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.kafka_ai_events_json_ws AS src
+SQL
+
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "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 "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 = "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 = "Nullable(String)"
+ }
+ column "provider" {
+ type = "Nullable(String)"
+ }
+ column "framework" {
+ type = "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 = "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 = "Nullable(DateTime)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
materialized_view "ops_query_log_archive_mv" {
to_table = "posthog.writable_query_log_archive"
query = <<SQL
diff --git a/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl b/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl
new file mode 100644
index 000000000000..de920a8457be
--- /dev/null
+++ b/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl
@@ -0,0 +1,4008 @@
+database "posthog" {
+ 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 "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 "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 "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 "hog_invocation_results_data" {
+ order_by = ["team_id", "function_kind", "function_id", "invocation_id"]
+ partition_by = "toYYYYMMDD(scheduled_at)"
+ ttl = "toDate(scheduled_at) + toIntervalDay(30)"
+ settings = {
+ index_granularity = "1024"
+ storage_policy = "s3_tiered"
+ ttl_only_drop_parts = "1"
+ }
+ 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')"
+ default = "scheduled_at"
+ }
+ 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"
+ default = "0"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "status_idx" {
+ expr = "status"
+ type = "set(8)"
+ granularity = 1
+ }
+ index "function_idx" {
+ expr = "function_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "event_uuid_idx" {
+ expr = "event_uuid"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ index "is_retry_idx" {
+ expr = "is_retry"
+ type = "set(2)"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.hog_invocation_results_data"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "ingestion_warnings_v2" {
+ order_by = ["team_id", "type", "timestamp"]
+ partition_by = "toYYYYMM(timestamp)"
+ ttl = "toDateTime(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "8192"
+ }
+ 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 "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.ingestion_warnings_v2"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ 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_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"
+ }
+ engine "kafka" {
+ broker_list = "warpstream_cyclotron"
+ topic_list = "kafka_topic_list = 'clickhouse_hog_invocation_results'"
+ group_name = "kafka_group_name = 'clickhouse_hog_invocation_results'"
+ format = "kafka_format = 'JSONEachRow'"
+ skip_broken_messages = 100
+ }
+ }
+
+ table "kafka_ingestion_warnings_v2" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "source" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "details" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ engine "kafka" {
+ broker_list = "warpstream_ingestion"
+ topic_list = "kafka_topic_list = 'clickhouse_ingestion_warnings'"
+ group_name = "kafka_group_name = 'clickhouse_ingestion_warnings_v2'"
+ format = "kafka_format = 'JSONEachRow'"
+ }
+ }
+
+ table "kafka_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"
+ }
+ engine "kafka" {
+ broker_list = "warpstream_cyclotron"
+ topic_list = "kafka_topic_list = 'clickhouse_message_assets'"
+ group_name = "kafka_group_name = 'clickhouse_message_assets'"
+ format = "kafka_format = 'JSONEachRow'"
+ skip_broken_messages = 100
+ }
+ }
+
+ table "kafka_property_values" {
+ column "team_id" {
+ type = "Int64"
+ }
+ column "property_type" {
+ type = "LowCardinality(String)"
+ }
+ column "property_key" {
+ type = "String"
+ }
+ column "property_value" {
+ type = "String"
+ }
+ column "property_count" {
+ type = "UInt64"
+ }
+ engine "kafka" {
+ broker_list = "warpstream_ingestion"
+ topic_list = "kafka_topic_list = 'clickhouse_property_values'"
+ group_name = "kafka_group_name = 'clickhouse_property_values'"
+ format = "kafka_format = 'JSONEachRow'"
+ num_consumers = 1
+ thread_per_consumer = true
+ }
+ }
+
+ 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 "message_assets_data" {
+ order_by = ["team_id", "function_kind", "function_id", "invocation_id", "action_id"]
+ partition_by = "toYYYYMMDD(sent_at)"
+ ttl = "toDate(sent_at) + toIntervalDay(30)"
+ settings = {
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
+ }
+ 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"
+ default = "0"
+ }
+ column "html" {
+ type = "String"
+ codec = "ZSTD(3)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "parent_run_idx" {
+ expr = "parent_run_id"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ 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 "recipient_idx" {
+ expr = "recipient"
+ type = "bloom_filter(0.01)"
+ granularity = 1
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.message_assets_data"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ table "property_values" {
+ order_by = ["team_id", "property_type", "property_key", "property_value"]
+ ttl = "last_seen + toIntervalDay(30)"
+ settings = {
+ index_granularity = "8192"
+ }
+ 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()"
+ }
+ index "idx_property_value_ngrambf" {
+ expr = "lower(property_value)"
+ type = "ngrambf_v1(3, 32768, 3, 0)"
+ granularity = 1
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.property_values"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ 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_error_tracking_fingerprint_issue_state" {
+ order_by = ["team_id", "fingerprint"]
+ settings = {
+ index_granularity = "512"
+ }
+ 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"
+ }
+ index "kafka_timestamp_minmax_raw_error_tracking_fingerprint_issue_state" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.raw_error_tracking_fingerprint_issue_state"
+ replica_name = "{replica}-{shard}"
+ version_column = "version"
+ }
+ }
+
+ 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 "sharded_conversion_goal_attributed_preaggregated" {
+ order_by = ["team_id", "job_id", "person_id", "conversion_timestamp", "touchpoint_timestamp"]
+ 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 "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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.conversion_goal_attributed_preaggregated"
+ replica_name = "{replica}-{shard}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_experiment_metric_events_preaggregated" {
+ order_by = ["team_id", "job_id", "entity_id", "timestamp", "event_uuid"]
+ 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 "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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.experiment_metric_events_preaggregated"
+ replica_name = "{replica}-{shard}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_ingestion_warnings" {
+ order_by = ["team_id", "toHour(timestamp)", "type", "source", "timestamp"]
+ partition_by = "toYear(timestamp)"
+ settings = {
+ index_granularity = "8192"
+ }
+ 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 "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.sharded_ingestion_warnings"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_marketing_conversions_preaggregated" {
+ order_by = ["team_id", "job_id", "person_id", "conversion_timestamp"]
+ 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 "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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.marketing_conversions_preaggregated"
+ replica_name = "{replica}-{shard}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_marketing_costs_preaggregated" {
+ order_by = ["team_id", "job_id", "source_name", "grain", "campaign_id", "ad_group_id", "ad_id", "cost_date"]
+ 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 "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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.marketing_costs_preaggregated"
+ replica_name = "{replica}-{shard}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_marketing_touchpoints_preaggregated" {
+ order_by = ["team_id", "job_id", "person_id", "touchpoint_timestamp"]
+ 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 "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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.marketing_touchpoints_preaggregated"
+ replica_name = "{replica}-{shard}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_session_replay_features" {
+ order_by = ["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 "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 "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_features"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_usage_report_events_preagg" {
+ order_by = ["date", "team_id", "person_mode", "lib", "event"]
+ partition_by = "date"
+ ttl = "date + toIntervalDay(14)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_usage_report_events_preagg"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_web_bot_definition" {
+ order_by = ["id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "parent_id" {
+ type = "UInt64"
+ }
+ column "regexp" {
+ type = "String"
+ }
+ column "keys" {
+ type = "Array(String)"
+ }
+ column "values" {
+ type = "Array(String)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.sharded_web_bot_definition"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "sharded_web_bounces_dimensional_preaggregated" {
+ order_by = ["team_id", "job_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_backend", "mat_metadata_loggedIn"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "toDateTime(expires_at)"
+ settings = {
+ allow_nullable_key = "1"
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_bounces_dimensional_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_web_goals_preaggregated" {
+ order_by = ["team_id", "job_id", "action_id", "time_window_start"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "toDateTime(expires_at)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_goals_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_web_overview_preaggregated" {
+ order_by = ["team_id", "job_id", "time_window_start"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "toDateTime(expires_at)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_overview_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_web_stats_dimensional_preaggregated" {
+ order_by = ["team_id", "job_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_backend", "mat_metadata_loggedIn"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "toDateTime(expires_at)"
+ settings = {
+ allow_nullable_key = "1"
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_stats_dimensional_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_web_stats_frustration_preaggregated" {
+ order_by = ["team_id", "job_id", "breakdown_value", "time_window_start"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "toDateTime(expires_at)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_stats_frustration_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_web_stats_paths_preaggregated" {
+ order_by = ["team_id", "job_id", "breakdown_value", "time_window_start"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "toDateTime(expires_at)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_stats_paths_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_web_stats_paths_preaggregated_pathkey" {
+ order_by = ["team_id", "time_window_start", "breakdown_value", "job_id"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "toDateTime(expires_at)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_stats_paths_preaggregated_pathkey"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_web_stats_preaggregated" {
+ order_by = ["team_id", "job_id", "breakdown_by", "time_window_start", "breakdown_value"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "toDateTime(expires_at)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_stats_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ table "sharded_web_vitals_paths_preaggregated" {
+ order_by = ["team_id", "job_id", "time_window_start", "path"]
+ partition_by = "toYYYYMMDD(expires_at)"
+ ttl = "toDateTime(expires_at)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_vitals_paths_preaggregated"
+ replica_name = "{replica}"
+ version_column = "computed_at"
+ }
+ }
+
+ 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_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_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_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 "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"
+ }
+ }
+
+ materialized_view "hog_invocation_results_mv" {
+ to_table = "posthog.hog_invocation_results_data"
+ query = <<SQL
+SELECT
+ team_id,
+ function_kind,
+ function_id,
+ invocation_id,
+ parent_run_id,
+ status,
+ attempts,
+ is_retry,
+ scheduled_at,
+ if(
+ first_scheduled_at = toDateTime64('1970-01-01 00:00:00', 6, 'UTC'),
+ scheduled_at,
+ first_scheduled_at
+ ) AS first_scheduled_at,
+ started_at,
+ finished_at,
+ duration_ms,
+ error_kind,
+ error_message,
+ event_uuid,
+ distinct_id,
+ person_id,
+ invocation_globals,
+ version,
+ is_deleted,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.kafka_hog_invocation_results
+SQL
+
+ 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 = "Nullable(DateTime)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "ingestion_warnings_v2_mv" {
+ to_table = "posthog.ingestion_warnings_v2"
+ query = <<SQL
+SELECT
+ team_id,
+ source,
+ type,
+ details,
+ timestamp,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.kafka_ingestion_warnings_v2
+SQL
+
+ 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 = "Nullable(DateTime)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "message_assets_mv" {
+ to_table = "posthog.message_assets_data"
+ query = <<SQL
+SELECT
+ team_id,
+ function_kind,
+ function_id,
+ parent_run_id,
+ invocation_id,
+ action_id,
+ kind,
+ distinct_id,
+ person_id,
+ recipient,
+ subject,
+ status,
+ sent_at,
+ version,
+ is_deleted,
+ html,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.kafka_message_assets
+SQL
+
+ 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 = "Nullable(DateTime)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ }
+
+ 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 "property_values_mv" {
+ to_table = "posthog.property_values"
+ query = <<SQL
+SELECT
+ team_id,
+ property_type,
+ property_key,
+ property_value,
+ property_count,
+ coalesce(_timestamp, now()) AS last_seen
+FROM posthog.kafka_property_values
+SQL
+
+ column "team_id" {
+ type = "Int64"
+ }
+ column "property_type" {
+ type = "LowCardinality(String)"
+ }
+ column "property_key" {
+ type = "String"
+ }
+ column "property_value" {
+ type = "String"
+ }
+ column "property_count" {
+ type = "UInt64"
+ }
+ column "last_seen" {
+ type = "DateTime"
+ }
+ }
+
+ 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
+
+ }
+
+ 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" {
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/golden/dev/batch_exports.hcl b/posthog/clickhouse/hcl/golden/dev/batch_exports.hcl
new file mode 100644
index 000000000000..942eb27e2aeb
--- /dev/null
+++ b/posthog/clickhouse/hcl/golden/dev/batch_exports.hcl
@@ -0,0 +1,822 @@
+database "posthog" {
+ 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 "sharded_events_recent" {
+ order_by = ["team_id", "toStartOfHour(inserted_at)", "event", "cityHash64(distinct_id)", "cityHash64(uuid)"]
+ partition_by = "toStartOfDay(inserted_at)"
+ ttl = "toDateTime(inserted_at) + toIntervalDay(7)"
+ settings = {
+ index_granularity = "8192"
+ parts_to_delay_insert = "800"
+ parts_to_throw_insert = "1500"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/batch_exports/{shard}/posthog.sharded_events_recent"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ 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"
+ }
+ }
+
+ 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)"
+ }
+ }
+
+ 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
+
+ }
+}
diff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hcl
index dda0bfb48173..05b0a870b44e 100644
--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl
@@ -313,7 +313,10 @@ database "posthog" {
allow_experimental_reverse_key = "1"
index_granularity = "8192"
index_granularity_bytes = "104857600"
+ map_buckets_strategy = "constant"
map_serialization_version = "with_buckets"
+ max_buckets_in_map = "32"
+ storage_policy = "s3_tiered"
ttl_only_drop_parts = "1"
}
column "time_bucket" {
@@ -2054,6 +2057,120 @@ SQL
}
}
+ materialized_view "kafka_metrics_avro_to_metric_samples" {
+ to_table = "posthog.metric_samples1"
+ query = <<SQL
+SELECT
+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,
+ ifNull(metric_name, '') AS metric_name,
+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,
+ timestamp,
+ ifNull(value, 0) AS value,
+ toUInt64(ifNull(count, 1)) AS count,
+ histogram_bounds,
+ arrayMap(x -> toUInt64(x), histogram_counts) AS histogram_counts,
+ trace_id,
+ span_id,
+ ifNull(trace_flags, 0) AS trace_flags
+FROM posthog.kafka_metrics_avro
+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL
+SETTINGS
+ min_insert_block_size_rows = 0,
+ min_insert_block_size_bytes = 0
+SQL
+
+ column "team_id" {
+ type = "Int32"
+ }
+ column "metric_name" {
+ type = "String"
+ }
+ column "series_fingerprint" {
+ type = "UInt64"
+ }
+ column "timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ }
+ column "histogram_bounds" {
+ type = "Array(Float64)"
+ }
+ column "histogram_counts" {
+ type = "Array(UInt64)"
+ }
+ column "trace_id" {
+ type = "String"
+ }
+ column "span_id" {
+ type = "String"
+ }
+ column "trace_flags" {
+ type = "Int32"
+ }
+ }
+
+ materialized_view "kafka_metrics_avro_to_metric_series" {
+ to_table = "posthog.metric_series1"
+ query = <<SQL
+SELECT
+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,
+ ifNull(metric_name, '') AS metric_name,
+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,
+ ifNull(metric_type, '') AS metric_type,
+ ifNull(unit, '') AS unit,
+ ifNull(aggregation_temporality, '') AS aggregation_temporality,
+ ifNull(is_monotonic, 0) AS is_monotonic,
+ ifNull(service_name, '') AS service_name,
+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)) AS attributes,
+ timestamp AS last_seen
+FROM posthog.kafka_metrics_avro
+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL
+SETTINGS
+ min_insert_block_size_rows = 0,
+ min_insert_block_size_bytes = 0
+SQL
+
+ column "team_id" {
+ type = "Int32"
+ }
+ column "metric_name" {
+ type = "String"
+ }
+ column "series_fingerprint" {
+ type = "UInt64"
+ }
+ column "metric_type" {
+ type = "String"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "aggregation_temporality" {
+ type = "String"
+ }
+ column "is_monotonic" {
+ type = "UInt8"
+ }
+ column "service_name" {
+ type = "String"
+ }
+ column "resource_attributes" {
+ type = "Map(String, String)"
+ }
+ column "attributes" {
+ type = "Map(String, String)"
+ }
+ column "last_seen" {
+ type = "DateTime64(6)"
+ }
+ }
+
materialized_view "logs34_to_log_attributes" {
to_table = "posthog.log_attributes2"
query = <<SQL
diff --git a/posthog/clickhouse/hcl/golden/dev/ops.hcl b/posthog/clickhouse/hcl/golden/dev/ops.hcl
index b0ee41dd8c30..294160fabade 100644
--- a/posthog/clickhouse/hcl/golden/dev/ops.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/ops.hcl
@@ -988,6 +988,49 @@ database "posthog" {
}
}
+ table "sharded_tophog" {
+ order_by = ["pipeline", "lane", "metric", "timestamp", "key"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(30)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ 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 "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/{shard}/posthog.tophog"
+ replica_name = "{replica}"
+ }
+ }
+
table "writable_prom_metrics" {
column "id" {
type = "UUID"
diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hcl
index 8953a5bd0169..d523389d488e 100644
--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl
+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl
@@ -5401,6 +5401,72 @@ SQL
}
}
+ table "logs_volume_buckets" {
+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]
+ partition_by = "toDate(time_bucket)"
+ ttl = "time_bucket + toIntervalDay(42)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "Int32"
+ }
+ column "time_bucket" {
+ type = "DateTime('UTC')"
+ codec = "DoubleDelta, ZSTD(1)"
+ }
+ column "service_name" {
+ type = "LowCardinality(String)"
+ }
+ column "namespace" {
+ type = "LowCardinality(String)"
+ }
+ column "environment" {
+ type = "LowCardinality(String)"
+ }
+ column "severity_text" {
+ type = "LowCardinality(String)"
+ }
+ column "log_count" {
+ type = "SimpleAggregateFunction(sum, UInt64)"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.logs_volume_buckets"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "logs_volume_buckets_distributed" {
+ column "team_id" {
+ type = "Int32"
+ }
+ column "time_bucket" {
+ type = "DateTime('UTC')"
+ codec = "DoubleDelta, ZSTD(1)"
+ }
+ column "service_name" {
+ type = "LowCardinality(String)"
+ }
+ column "namespace" {
+ type = "LowCardinality(String)"
+ }
+ column "environment" {
+ type = "LowCardinality(String)"
+ }
+ column "severity_text" {
+ type = "LowCardinality(String)"
+ }
+ column "log_count" {
+ type = "SimpleAggregateFunction(sum, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "posthog_single_shard"
+ remote_database = "posthog"
+ remote_table = "logs_volume_buckets"
+ }
+ }
+
table "marketing_conversions_preaggregated" {
column "team_id" {
type = "Int64"
@@ -10001,49 +10067,49 @@ SQL
default = "timestamp"
}
column "$group_0" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"
- comment = "column_materializer::$group_0"
+ type = "String"
+ default = "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"
+ type = "String"
+ default = "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"
+ type = "String"
+ default = "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"
+ type = "String"
+ default = "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"
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^\"|\"$', '')"
+ comment = "column_materializer::$group_4"
}
column "flag_key" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag'), '^\"|\"$', '')"
- comment = "column_materializer::properties::$feature_flag"
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag"
}
column "response" {
- type = "LowCardinality(String)"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^\"|\"$', '')"
- comment = "column_materializer::properties::$feature_flag_response"
+ type = "LowCardinality(String)"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag_response"
}
column "session_id" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
- comment = "column_materializer::properties::$session_id"
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$session_id"
}
column "request_id" {
- type = "String"
- materialized = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_request_id'), '^\"|\"$', '')"
- comment = "column_materializer::properties::$feature_flag_request_id"
+ type = "String"
+ default = "replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_request_id'), '^\"|\"$', '')"
+ comment = "column_materializer::properties::$feature_flag_request_id"
}
column "_timestamp" {
type = "DateTime"
diff --git a/posthog/clickhouse/hcl/manifest.hcl b/posthog/clickhouse/hcl/manifest.hcl
index 18577e73d81a..b27492064b96 100644
--- a/posthog/clickhouse/hcl/manifest.hcl
+++ b/posthog/clickhouse/hcl/manifest.hcl
@@ -26,7 +26,7 @@
role "ops" {
env "local-multi" { layers = ["roles/shared", "roles/coshared/custom_metrics", "roles/ops/shared", "roles/ops/local"] }
- env "dev" { layers = ["roles/shared", "roles/coshared/custom_metrics", "roles/ops/shared", "roles/ops/dev"] }
+ env "dev" { layers = ["roles/shared", "roles/coshared/custom_metrics", "roles/coshared/tophog", "roles/ops/shared", "roles/ops/dev"] }
env "prod-us" { layers = ["roles/shared", "roles/coshared/custom_metrics", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/ops/shared", "roles/ops/prod", "roles/ops/prod-us"] }
env "prod-eu" { layers = ["roles/shared", "roles/coshared/custom_metrics", "roles/coshared/tophog", "roles/ops/shared", "roles/ops/prod", "roles/ops/prod-eu"] }
}
@@ -36,7 +36,7 @@ role "ops" {
# than the shared cloud layers.
role "logs" {
env "local-multi" { layers = ["roles/shared/qla.hcl", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/local"] }
- env "dev" { layers = ["roles/shared", "roles/coshared/custom_metrics", "roles/logs/base", "roles/logs/shared"] }
+ env "dev" { layers = ["roles/shared", "roles/coshared/custom_metrics", "roles/logs/base", "roles/logs/shared", "roles/logs/prod/tables.hcl", "roles/logs/dev"] }
env "prod-us" { layers = ["roles/shared", "roles/coshared/custom_metrics", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/shared", "roles/logs/prod", "roles/logs/prod-us"] }
env "prod-eu" { layers = ["roles/shared", "roles/coshared/custom_metrics", "roles/logs/base", "roles/logs/traces", "roles/logs/shared", "roles/logs/prod", "roles/logs/prod-eu"] }
}
@@ -46,11 +46,12 @@ role "logs" {
# + distributed ai_events reader; US/EU run the WarpStream variant
# (kafka_ai_events_json_ws + ai_events_json_ws_mv, MSK dropped by migration 0248)
# writing into a single ai_events data table. roles/ai_events/shared holds the
-# env-uniform person / person_distinct_id2 Distributed shims (0240). dev currently
-# has only the top-level shared objects (per the latest dump).
+# env-uniform person / person_distinct_id2 Distributed shims (0240). dev runs the
+# same WarpStream pipeline as the prod envs; roles/ai_events/dev downsizes the
+# Kafka consumer for dev volume.
role "ai_events" {
env "local-multi" { layers = ["roles/shared", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/local"] }
- env "dev" { layers = ["roles/shared"] }
+ env "dev" { layers = ["roles/shared", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/prod", "roles/ai_events/dev"] }
env "prod-us" { layers = ["roles/shared", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/prod"] }
env "prod-eu" { layers = ["roles/shared", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/prod"] }
}
@@ -62,6 +63,7 @@ role "ai_events" {
# ingestion_warnings tables. prod goldens are dump-baselined (not live-verifiable here).
role "aux" {
env "local-multi" { layers = ["roles/shared", "roles/coshared/aux_data", "roles/auxiliary/shared", "roles/auxiliary/local"] }
+ env "dev" { layers = ["roles/shared", "roles/coshared/aux_data", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/dev"] }
env "prod-us" { layers = ["roles/shared", "roles/coshared/aux_data", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/prod-us"] }
env "prod-eu" { layers = ["roles/shared", "roles/coshared/aux_data", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/prod-eu"] }
}
@@ -73,6 +75,9 @@ role "aux" {
# join tables. roles/sessions/shared holds the env-uniform objects; prod-us/prod-eu
# carry the env-specific channel_definition / events / raw_sessions_v3 (prod-us also
# has writable_events_recent). prod goldens are dump-baselined (not live-verifiable here).
+# dev carries the channel_definition / web_pre_aggregated_teams objects + dictionaries,
+# but raw_sessions_v3 intentionally skips prod's tuning settings and the sessions-family
+# relocation is still converging — model a dev env block after it settles.
role "sessions" {
env "local-multi" { layers = ["roles/shared"] }
env "prod-us" { layers = ["roles/shared", "roles/coshared/sessions_data", "roles/coshared/events_recent_write", "roles/sessions/shared", "roles/sessions/prod-us"] }
@@ -90,6 +95,8 @@ role "sessionsv3" {
# query_log_archive path. Env-specific — prod-eu carries an extra historical_migration
# column. Dump-baselined (no local batch-exports node).
role "batch_exports" {
+ # dev composes the prod-us stack verbatim (verified zero drift via hclexp diff).
+ env "dev" { layers = ["roles/shared", "roles/coshared/batch_exports_data", "roles/batch_exports/prod-us"] }
env "prod-us" { layers = ["roles/shared", "roles/coshared/batch_exports_data", "roles/batch_exports/prod-us"] }
env "prod-eu" { layers = ["roles/shared", "roles/coshared/batch_exports_data", "roles/batch_exports/prod-eu"] }
}
diff --git a/posthog/clickhouse/hcl/roles/ai_events/dev/patches.hcl b/posthog/clickhouse/hcl/roles/ai_events/dev/patches.hcl
new file mode 100644
index 000000000000..b02fa94ecb73
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/ai_events/dev/patches.hcl
@@ -0,0 +1,17 @@
+# dev deltas to the prod ai_events stack: identical pipeline, Kafka consumer
+# downsized for dev volume (prod runs 16).
+database "posthog" {
+ patch_table "kafka_ai_events_json_ws" {
+ engine "kafka" {
+ broker_list = "warpstream_ingestion"
+ topic_list = "kafka_topic_list = 'clickhouse_ai_events_json'"
+ group_name = "kafka_group_name = 'clickhouse_ai_events_ws'"
+ format = "kafka_format = 'JSONEachRow'"
+ num_consumers = 1
+ max_block_size = 5000
+ skip_broken_messages = 100
+ poll_timeout_ms = 10000
+ thread_per_consumer = true
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/auxiliary/dev/patches.hcl b/posthog/clickhouse/hcl/roles/auxiliary/dev/patches.hcl
new file mode 100644
index 000000000000..7872dc5fd804
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/auxiliary/dev/patches.hcl
@@ -0,0 +1,14 @@
+# dev deltas to shared aux objects: identical pipeline, property_values Kafka
+# consumer downsized for dev volume (the canonical definition runs 8).
+database "posthog" {
+ patch_table "kafka_property_values" {
+ engine "kafka" {
+ broker_list = "warpstream_ingestion"
+ topic_list = "kafka_topic_list = 'clickhouse_property_values'"
+ group_name = "kafka_group_name = 'clickhouse_property_values'"
+ format = "kafka_format = 'JSONEachRow'"
+ num_consumers = 1
+ thread_per_consumer = true
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl b/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl
new file mode 100644
index 000000000000..20cf3f9442fe
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl
@@ -0,0 +1,12 @@
+# dev deltas to base logs objects. logs34 carries the prod storage/settings shape;
+# the metrics/metrics1 codec and trace-family ZK-path deltas in roles/logs/prod are
+# deliberately not composed here (intentional dev divergence).
+database "posthog" {
+ patch_table "logs34" {
+ settings = {
+ storage_policy = "s3_tiered"
+ map_buckets_strategy = "constant"
+ max_buckets_in_map = "32"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/logs/traces/tables.hcl b/posthog/clickhouse/hcl/roles/logs/traces/tables.hcl
index 36d71a3df868..02bb867cfbe8 100644
--- a/posthog/clickhouse/hcl/roles/logs/traces/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/logs/traces/tables.hcl
@@ -1,6 +1,7 @@
-# The trace-spans suite, hosted by the local logs node and both prod logs envs
-# (dev has no traces). Env deltas are patch_table / patch_materialized_view
-# blocks in the env layers, never second definitions.
+# The trace-spans suite, hosted by the local logs node and both prod logs envs.
+# The dev trace suite predates this shape and is not composed here. Env deltas are
+# patch_table / patch_materialized_view blocks in the env layers, never second
+# definitions.
database "posthog" {
table "trace_attributes" {
order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value"]
diff --git a/posthog/clickhouse/hcl/sql/dev/ai_events.sql b/posthog/clickhouse/hcl/sql/dev/ai_events.sql
index d1d0138ac723..6ed24d0cfc67 100644
--- a/posthog/clickhouse/hcl/sql/dev/ai_events.sql
+++ b/posthog/clickhouse/hcl/sql/dev/ai_events.sql
@@ -1,6 +1,109 @@
-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit.
-- Full CREATE schema for the dev/ai_events node. Apply to a fresh ClickHouse to build it.
+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,
+ INDEX idx_trace_id trace_id TYPE bloom_filter(0.001) GRANULARITY 1,
+ INDEX idx_session_id session_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX idx_parent_id parent_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX idx_span_id span_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX idx_prompt_name prompt_name TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX idx_model model TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX idx_experiment_id experiment_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX idx_event event TYPE set(20) GRANULARITY 1,
+ INDEX idx_is_error is_error TYPE set(2) GRANULARITY 1,
+ INDEX idx_provider provider TYPE set(50) GRANULARITY 1
+) ENGINE = ReplicatedMergeTree('/clickhouse/ai_events/tables/{shard}/posthog.ai_events', '{replica}') ORDER BY (team_id, trace_id, timestamp) PARTITION BY toYYYYMM(drop_date) TTL drop_date SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.kafka_ai_events_json_ws (
+ 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,
+ person_created_at DateTime64(3),
+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)
+) ENGINE = Kafka() SETTINGS kafka_broker_list = 'warpstream_ingestion', kafka_format = 'kafka_format = \'JSONEachRow\'', kafka_group_name = 'kafka_group_name = \'clickhouse_ai_events_ws\'', kafka_max_block_size = 5000, kafka_num_consumers = 1, kafka_poll_timeout_ms = 10000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'kafka_topic_list = \'clickhouse_ai_events_json\'';
+CREATE TABLE posthog.person (
+ id UUID,
+ created_at DateTime64(3),
+ team_id Int64,
+ properties String,
+ is_identified Int8,
+ is_deleted Int8,
+ version UInt64,
+ last_seen_at Nullable(DateTime64(3))
+) ENGINE = Distributed('posthog', 'posthog', 'person');
+CREATE TABLE posthog.person_distinct_id2 (
+ team_id Int64,
+ distinct_id String,
+ person_id UUID,
+ is_deleted Int8,
+ version Int64
+) ENGINE = Distributed('posthog', 'posthog', 'person_distinct_id2');
CREATE TABLE posthog.query_log_archive (
hostname LowCardinality(String),
user LowCardinality(String),
@@ -129,6 +232,79 @@ CREATE TABLE posthog.writable_query_log_archive (
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 MATERIALIZED VIEW posthog.ai_events_json_ws_mv TO posthog.ai_events (uuid UUID, event String, timestamp DateTime64(6, 'UTC'), team_id Int64, distinct_id String, person_id UUID, properties String, trace_id String, session_id Nullable(String), parent_id Nullable(String), span_id Nullable(String), span_type Nullable(String), generation_id Nullable(String), experiment_id Nullable(String), span_name Nullable(String), trace_name Nullable(String), prompt_name Nullable(String), model Nullable(String), provider Nullable(String), framework 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 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 Nullable(DateTime), _offset UInt64, _partition UInt64) AS SELECT
+ uuid,
+ event,
+ timestamp,
+ team_id,
+ distinct_id,
+ person_id,
+ concat(
+ '{',
+ arrayStringConcat(
+ arrayMap(
+ x -> concat('"', x.1, '":', x.2),
+ arrayFilter(
+ x -> ((x.1) NOT IN ('$ai_input', '$ai_output', '$ai_output_choices', '$ai_input_state', '$ai_output_state', '$ai_tools')),
+ JSONExtractKeysAndValuesRaw(src.properties)
+ )
+ ),
+ ','
+ ),
+ '}'
+ ) AS properties,
+ JSONExtractString(src.properties, '$ai_trace_id') AS trace_id,
+ JSONExtract(src.properties, '$ai_session_id', 'Nullable(String)') AS session_id,
+ JSONExtract(src.properties, '$ai_parent_id', 'Nullable(String)') AS parent_id,
+ JSONExtract(src.properties, '$ai_span_id', 'Nullable(String)') AS span_id,
+ JSONExtract(src.properties, '$ai_span_type', 'Nullable(String)') AS span_type,
+ JSONExtract(src.properties, '$ai_generation_id', 'Nullable(String)') AS generation_id,
+ JSONExtract(src.properties, '$ai_experiment_id', 'Nullable(String)') AS experiment_id,
+ JSONExtract(src.properties, '$ai_span_name', 'Nullable(String)') AS span_name,
+ JSONExtract(src.properties, '$ai_trace_name', 'Nullable(String)') AS trace_name,
+ JSONExtract(src.properties, '$ai_prompt_name', 'Nullable(String)') AS prompt_name,
+ JSONExtract(src.properties, '$ai_model', 'Nullable(String)') AS model,
+ JSONExtract(src.properties, '$ai_provider', 'Nullable(String)') AS provider,
+ JSONExtract(src.properties, '$ai_framework', 'Nullable(String)') AS framework,
+ JSONExtract(src.properties, '$ai_total_tokens', 'Nullable(Int64)') AS total_tokens,
+ JSONExtract(src.properties, '$ai_input_tokens', 'Nullable(Int64)') AS input_tokens,
+ JSONExtract(src.properties, '$ai_output_tokens', 'Nullable(Int64)') AS output_tokens,
+ JSONExtract(src.properties, '$ai_text_input_tokens', 'Nullable(Int64)') AS text_input_tokens,
+ JSONExtract(src.properties, '$ai_text_output_tokens', 'Nullable(Int64)') AS text_output_tokens,
+ JSONExtract(src.properties, '$ai_image_input_tokens', 'Nullable(Int64)') AS image_input_tokens,
+ JSONExtract(src.properties, '$ai_image_output_tokens', 'Nullable(Int64)') AS image_output_tokens,
+ JSONExtract(src.properties, '$ai_audio_input_tokens', 'Nullable(Int64)') AS audio_input_tokens,
+ JSONExtract(src.properties, '$ai_audio_output_tokens', 'Nullable(Int64)') AS audio_output_tokens,
+ JSONExtract(src.properties, '$ai_video_input_tokens', 'Nullable(Int64)') AS video_input_tokens,
+ JSONExtract(src.properties, '$ai_video_output_tokens', 'Nullable(Int64)') AS video_output_tokens,
+ JSONExtract(src.properties, '$ai_reasoning_tokens', 'Nullable(Int64)') AS reasoning_tokens,
+ JSONExtract(src.properties, '$ai_cache_read_input_tokens', 'Nullable(Int64)') AS cache_read_input_tokens,
+ JSONExtract(src.properties, '$ai_cache_creation_input_tokens', 'Nullable(Int64)') AS cache_creation_input_tokens,
+ JSONExtract(src.properties, '$ai_web_search_count', 'Nullable(Int64)') AS web_search_count,
+ JSONExtract(src.properties, '$ai_input_cost_usd', 'Nullable(Float64)') AS input_cost_usd,
+ JSONExtract(src.properties, '$ai_output_cost_usd', 'Nullable(Float64)') AS output_cost_usd,
+ JSONExtract(src.properties, '$ai_total_cost_usd', 'Nullable(Float64)') AS total_cost_usd,
+ JSONExtract(src.properties, '$ai_request_cost_usd', 'Nullable(Float64)') AS request_cost_usd,
+ JSONExtract(src.properties, '$ai_web_search_cost_usd', 'Nullable(Float64)') AS web_search_cost_usd,
+ JSONExtract(src.properties, '$ai_audio_cost_usd', 'Nullable(Float64)') AS audio_cost_usd,
+ JSONExtract(src.properties, '$ai_image_cost_usd', 'Nullable(Float64)') AS image_cost_usd,
+ JSONExtract(src.properties, '$ai_video_cost_usd', 'Nullable(Float64)') AS video_cost_usd,
+ JSONExtract(src.properties, '$ai_latency', 'Nullable(Float64)') AS latency,
+ JSONExtract(src.properties, '$ai_time_to_first_token', 'Nullable(Float64)') AS time_to_first_token,
+ if((JSONExtractRaw(src.properties, '$ai_is_error') IN ('true', '"true"')), 1, 0) AS is_error,
+ JSONExtract(src.properties, '$ai_error', 'Nullable(String)') AS error,
+ JSONExtract(src.properties, '$ai_error_type', 'Nullable(String)') AS error_type,
+ JSONExtract(src.properties, '$ai_error_normalized', 'Nullable(String)') AS error_normalized,
+ nullIf(JSONExtractRaw(src.properties, '$ai_input'), '') AS input,
+ nullIf(JSONExtractRaw(src.properties, '$ai_output'), '') AS output,
+ nullIf(JSONExtractRaw(src.properties, '$ai_output_choices'), '') AS output_choices,
+ nullIf(JSONExtractRaw(src.properties, '$ai_input_state'), '') AS input_state,
+ nullIf(JSONExtractRaw(src.properties, '$ai_output_state'), '') AS output_state,
+ nullIf(JSONExtractRaw(src.properties, '$ai_tools'), '') AS tools,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.kafka_ai_events_json_ws AS src;
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,
diff --git a/posthog/clickhouse/hcl/sql/dev/auxiliary.sql b/posthog/clickhouse/hcl/sql/dev/auxiliary.sql
new file mode 100644
index 000000000000..418b4a1c104b
--- /dev/null
+++ b/posthog/clickhouse/hcl/sql/dev/auxiliary.sql
@@ -0,0 +1,1212 @@
+-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit.
+-- Full CREATE schema for the dev/aux node. Apply to a fresh ClickHouse to build it.
+
+CREATE TABLE posthog.hog_invocation_results_data (
+ 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') DEFAULT scheduled_at,
+ 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 DEFAULT 0,
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX status_idx status TYPE set(8) GRANULARITY 1,
+ INDEX function_idx function_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX event_uuid_idx event_uuid TYPE bloom_filter(0.01) GRANULARITY 1,
+ INDEX is_retry_idx is_retry TYPE set(2) GRANULARITY 1
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.hog_invocation_results_data', '{replica}-{shard}', version) ORDER BY (team_id, function_kind, function_id, invocation_id) PARTITION BY toYYYYMMDD(scheduled_at) TTL toDate(scheduled_at) + toIntervalDay(30) SETTINGS index_granularity = 1024, storage_policy = 's3_tiered', ttl_only_drop_parts = 1;
+CREATE TABLE posthog.ingestion_warnings_v2 (
+ 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 = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.ingestion_warnings_v2', '{replica}-{shard}') ORDER BY (team_id, type, timestamp) PARTITION BY toYYYYMM(timestamp) TTL toDateTime(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 8192;
+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_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
+) ENGINE = Kafka() SETTINGS kafka_broker_list = 'warpstream_cyclotron', kafka_format = 'kafka_format = \'JSONEachRow\'', kafka_group_name = 'kafka_group_name = \'clickhouse_hog_invocation_results\'', kafka_skip_broken_messages = 100, kafka_topic_list = 'kafka_topic_list = \'clickhouse_hog_invocation_results\'';
+CREATE TABLE posthog.kafka_ingestion_warnings_v2 (
+ team_id Int64,
+ source LowCardinality(String),
+ type String,
+ details String,
+ timestamp DateTime64(6, 'UTC')
+) ENGINE = Kafka() SETTINGS kafka_broker_list = 'warpstream_ingestion', kafka_format = 'kafka_format = \'JSONEachRow\'', kafka_group_name = 'kafka_group_name = \'clickhouse_ingestion_warnings_v2\'', kafka_topic_list = 'kafka_topic_list = \'clickhouse_ingestion_warnings\'';
+CREATE TABLE posthog.kafka_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
+) ENGINE = Kafka() SETTINGS kafka_broker_list = 'warpstream_cyclotron', kafka_format = 'kafka_format = \'JSONEachRow\'', kafka_group_name = 'kafka_group_name = \'clickhouse_message_assets\'', kafka_skip_broken_messages = 100, kafka_topic_list = 'kafka_topic_list = \'clickhouse_message_assets\'';
+CREATE TABLE posthog.kafka_property_values (
+ team_id Int64,
+ property_type LowCardinality(String),
+ property_key String,
+ property_value String,
+ property_count UInt64
+) ENGINE = Kafka() SETTINGS kafka_broker_list = 'warpstream_ingestion', kafka_format = 'kafka_format = \'JSONEachRow\'', kafka_group_name = 'kafka_group_name = \'clickhouse_property_values\'', kafka_num_consumers = 1, kafka_thread_per_consumer = 1, kafka_topic_list = 'kafka_topic_list = \'clickhouse_property_values\'';
+CREATE TABLE posthog.message_assets_data (
+ 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 DEFAULT 0,
+ html String CODEC(ZSTD(3)),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64,
+ INDEX parent_run_idx parent_run_id TYPE bloom_filter(0.01) GRANULARITY 1,
+ 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 recipient_idx recipient TYPE bloom_filter(0.01) GRANULARITY 1
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.message_assets_data', '{replica}-{shard}', version) ORDER BY (team_id, function_kind, function_id, invocation_id, action_id) PARTITION BY toYYYYMMDD(sent_at) TTL toDate(sent_at) + toIntervalDay(30) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.property_values (
+ 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(),
+ INDEX idx_property_value_ngrambf lower(property_value) TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.property_values', '{replica}-{shard}') ORDER BY (team_id, property_type, property_key, property_value) TTL last_seen + toIntervalDay(30) 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_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,
+ INDEX kafka_timestamp_minmax_raw_error_tracking_fingerprint_issue_state _timestamp TYPE minmax GRANULARITY 3
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.raw_error_tracking_fingerprint_issue_state', '{replica}-{shard}', version) ORDER BY (team_id, fingerprint) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.conversion_goal_attributed_preaggregated', '{replica}-{shard}', computed_at) ORDER BY (team_id, job_id, person_id, conversion_timestamp, touchpoint_timestamp) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.experiment_metric_events_preaggregated', '{replica}-{shard}', computed_at) ORDER BY (team_id, job_id, entity_id, timestamp, event_uuid) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_ingestion_warnings (
+ team_id Int64,
+ source LowCardinality(String),
+ type String,
+ details String,
+ timestamp DateTime64(6, 'UTC'),
+ _timestamp DateTime,
+ _offset UInt64,
+ _partition UInt64
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/reshard/{shard}/posthog.sharded_ingestion_warnings', '{replica}') ORDER BY (team_id, toHour(timestamp), type, source, timestamp) PARTITION BY toYear(timestamp) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.marketing_conversions_preaggregated', '{replica}-{shard}', computed_at) ORDER BY (team_id, job_id, person_id, conversion_timestamp) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.marketing_costs_preaggregated', '{replica}-{shard}', computed_at) ORDER BY (team_id, job_id, source_name, grain, campaign_id, ad_group_id, ad_id, cost_date) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.marketing_touchpoints_preaggregated', '{replica}-{shard}', computed_at) ORDER BY (team_id, job_id, person_id, touchpoint_timestamp) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.session_replay_features', '{replica}') ORDER BY (team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512;
+CREATE TABLE posthog.sharded_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 = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.sharded_usage_report_events_preagg', '{replica}') ORDER BY (date, team_id, person_mode, lib, event) PARTITION BY date TTL date + toIntervalDay(14) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_web_bot_definition (
+ id UInt64,
+ parent_id UInt64,
+ regexp String,
+ keys Array(String),
+ values Array(String)
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.sharded_web_bot_definition', '{replica}') ORDER BY (id) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_bounces_dimensional_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_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_backend, mat_metadata_loggedIn) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS allow_nullable_key = 1, index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_goals_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, action_id, time_window_start) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_overview_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, time_window_start) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_stats_dimensional_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_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_backend, mat_metadata_loggedIn) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS allow_nullable_key = 1, index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_stats_frustration_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, breakdown_value, time_window_start) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_stats_paths_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, breakdown_value, time_window_start) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_stats_paths_preaggregated_pathkey', '{replica}', computed_at) ORDER BY (team_id, time_window_start, breakdown_value, job_id) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_stats_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, breakdown_by, time_window_start, breakdown_value) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_vitals_paths_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, time_window_start, path) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+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_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_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_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.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 MATERIALIZED VIEW posthog.hog_invocation_results_mv TO posthog.hog_invocation_results_data (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 Nullable(DateTime), _offset UInt64, _partition UInt64) AS SELECT
+ team_id,
+ function_kind,
+ function_id,
+ invocation_id,
+ parent_run_id,
+ status,
+ attempts,
+ is_retry,
+ scheduled_at,
+ if(
+ first_scheduled_at = toDateTime64('1970-01-01 00:00:00', 6, 'UTC'),
+ scheduled_at,
+ first_scheduled_at
+ ) AS first_scheduled_at,
+ started_at,
+ finished_at,
+ duration_ms,
+ error_kind,
+ error_message,
+ event_uuid,
+ distinct_id,
+ person_id,
+ invocation_globals,
+ version,
+ is_deleted,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.kafka_hog_invocation_results;
+CREATE MATERIALIZED VIEW posthog.ingestion_warnings_v2_mv TO posthog.ingestion_warnings_v2 (team_id Int64, source LowCardinality(String), type String, details String, timestamp DateTime64(6, 'UTC'), _timestamp Nullable(DateTime), _offset UInt64, _partition UInt64) AS SELECT
+ team_id,
+ source,
+ type,
+ details,
+ timestamp,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.kafka_ingestion_warnings_v2;
+CREATE MATERIALIZED VIEW posthog.message_assets_mv TO posthog.message_assets_data (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 Nullable(DateTime), _offset UInt64, _partition UInt64) AS SELECT
+ team_id,
+ function_kind,
+ function_id,
+ parent_run_id,
+ invocation_id,
+ action_id,
+ kind,
+ distinct_id,
+ person_id,
+ recipient,
+ subject,
+ status,
+ sent_at,
+ version,
+ is_deleted,
+ html,
+ _timestamp,
+ _offset,
+ _partition
+FROM posthog.kafka_message_assets;
+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.property_values_mv TO posthog.property_values (team_id Int64, property_type LowCardinality(String), property_key String, property_value String, property_count UInt64, last_seen DateTime) AS SELECT
+ team_id,
+ property_type,
+ property_key,
+ property_value,
+ property_count,
+ coalesce(_timestamp, now()) AS last_seen
+FROM posthog.kafka_property_values;
+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 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 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.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.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.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.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.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));
diff --git a/posthog/clickhouse/hcl/sql/dev/batch_exports.sql b/posthog/clickhouse/hcl/sql/dev/batch_exports.sql
new file mode 100644
index 000000000000..46009f1734cb
--- /dev/null
+++ b/posthog/clickhouse/hcl/sql/dev/batch_exports.sql
@@ -0,0 +1,294 @@
+-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit.
+-- Full CREATE schema for the dev/batch_exports node. Apply to a fresh ClickHouse to build it.
+
+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.sharded_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 = ReplicatedReplacingMergeTree('/clickhouse/tables/batch_exports/{shard}/posthog.sharded_events_recent', '{replica}', _timestamp) ORDER BY (team_id, toStartOfHour(inserted_at), event, cityHash64(distinct_id), cityHash64(uuid)) PARTITION BY toStartOfDay(inserted_at) TTL toDateTime(inserted_at) + toIntervalDay(7) SETTINGS index_granularity = 8192, parts_to_delay_insert = 800, parts_to_throw_insert = 1500, ttl_only_drop_parts = 1;
+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 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 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;
diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sql
index 44f25b5dec7a..cab992f20afd 100644
--- a/posthog/clickhouse/hcl/sql/dev/logs.sql
+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql
@@ -122,7 +122,7 @@ CREATE TABLE posthog.logs34 (
INDEX idx_uuid_bloom uuid TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_observed_minmax observed_timestamp TYPE minmax GRANULARITY 1,
INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1
-) ENGINE = ReplicatedMergeTree('/clickhouse/tables/logs/{shard}/posthog.logs34', '{replica}') ORDER BY (team_id, time_bucket, service_name, resource_fingerprint, severity_text, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS add_minmax_index_for_numeric_columns = 1, allow_experimental_reverse_key = 1, index_granularity = 8192, index_granularity_bytes = 104857600, map_serialization_version = 'with_buckets', ttl_only_drop_parts = 1;
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/logs/{shard}/posthog.logs34', '{replica}') ORDER BY (team_id, time_bucket, service_name, resource_fingerprint, severity_text, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS add_minmax_index_for_numeric_columns = 1, allow_experimental_reverse_key = 1, index_granularity = 8192, index_granularity_bytes = 104857600, map_buckets_strategy = 'constant', map_serialization_version = 'with_buckets', max_buckets_in_map = 32, storage_policy = 's3_tiered', ttl_only_drop_parts = 1;
CREATE TABLE posthog.logs_billing_metrics (
team_id Int32,
time_bucket DateTime64(0),
@@ -522,6 +522,40 @@ CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_mv TO posthog.metrics1 (uuid
) AS attributes_map_float,
toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id
FROM posthog.kafka_metrics_avro
+SETTINGS
+ min_insert_block_size_rows = 0,
+ min_insert_block_size_bytes = 0;
+CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_to_metric_samples TO posthog.metric_samples1 (team_id Int32, metric_name String, series_fingerprint UInt64, timestamp DateTime64(6), value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32) AS SELECT
+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,
+ ifNull(metric_name, '') AS metric_name,
+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,
+ timestamp,
+ ifNull(value, 0) AS value,
+ toUInt64(ifNull(count, 1)) AS count,
+ histogram_bounds,
+ arrayMap(x -> toUInt64(x), histogram_counts) AS histogram_counts,
+ trace_id,
+ span_id,
+ ifNull(trace_flags, 0) AS trace_flags
+FROM posthog.kafka_metrics_avro
+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL
+SETTINGS
+ min_insert_block_size_rows = 0,
+ min_insert_block_size_bytes = 0;
+CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_to_metric_series TO posthog.metric_series1 (team_id Int32, metric_name String, series_fingerprint UInt64, metric_type String, unit String, aggregation_temporality String, is_monotonic UInt8, service_name String, resource_attributes Map(String, String), attributes Map(String, String), last_seen DateTime64(6)) AS SELECT
+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,
+ ifNull(metric_name, '') AS metric_name,
+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,
+ ifNull(metric_type, '') AS metric_type,
+ ifNull(unit, '') AS unit,
+ ifNull(aggregation_temporality, '') AS aggregation_temporality,
+ ifNull(is_monotonic, 0) AS is_monotonic,
+ ifNull(service_name, '') AS service_name,
+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)) AS attributes,
+ timestamp AS last_seen
+FROM posthog.kafka_metrics_avro
+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL
SETTINGS
min_insert_block_size_rows = 0,
min_insert_block_size_bytes = 0;
diff --git a/posthog/clickhouse/hcl/sql/dev/ops.sql b/posthog/clickhouse/hcl/sql/dev/ops.sql
index 13b2f8be1fa9..753cfb4a1bd6 100644
--- a/posthog/clickhouse/hcl/sql/dev/ops.sql
+++ b/posthog/clickhouse/hcl/sql/dev/ops.sql
@@ -131,6 +131,17 @@ CREATE TABLE posthog.sharded_query_log_archive (
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 = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.sharded_query_log_archive', '{replica}-{shard}') ORDER BY (team_id, event_date, event_time, query_id) PARTITION BY toYYYYMM(event_date) SETTINGS index_granularity = 8192, object_serialization_version = 'v3', object_shared_data_serialization_version = 'map_with_buckets';
+CREATE TABLE posthog.sharded_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 = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.tophog', '{replica}') ORDER BY (pipeline, lane, metric, timestamp, key) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(timestamp) + toIntervalDay(30) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
CREATE TABLE posthog.writable_prom_metrics_data (
id UUID,
timestamp DateTime64(3),
diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sql
index 2c4a6d4b7452..41880a6a0649 100644
--- a/posthog/clickhouse/hcl/sql/local-single/all.sql
+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql
@@ -1081,6 +1081,24 @@ CREATE TABLE posthog.logs_kafka_metrics_distributed (
max_created_at SimpleAggregateFunction(max, DateTime64(9)),
max_lag SimpleAggregateFunction(max, UInt64)
) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs_kafka_metrics');
+CREATE TABLE posthog.logs_volume_buckets (
+ team_id Int32,
+ time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),
+ service_name LowCardinality(String),
+ namespace LowCardinality(String),
+ environment LowCardinality(String),
+ severity_text LowCardinality(String),
+ log_count SimpleAggregateFunction(sum, UInt64)
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(42) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.logs_volume_buckets_distributed (
+ team_id Int32,
+ time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),
+ service_name LowCardinality(String),
+ namespace LowCardinality(String),
+ environment LowCardinality(String),
+ severity_text LowCardinality(String),
+ log_count SimpleAggregateFunction(sum, UInt64)
+) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs_volume_buckets');
CREATE TABLE posthog.message_assets_data (
team_id Int64,
function_kind LowCardinality(String),
@@ -1801,15 +1819,15 @@ CREATE TABLE posthog.sharded_flag_evaluations (
group3_properties String,
group4_properties String,
inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,
- $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',
- flag_key String MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag',
- response LowCardinality(String) MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag_response',
- session_id String MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^"|"$', '') COMMENT 'column_materializer::properties::$session_id',
- request_id String MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_request_id'), '^"|"$', '') COMMENT 'column_materializer::properties::$feature_flag_request_id',
+ $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,
diff --git a/posthog/clickhouse/migrations/0249_property_values_kafka_named_collection.py b/posthog/clickhouse/migrations/0249_property_values_kafka_named_collection.py
index 2a0a6b3d53b9..76af4718161f 100644
--- a/posthog/clickhouse/migrations/0249_property_values_kafka_named_collection.py
+++ b/posthog/clickhouse/migrations/0249_property_values_kafka_named_collection.py
@@ -9,27 +9,19 @@ from posthog.clickhouse.property_values import (
PROPERTY_VALUES_TABLE_SQL,
)
-# Two fixes to 0244:
-# - US/EU: kafka_property_values used the default msk_cluster named collection,
-# but the topic is produced to warpstream_ingestion. Drop the MV first, then
-# the Kafka table, then recreate both with the right named collection.
-# Storage table is untouched.
-# - DEV: 0244's AUX ops no-op'd because dev has no hostClusterRole=aux nodes.
-# Create storage, Kafka, and MV on DATA. Dev's `aux` cluster aliases to those
-# same hosts so the existing Distributed proxy resolves correctly.
+# Fix to 0244: kafka_property_values used the default msk_cluster named
+# collection, but the topic is produced to warpstream_ingestion. Drop the MV
+# first, then the Kafka table, then recreate both with the right named
+# collection. Storage table is untouched. The property_values pipeline lives
+# on AUX in every cloud env.
-if settings.CLOUD_DEPLOYMENT in ("US", "EU"):
+if settings.CLOUD_DEPLOYMENT in ("US", "EU", "DEV"):
operations = [
+ run_sql_with_exceptions(PROPERTY_VALUES_TABLE_SQL(), node_roles=[NodeRole.AUX]),
run_sql_with_exceptions(DROP_PROPERTY_VALUES_MV_SQL(), node_roles=[NodeRole.AUX]),
run_sql_with_exceptions(DROP_KAFKA_PROPERTY_VALUES_TABLE_SQL(), node_roles=[NodeRole.AUX]),
run_sql_with_exceptions(KAFKA_PROPERTY_VALUES_TABLE_SQL_FN(), node_roles=[NodeRole.AUX]),
run_sql_with_exceptions(PROPERTY_VALUES_MV_SQL(), node_roles=[NodeRole.AUX]),
]
-elif settings.CLOUD_DEPLOYMENT == "DEV":
- operations = [
- run_sql_with_exceptions(PROPERTY_VALUES_TABLE_SQL(), node_roles=[NodeRole.DATA]),
- run_sql_with_exceptions(KAFKA_PROPERTY_VALUES_TABLE_SQL_FN(), node_roles=[NodeRole.DATA]),
- run_sql_with_exceptions(PROPERTY_VALUES_MV_SQL(), node_roles=[NodeRole.DATA]),
- ]
else:
operations = []
diff --git a/posthog/clickhouse/migrations/0250_property_values_lowercase_text_index.py b/posthog/clickhouse/migrations/0250_property_values_lowercase_text_index.py
index b4589524f9e3..b46e9c5d24ef 100644
--- a/posthog/clickhouse/migrations/0250_property_values_lowercase_text_index.py
+++ b/posthog/clickhouse/migrations/0250_property_values_lowercase_text_index.py
@@ -2,10 +2,8 @@ from posthog import settings
from posthog.clickhouse.client.connection import NodeRole
from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
-if settings.CLOUD_DEPLOYMENT in ("US", "EU"):
+if settings.CLOUD_DEPLOYMENT in ("US", "EU", "DEV"):
_ROLES = [NodeRole.AUX]
-elif settings.CLOUD_DEPLOYMENT == "DEV":
- _ROLES = [NodeRole.DATA]
else:
_ROLES = []
diff --git a/posthog/clickhouse/migrations/0257_property_values_count_column.py b/posthog/clickhouse/migrations/0257_property_values_count_column.py
index e729f537316c..88b63d019f7d 100644
--- a/posthog/clickhouse/migrations/0257_property_values_count_column.py
+++ b/posthog/clickhouse/migrations/0257_property_values_count_column.py
@@ -11,10 +11,8 @@ from posthog.clickhouse.property_values import (
# Kafka engine tables don't support ALTER ADD COLUMN, so we drop and recreate
# the MV + Kafka engine table together.
-if settings.CLOUD_DEPLOYMENT in ("US", "EU"):
+if settings.CLOUD_DEPLOYMENT in ("US", "EU", "DEV"):
_ROLES = [NodeRole.AUX]
-elif settings.CLOUD_DEPLOYMENT == "DEV":
- _ROLES = [NodeRole.DATA]
else:
_ROLES = []
diff --git a/posthog/clickhouse/migrations/0262_property_values_swap_text_index_for_ngrambf.py b/posthog/clickhouse/migrations/0262_property_values_swap_text_index_for_ngrambf.py
index 9ea5d93e18bd..117b552bc858 100644
--- a/posthog/clickhouse/migrations/0262_property_values_swap_text_index_for_ngrambf.py
+++ b/posthog/clickhouse/migrations/0262_property_values_swap_text_index_for_ngrambf.py
@@ -1,12 +1,8 @@
-from posthog import settings
from posthog.clickhouse.client.connection import NodeRole
from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
from posthog.clickhouse.property_values import TABLE_NAME
-if settings.CLOUD_DEPLOYMENT == "DEV":
- _ROLES = [NodeRole.DATA]
-else:
- _ROLES = [NodeRole.AUX]
+_ROLES = [NodeRole.AUX]
operations = [
run_sql_with_exceptions(
diff --git a/posthog/clickhouse/migrations/0268_property_values_kafka_num_consumers.py b/posthog/clickhouse/migrations/0268_property_values_kafka_num_consumers.py
index d2c44c710322..bc52c95c6b41 100644
--- a/posthog/clickhouse/migrations/0268_property_values_kafka_num_consumers.py
+++ b/posthog/clickhouse/migrations/0268_property_values_kafka_num_consumers.py
@@ -8,10 +8,8 @@ from posthog.clickhouse.property_values import (
PROPERTY_VALUES_MV_SQL,
)
-if settings.CLOUD_DEPLOYMENT in ("US", "EU"):
+if settings.CLOUD_DEPLOYMENT in ("US", "EU", "DEV"):
_ROLES = [NodeRole.AUX]
-elif settings.CLOUD_DEPLOYMENT == "DEV":
- _ROLES = [NodeRole.DATA]
else:
_ROLES = []
diff --git a/posthog/clickhouse/migrations/0270_property_values_drop_mv_length_filter.py b/posthog/clickhouse/migrations/0270_property_values_drop_mv_length_filter.py
index d0e2acfbb0a5..d5f0ab4e32de 100644
--- a/posthog/clickhouse/migrations/0270_property_values_drop_mv_length_filter.py
+++ b/posthog/clickhouse/migrations/0270_property_values_drop_mv_length_filter.py
@@ -5,12 +5,9 @@ from posthog.clickhouse.property_values import DROP_PROPERTY_VALUES_MV_SQL, PROP
# Length and empty-value filtering now lives in the property-vals service, so the
# MV passes everything from the Kafka table straight through. property_values lives
-# on AUX in prod but on DATA in dev (dev's aux nodes don't host it), matching
-# 0262/0268. Single-node local/hobby get overridden to ALL by the migration runner.
-if settings.CLOUD_DEPLOYMENT == "DEV":
- _ROLES = [NodeRole.DATA]
-else:
- _ROLES = [NodeRole.AUX]
+# on AUX in every cloud env. Single-node local/hobby get overridden to ALL by
+# the migration runner.
+_ROLES = [NodeRole.AUX]
operations = (
[
diff --git a/posthog/clickhouse/migrations/AGENTS.md b/posthog/clickhouse/migrations/AGENTS.md
index 990c976eb358..de440106a0a2 100644
--- a/posthog/clickhouse/migrations/AGENTS.md
+++ b/posthog/clickhouse/migrations/AGENTS.md
@@ -19,9 +19,18 @@ The main clusters are:
- 3 replicas
- ai_events 1x2
- aux 1x2
+- batch_exports 1x2
+- endpoints 1x2
+- logs 1x2
- sessions 1x2
- ops 1x2
+## Development
+
+Development mirrors the US Production layout — the main sharded cluster plus the same
+satellite clusters — at reduced node counts. Schema parity between Development and US
+Production is expected; migrations target both the same way.
+
## EU Production
The main cluster is: