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.

refactor(clickhouse): declare each schema object once (#96339)

Paweł Szczur3a0a9abea362
diff --git a/posthog/clickhouse/hcl/README.md b/posthog/clickhouse/hcl/README.md
index f62557915d20..ac29efbb0dcc 100644
--- a/posthog/clickhouse/hcl/README.md
+++ b/posthog/clickhouse/hcl/README.md
@@ -131,6 +131,12 @@ The wrapper resolves `$HCLEXP_BIN` → `hclexp` on `$PATH` → that image, so a
wins: run `bash $HCL/bin/install-hclexp` to extract one from the pinned image (what CI does), or
build it yourself with `go build -o hclexp ./cmd/hclexp` in `../../../../python-clickhouse-schema`.
+**Pass `-ignore-column-order` to every `hclexp diff` and `hclexp plan`.**
+`check.sh`, `check-live.sh`, `diff.sh` and `check-cloud.sh` all do.
+Column order carries no meaning here, and the layers cannot express it anyway: a patch cannot reorder the columns it inherits ([chschema#240](https://github.com/PostHog/chschema/issues/240)), so an object whose order differs between two compositions could otherwise only be written out in full.
+Without the flag, two identical schemas whose columns sit in a different order report a column change, which reads as real drift and is expensive to disprove.
+On our three cloud envs the flag removes 10 of the 26 `unsafe` rows the reconcile used to report.
+
1. **Edit the right layer** for what you're changing.
Placement = which node stacks compose the layer, declared in `manifest.hcl`; find an existing object's single declaration with `hclexp locate` (or grep) rather than assuming:
- an object on every role (the `query_log_archive` path, `custom_metrics_*` sub-views) → `roles/shared/`
diff --git a/posthog/clickhouse/hcl/bin/image.txt b/posthog/clickhouse/hcl/bin/image.txt
index 4e2c24ffe124..a7b669715ba6 100644
--- a/posthog/clickhouse/hcl/bin/image.txt
+++ b/posthog/clickhouse/hcl/bin/image.txt
@@ -1 +1 @@
-ghcr.io/posthog/chschema:sha-46db733
+ghcr.io/posthog/chschema:sha-171d6fe
diff --git a/posthog/clickhouse/hcl/check-cloud.sh b/posthog/clickhouse/hcl/check-cloud.sh
index 69d901577077..3ba82ad291f6 100755
--- a/posthog/clickhouse/hcl/check-cloud.sh
+++ b/posthog/clickhouse/hcl/check-cloud.sh
@@ -58,7 +58,7 @@ else
[ -d "$DUMPS/$env" ] || { echo "== $env: no dumps in $DUMPS, skipping =="; continue; }
json="$("$HCLEXP" plan -manifest "$MANIFEST" -env "$env" -layer-root "$HCL" \
- -dump "$DUMPS/$env" -exclude "$HCL/exclude.hcl" -format json 2>/dev/null)" || {
+ -dump "$DUMPS/$env" -exclude "$HCL/exclude.hcl" -ignore-column-order -format json 2>/dev/null)" || {
echo "FAIL: plan $env against $DUMPS/$env"; rc=1; continue
}
diff --git a/posthog/clickhouse/hcl/check-live.sh b/posthog/clickhouse/hcl/check-live.sh
index ecdc098e2146..034c30e9009b 100755
--- a/posthog/clickhouse/hcl/check-live.sh
+++ b/posthog/clickhouse/hcl/check-live.sh
@@ -70,7 +70,7 @@ for role in "${ROLES[@]}"; do
fi
echo "== $ENV/$role: diff golden vs live dump =="
- if drift="$("$HCLEXP" diff -left "$golden" -right "$live" -exclude "$EXCLUDE" -format json | report_drift)"; then
+ if drift="$("$HCLEXP" diff -left "$golden" -right "$live" -exclude "$EXCLUDE" -ignore-column-order -format json | report_drift)"; then
echo "no differences"
else
echo "DRIFT: $ENV/$role — migrations produced a schema that differs from the HCL golden"
diff --git a/posthog/clickhouse/hcl/check.sh b/posthog/clickhouse/hcl/check.sh
index b436bf7f1902..ff085d8b33cb 100755
--- a/posthog/clickhouse/hcl/check.sh
+++ b/posthog/clickhouse/hcl/check.sh
@@ -123,7 +123,7 @@ for env in $envs; do
echo "== $env/$role: diff vs golden =="
stack="$(manifest_stack "$env" "$role")"
err="$(mktemp)"
- out="$("$HCLEXP" diff -left "$stack" -right "$golden" 2>"$err")"
+ out="$("$HCLEXP" diff -left "$stack" -right "$golden" -ignore-column-order 2>"$err")"
if [ "$out" != "no differences" ]; then
echo "FAIL: drift in $env/$role"; echo "$out"; cat "$err"; rc=1
else
diff --git a/posthog/clickhouse/hcl/diff.sh b/posthog/clickhouse/hcl/diff.sh
index 0c3d042c3f6a..5d5dbcc93fb1 100755
--- a/posthog/clickhouse/hcl/diff.sh
+++ b/posthog/clickhouse/hcl/diff.sh
@@ -68,7 +68,7 @@ for env in $envs; do
echo "=============================================================="
echo "# $env/$role (committed@$REF -> working tree)"
echo "=============================================================="
- if ! "$HCLEXP" diff -left "$committed" -right "$working" -sql; then
+ if ! "$HCLEXP" diff -left "$committed" -right "$working" -ignore-column-order -sql; then
echo "WARN: hclexp diff failed for $env/$role" >&2
rc=1
fi
diff --git a/posthog/clickhouse/hcl/golden/dev/apm.hcl b/posthog/clickhouse/hcl/golden/dev/apm.hcl
index 87bb8360b73a..63a5e870f28a 100644
--- a/posthog/clickhouse/hcl/golden/dev/apm.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/apm.hcl
@@ -1200,6 +1200,12 @@ SQL
column "name" {
type = "String"
}
+ column "kind" {
+ type = "Int8"
+ }
+ column "flags" {
+ type = "UInt32"
+ }
column "timestamp" {
type = "DateTime64(6)"
}
@@ -1212,39 +1218,33 @@ SQL
column "service_name" {
type = "String"
}
+ column "resource_attributes" {
+ type = "Map(String, String)"
+ }
column "instrumentation_scope" {
type = "String"
}
- column "events" {
- type = "Array(String)"
- }
- column "links" {
- type = "Array(String)"
- }
- column "kind" {
- type = "Int8"
- }
- column "flags" {
- type = "UInt32"
+ column "attributes_map_str" {
+ type = "Map(String, String)"
}
column "dropped_attributes_count" {
type = "UInt32"
}
+ column "events" {
+ type = "Array(String)"
+ }
column "dropped_events_count" {
type = "UInt32"
}
+ column "links" {
+ type = "Array(String)"
+ }
column "dropped_links_count" {
type = "UInt32"
}
column "status_code" {
type = "Int16"
}
- column "attributes_map_str" {
- type = "Map(String, String)"
- }
- column "resource_attributes" {
- type = "Map(String, String)"
- }
column "team_id" {
type = "Int32"
}
diff --git a/posthog/clickhouse/hcl/golden/dev/data.hcl b/posthog/clickhouse/hcl/golden/dev/data.hcl
index 53c111b8a906..0df9f65834fb 100644
--- a/posthog/clickhouse/hcl/golden/dev/data.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/data.hcl
@@ -4047,16 +4047,16 @@ database "posthog" {
column "created_at" {
type = "DateTime64(6, 'UTC')"
}
- column "has_full_snapshot" {
- type = "Int8"
- comment = "column_materializer::has_full_snapshot"
- }
column "_timestamp" {
type = "DateTime"
}
column "_offset" {
type = "UInt64"
}
+ column "has_full_snapshot" {
+ type = "Int8"
+ comment = "column_materializer::has_full_snapshot"
+ }
column "events_summary" {
type = "Array(String)"
comment = "column_materializer::events_summary"
@@ -4137,9 +4137,21 @@ database "posthog" {
column "max_last_timestamp" {
type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
}
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
column "first_url" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
column "click_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
@@ -4170,29 +4182,14 @@ database "posthog" {
column "event_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
column "snapshot_source" {
type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
}
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
}
column "is_deleted" {
type = "SimpleAggregateFunction(max, UInt8)"
@@ -4211,6 +4208,9 @@ database "posthog" {
column "surfacing_score" {
type = "SimpleAggregateFunction(max, Nullable(Float32))"
}
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
engine "distributed" {
cluster_name = "posthog"
remote_database = "posthog"
@@ -6659,9 +6659,21 @@ database "posthog" {
column "max_last_timestamp" {
type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
}
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
column "first_url" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
column "click_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
@@ -6692,29 +6704,14 @@ database "posthog" {
column "event_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
column "snapshot_source" {
type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
}
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
}
column "is_deleted" {
type = "SimpleAggregateFunction(max, UInt8)"
@@ -6733,6 +6730,9 @@ database "posthog" {
column "surfacing_score" {
type = "SimpleAggregateFunction(max, Nullable(Float32))"
}
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
replica_name = "{replica}"
diff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hcl
index 1eaa5a4f3f8e..6d2357e95d11 100644
--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl
@@ -1,80 +1,4 @@
database "posthog" {
- table "kafka_metrics_avro" {
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "trace_flags" {
- type = "Nullable(Int32)"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "service_name" {
- type = "Nullable(String)"
- }
- column "metric_name" {
- type = "Nullable(String)"
- }
- column "metric_type" {
- type = "Nullable(String)"
- }
- column "value" {
- type = "Nullable(Float64)"
- }
- column "count" {
- type = "Nullable(Int64)"
- }
- column "histogram_bounds" {
- type = "Array(Float64)"
- }
- column "histogram_counts" {
- type = "Array(Int64)"
- }
- column "unit" {
- type = "Nullable(String)"
- }
- column "aggregation_temporality" {
- type = "Nullable(String)"
- }
- column "is_monotonic" {
- type = "Nullable(UInt8)"
- }
- column "resource_attributes" {
- type = "Map(String, String)"
- }
- column "instrumentation_scope" {
- type = "Nullable(String)"
- }
- column "attributes" {
- type = "Map(String, String)"
- }
- column "series_fingerprint" {
- type = "Nullable(Int64)"
- }
- engine "kafka" {
- collection = "warpstream_metrics"
- topic_list = "clickhouse_metrics"
- group_name = "clickhouse-metrics-avro-new"
- format = "Avro"
- num_consumers = 2
- max_block_size = 4096
- skip_broken_messages = 100
- poll_timeout_ms = 10000
- poll_max_batch_size = 4096
- flush_interval_ms = 10000
- thread_per_consumer = true
- }
- }
-
table "kafka_metrics_avro2" {
settings = {
input_format_avro_allow_missing_fields = "1"
@@ -160,83 +84,6 @@ database "posthog" {
}
}
- table "kafka_trace_spans_avro" {
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "parent_span_id" {
- type = "String"
- }
- column "trace_state" {
- type = "String"
- }
- column "name" {
- type = "String"
- }
- column "kind" {
- type = "Int32"
- }
- column "flags" {
- type = "Int32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "end_time" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "service_name" {
- type = "String"
- }
- column "resource_attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "dropped_attributes_count" {
- type = "Int32"
- }
- column "events" {
- type = "Array(String)"
- }
- column "dropped_events_count" {
- type = "Int32"
- }
- column "links" {
- type = "Array(String)"
- }
- column "dropped_links_count" {
- type = "Int32"
- }
- column "status_code" {
- type = "Int32"
- }
- engine "kafka" {
- collection = "warpstream_traces"
- topic_list = "clickhouse_traces"
- group_name = "clickhouse-traces-avro"
- format = "Avro"
- num_consumers = 8
- skip_broken_messages = 100
- poll_timeout_ms = 3000
- poll_max_batch_size = 1000
- thread_per_consumer = true
- }
- }
-
table "log_attributes2" {
order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value"]
partition_by = "toDate(time_bucket)"
@@ -3274,361 +3121,6 @@ SQL
}
}
- materialized_view "kafka_metrics_avro_kafka_metrics_mv" {
- to_table = "posthog.metrics_kafka_metrics"
- query = <<SQL
-SELECT
- _partition,
- _topic,
- maxSimpleState(_offset) AS max_offset,
- maxSimpleState(observed_timestamp) AS max_observed_timestamp,
- maxSimpleState(timestamp) AS max_timestamp,
- maxSimpleState(now()) AS max_created_at,
- maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM posthog.kafka_metrics_avro
-GROUP BY
- _partition, _topic
-SQL
-
- column "_partition" {
- type = "UInt64"
- }
- column "_topic" {
- type = "LowCardinality(String)"
- }
- column "max_offset" {
- type = "SimpleAggregateFunction(max, UInt64)"
- }
- column "max_observed_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6))"
- }
- column "max_created_at" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
- column "max_lag" {
- type = "SimpleAggregateFunction(max, Decimal(18, 6))"
- }
- }
-
- materialized_view "kafka_metrics_avro_mv" {
- to_table = "posthog.metrics1"
- query = <<SQL
-SELECT
- uuid,
- trace_id,
- span_id,
- ifNull(trace_flags, 0) AS trace_flags,
- timestamp,
- observed_timestamp,
- ifNull(service_name, '') AS service_name,
- ifNull(metric_name, '') AS metric_name,
- ifNull(metric_type, '') AS metric_type,
- ifNull(value, 0) AS value,
- toUInt64(ifNull(count, 1)) AS count,
- histogram_bounds,
- arrayMap(x -> toUInt64(x), histogram_counts) AS histogram_counts,
- ifNull(unit, '') AS unit,
- ifNull(aggregation_temporality, '') AS aggregation_temporality,
- ifNull(is_monotonic, 0) AS is_monotonic,
- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
- ifNull(instrumentation_scope, '') AS instrumentation_scope,
- mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,
- mapSort(
- mapFilter(
- (k, v) -> isNotNull(v),
- mapApply(
- (k, v) -> (concat(k, '__float'), toFloat64OrNull(JSONExtract(v, 'String'))),
- attributes
- )
- )
- ) 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
-SQL
-
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "trace_flags" {
- type = "Int32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "service_name" {
- type = "String"
- }
- column "metric_name" {
- type = "String"
- }
- column "metric_type" {
- type = "String"
- }
- column "value" {
- type = "Float64"
- }
- column "count" {
- type = "UInt64"
- }
- column "histogram_bounds" {
- type = "Array(Float64)"
- }
- column "histogram_counts" {
- type = "Array(UInt64)"
- }
- column "unit" {
- type = "String"
- }
- column "aggregation_temporality" {
- type = "String"
- }
- column "is_monotonic" {
- type = "UInt8"
- }
- column "resource_attributes" {
- type = "Map(String, String)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "attributes_map_str" {
- type = "Map(String, String)"
- }
- column "attributes_map_float" {
- type = "Map(String, Nullable(Float64))"
- }
- column "team_id" {
- type = "Int32"
- }
- }
-
- 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 "kafka_trace_spans_avro_mv" {
- to_table = "posthog.trace_spans"
- query = <<SQL
-SELECT
- * EXCEPT(attributes, resource_attributes, kind, flags, dropped_attributes_count, dropped_events_count, dropped_links_count, status_code),
- toInt8(kind) AS kind,
- toUInt32(flags) AS flags,
- toUInt32(dropped_attributes_count) AS dropped_attributes_count,
- toUInt32(dropped_events_count) AS dropped_events_count,
- toUInt32(dropped_links_count) AS dropped_links_count,
- toInt16(status_code) AS status_code,
- mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,
- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,
- observed_timestamp
- + toIntervalDay(
- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(15))
- ) AS original_expiry_timestamp,
- _partition,
- _topic,
- _offset,
- toInt64OrDefault(_headers.value[indexOf(_headers.name, 'record_count')], toInt64(1)) AS _record_count,
- toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) AS _bytes_uncompressed,
- toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) AS _bytes_compressed
-FROM posthog.kafka_trace_spans_avro
-SQL
-
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "parent_span_id" {
- type = "String"
- }
- column "trace_state" {
- type = "String"
- }
- column "name" {
- type = "String"
- }
- column "kind" {
- type = "Int8"
- }
- column "flags" {
- type = "UInt32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "end_time" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "service_name" {
- type = "String"
- }
- column "resource_attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "attributes_map_str" {
- type = "Map(LowCardinality(String), String)"
- }
- column "dropped_attributes_count" {
- type = "UInt32"
- }
- column "events" {
- type = "Array(String)"
- }
- column "dropped_events_count" {
- type = "UInt32"
- }
- column "links" {
- type = "Array(String)"
- }
- column "dropped_links_count" {
- type = "UInt32"
- }
- column "status_code" {
- type = "Int16"
- }
- column "team_id" {
- type = "Int32"
- }
- column "original_expiry_timestamp" {
- type = "DateTime64(6)"
- }
- }
-
materialized_view "logs34_to_log_attributes3" {
to_table = "posthog.log_attributes3"
query = <<SQL
diff --git a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl
index cca729f909e7..c5c9eccde3c9 100644
--- a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl
@@ -4520,16 +4520,16 @@ database "posthog" {
column "created_at" {
type = "DateTime64(6, 'UTC')"
}
- column "has_full_snapshot" {
- type = "Int8"
- comment = "column_materializer::has_full_snapshot"
- }
column "_timestamp" {
type = "DateTime"
}
column "_offset" {
type = "UInt64"
}
+ column "has_full_snapshot" {
+ type = "Int8"
+ comment = "column_materializer::has_full_snapshot"
+ }
column "events_summary" {
type = "Array(String)"
comment = "column_materializer::events_summary"
@@ -4610,9 +4610,21 @@ database "posthog" {
column "max_last_timestamp" {
type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
}
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
column "first_url" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
column "click_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
@@ -4643,29 +4655,14 @@ database "posthog" {
column "event_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
column "snapshot_source" {
type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
}
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
}
column "is_deleted" {
type = "SimpleAggregateFunction(max, UInt8)"
@@ -4684,6 +4681,9 @@ database "posthog" {
column "surfacing_score" {
type = "SimpleAggregateFunction(max, Nullable(Float32))"
}
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
engine "distributed" {
cluster_name = "posthog"
remote_database = "posthog"
@@ -6467,9 +6467,21 @@ database "posthog" {
column "max_last_timestamp" {
type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
}
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
column "first_url" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
column "click_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
@@ -6500,29 +6512,14 @@ database "posthog" {
column "event_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
column "snapshot_source" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
}
column "is_deleted" {
type = "SimpleAggregateFunction(max, UInt8)"
@@ -6541,6 +6538,9 @@ database "posthog" {
column "surfacing_score" {
type = "SimpleAggregateFunction(max, Nullable(Float32))"
}
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
replica_name = "{replica}"
diff --git a/posthog/clickhouse/hcl/golden/prod-us/data.hcl b/posthog/clickhouse/hcl/golden/prod-us/data.hcl
index dd290d04fb23..3d061bed3f98 100644
--- a/posthog/clickhouse/hcl/golden/prod-us/data.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-us/data.hcl
@@ -4405,9 +4405,21 @@ database "posthog" {
column "max_last_timestamp" {
type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
}
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
column "first_url" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
column "click_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
@@ -4438,29 +4450,14 @@ database "posthog" {
column "event_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
column "snapshot_source" {
type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
}
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
}
column "is_deleted" {
type = "SimpleAggregateFunction(max, UInt8)"
@@ -4479,6 +4476,9 @@ database "posthog" {
column "surfacing_score" {
type = "SimpleAggregateFunction(max, Nullable(Float32))"
}
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
engine "distributed" {
cluster_name = "posthog"
remote_database = "posthog"
@@ -6229,9 +6229,21 @@ database "posthog" {
column "max_last_timestamp" {
type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
}
+ column "block_first_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_last_timestamps" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
+ }
+ column "block_urls" {
+ type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
+ }
column "first_url" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "all_urls" {
+ type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
+ }
column "click_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
@@ -6262,29 +6274,14 @@ database "posthog" {
column "event_count" {
type = "SimpleAggregateFunction(sum, Int64)"
}
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
column "snapshot_source" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ column "_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime)"
}
column "is_deleted" {
type = "SimpleAggregateFunction(max, UInt8)"
@@ -6303,6 +6300,9 @@ database "posthog" {
column "surfacing_score" {
type = "SimpleAggregateFunction(max, Nullable(Float32))"
}
+ column "retention_period_days" {
+ type = "SimpleAggregateFunction(max, Nullable(Int64))"
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.session_replay_events"
replica_name = "{replica}"
diff --git a/posthog/clickhouse/hcl/manifest.hcl b/posthog/clickhouse/hcl/manifest.hcl
index 4ebaf3846fc6..a2e16ab19706 100644
--- a/posthog/clickhouse/hcl/manifest.hcl
+++ b/posthog/clickhouse/hcl/manifest.hcl
@@ -36,10 +36,10 @@ role "ops" {
# self-contained roles/logs/local (extracted from the live node) for the legacy
# logs32 family it still runs.
role "logs" {
- env "local-multi" { layers = ["roles/shared/qla.hcl", "roles/coshared/named_collections", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/local"] }
+ env "local-multi" { layers = ["roles/shared/qla.hcl", "roles/coshared/named_collections", "roles/coshared/apm_ingest", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/local"] }
env "dev" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/shared", "roles/logs/dev"] }
- env "prod-us" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/shared", "roles/logs/prod", "roles/logs/prod-us"] }
- env "prod-eu" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/shared", "roles/logs/prod", "roles/logs/prod-eu"] }
+ env "prod-us" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/apm_ingest", "roles/coshared/custom_metrics", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/shared", "roles/logs/prod", "roles/logs/prod-us"] }
+ env "prod-eu" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/apm_ingest", "roles/coshared/custom_metrics", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/shared", "roles/logs/prod", "roles/logs/prod-eu"] }
}
# APM satellite: the ingestion-apm nodes. Every env runs the shared custom_metrics
@@ -48,7 +48,7 @@ role "logs" {
# traces and metrics and the writable proxies they feed -- which the prod envs still
# run on their logs nodes.
role "apm" {
- env "dev" { layers = ["roles/shared/qla_write.hcl", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/apm/dev"] }
+ env "dev" { layers = ["roles/shared/qla_write.hcl", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/apm_ingest", "roles/coshared/logs_avro_ingest", "roles/apm/dev"] }
env "prod-us" { layers = ["roles/shared/qla_write.hcl", "roles/coshared/custom_metrics"] }
env "prod-eu" { layers = ["roles/shared/qla_write.hcl", "roles/coshared/custom_metrics"] }
}
@@ -131,7 +131,7 @@ role "data" {
# Beyond that they carry only the shared query_log_archive path. Role names are the
# hostClusterRole macros migrations target: events, small, medium.
role "events" {
- env "local-multi" { layers = ["roles/shared/qla.hcl", "roles/coshared/named_collections", "roles/coshared/events_json_write", "roles/ingestion_events/local"] }
+ env "local-multi" { layers = ["roles/shared/qla.hcl", "roles/coshared/named_collections", "roles/coshared/logs_avro_ingest", "roles/coshared/events_json_write", "roles/ingestion_events/local"] }
}
role "small" {
@@ -147,7 +147,7 @@ role "medium" {
# and not MULTINODE_CLICKHOUSE. Composed as the deduped union of the local-multi stacks it
# hosts, so any name two of those roles declare fails this load instead of drifting.
role "all" {
- env "local-single" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/ops/shared", "roles/ops/local", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/local", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/local", "roles/coshared/aux_data", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local", "roles/coshared/sessions_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local", "roles/ingestion_events/local", "roles/ingestion_events/local-single", "roles/ingestion_small/local", "roles/ingestion_medium/local"] }
+ env "local-single" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/apm_ingest", "roles/coshared/logs_avro_ingest", "roles/coshared/custom_metrics", "roles/ops/shared", "roles/ops/local", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/local", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/local", "roles/coshared/aux_data", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local", "roles/coshared/sessions_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local", "roles/ingestion_events/local", "roles/ingestion_events/local-single", "roles/ingestion_small/local", "roles/ingestion_medium/local"] }
}
# role "endpoints" {
diff --git a/posthog/clickhouse/hcl/migration.md b/posthog/clickhouse/hcl/migration.md
index d87baf8f2f5f..d8b696cc756d 100644
--- a/posthog/clickhouse/hcl/migration.md
+++ b/posthog/clickhouse/hcl/migration.md
@@ -99,6 +99,8 @@ Each table shall be **defined** once, if there's a difference between envs, it s
`hclexp locate -duplicates` draws exactly this line (verified against the pin: table+`patch_table` → 0, table+`override=true` → 0, `extend` refinements → 0, table+plain redeclaration → 1, abstract+abstract → 1), so it is the enforcement mechanism, not a heuristic. Both repos gate on it against a `duplicates-baseline.txt` that may only shrink.
+The same rule holds across **roles**, not just envs, and the guard cannot help you there. When two node classes run the same object — a Kafka consumer that dev runs on `ingestion-apm` and the prod clusters run on `logs`, a `writable_*` proxy the data and ingestion nodes both carry — the declaration moves into a layer both roles compose (`roles/coshared/<thing>`), and each role's own layer carries only its delta as a `patch_*`. Do **not** restate the object in the second role with `override = true`: the guard counts that as zero duplicates and stays green, so nothing will tell you the schema is now authored twice. The symptom is a large block copied into a second layer where only a handful of lines differ; if you are reaching for `override` because the object already exists somewhere else, the answer is almost always a coshared layer plus a patch. Reserve `override` for one name that genuinely denotes two different objects — `channel_definition`, a Distributed proxy on one cluster and a storage table on another.
+
The patch vocabulary covers tables and materialized views fully, so "express it as a patch" is always available for a content difference. `patch_table` carries `column` and `index` (both with positional `after`), `modify_column` (full replacement column spec — `type` is required), additive `projection`, `engine`, `order_by`, `partition_by`, `ttl` and `settings`; `patch_view` and `patch_dictionary` do the same for views and dictionaries, and `patch_materialized_view` carries `query` (replace) plus the column operations — an MV whose query differs per env stays declared once with per-env query patches. `settings` merge into the target with the patch winning on collision; everything else replaces. Built on demand in PostHog/chschema — #153 (settings merge), #156 (full vocab + `patch_view`/`patch_dictionary`), #159 (positioned column adds), #161 (positioned index adds), #170 (`patch_materialized_view`, MV `override = true`, projections in `patch_table`), #174/#175 (patches resolve with inheritance: a concrete-target patch applies after `extend`, so it can modify, drop, or position against inherited columns; abstract-target patches propagate to every child).
`patch_column` (#165) is the `extend` side of the same idea: a child using `extend` can specialize a single _inherited_ column — type, nullability, default kind, CODEC, TTL, comment — while keeping every unspecified field and the inherited column order. A plain `column` block on a child still means _add_, and still collides with an inherited name. This is what lets one codec-free abstract back both a storage table and its Distributed proxy, with only the storage child declaring CODECs:
diff --git a/posthog/clickhouse/hcl/roles/apm/dev/tables.hcl b/posthog/clickhouse/hcl/roles/apm/dev/tables.hcl
index da5b4ed4ccb2..4e88bec6c582 100644
--- a/posthog/clickhouse/hcl/roles/apm/dev/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/apm/dev/tables.hcl
@@ -1,16 +1,36 @@
-# The APM ingest chain, as dev runs it on its ingestion-apm nodes: the Kafka
-# consumers for logs, traces and metrics, their views, and the writable proxies
-# they feed. The prod envs still run this chain on their logs nodes, so an object
-# the logs role already declares is restated here rather than declared twice. dev
-# also tunes its consumers smaller than prod does.
+# What only dev's ingestion-apm nodes run: the writable proxies the ingest chain
+# feeds, and dev's own consumer tuning on top of the shared ingest layers. dev
+# runs its consumers smaller than the prod clusters do.
database "posthog" {
- table "kafka_logs_avro" {
- override = true
- settings = {
- input_format_avro_allow_missing_fields = "1"
+
+ table "writable_metric_samples1" {
+ column "team_id" {
+ type = "Int32"
}
- column "uuid" {
- type = "String"
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "series_fingerprint" {
+ type = "UInt64"
+ codec = "DoubleDelta"
+ }
+ column "timestamp" {
+ type = "DateTime64(6)"
+ codec = "DoubleDelta"
+ }
+ column "value" {
+ type = "Float64"
+ codec = "Gorilla(8)"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "1"
+ }
+ column "histogram_bounds" {
+ type = "Array(Float64)"
+ }
+ column "histogram_counts" {
+ type = "Array(UInt64)"
}
column "trace_id" {
type = "String"
@@ -21,67 +41,68 @@ database "posthog" {
column "trace_flags" {
type = "Int32"
}
- column "timestamp" {
- type = "DateTime64(6)"
+ engine "distributed" {
+ cluster_name = "logs"
+ remote_database = "posthog"
+ remote_table = "metric_samples1"
}
- column "observed_timestamp" {
- type = "DateTime64(6)"
+ }
+
+ table "writable_metric_series1" {
+ column "team_id" {
+ type = "Int32"
}
- column "body" {
- type = "String"
+ column "metric_name" {
+ type = "LowCardinality(String)"
}
- column "severity_text" {
- type = "String"
+ column "series_fingerprint" {
+ type = "UInt64"
+ codec = "DoubleDelta"
}
- column "severity_number" {
- type = "Int32"
+ column "metric_type" {
+ type = "LowCardinality(String)"
+ }
+ column "unit" {
+ type = "LowCardinality(String)"
+ }
+ column "aggregation_temporality" {
+ type = "LowCardinality(String)"
+ }
+ column "is_monotonic" {
+ type = "Bool"
+ default = "false"
}
column "service_name" {
- type = "String"
+ type = "LowCardinality(String)"
}
column "resource_attributes" {
type = "Map(LowCardinality(String), String)"
}
- column "instrumentation_scope" {
- type = "String"
- }
- column "event_name" {
- type = "String"
- }
column "attributes" {
type = "Map(LowCardinality(String), String)"
}
- column "retention_days" {
- type = "Nullable(Int32)"
- }
- column "pattern" {
- type = "Nullable(String)"
- }
- column "pattern_version" {
- type = "Nullable(Int32)"
+ column "last_seen" {
+ type = "DateTime64(6)"
+ codec = "DoubleDelta"
}
- engine "kafka" {
- collection = "warpstream_logs"
- topic_list = "clickhouse_logs"
- group_name = "clickhouse-logs-avro-new"
- format = "Avro"
- num_consumers = 4
- skip_broken_messages = 100
- poll_timeout_ms = 10000
- poll_max_batch_size = 1000
- flush_interval_ms = 10000
- thread_per_consumer = true
+ engine "distributed" {
+ cluster_name = "logs"
+ remote_database = "posthog"
+ remote_table = "metric_series1"
}
}
- table "kafka_metrics_avro" {
- override = true
- settings = {
- input_format_avro_allow_missing_fields = "1"
+ table "writable_metrics1" {
+ column "time_bucket" {
+ type = "DateTime"
+ materialized = "toStartOfDay(timestamp)"
}
column "uuid" {
type = "String"
}
+ column "team_id" {
+ type = "Int32"
+ }
column "trace_id" {
type = "String"
}
@@ -89,7 +110,7 @@ database "posthog" {
type = "String"
}
column "trace_flags" {
- type = "Nullable(Int32)"
+ type = "Int32"
}
column "timestamp" {
type = "DateTime64(6)"
@@ -97,70 +118,116 @@ database "posthog" {
column "observed_timestamp" {
type = "DateTime64(6)"
}
+ column "created_at" {
+ type = "DateTime64(6)"
+ materialized = "now()"
+ }
column "service_name" {
- type = "Nullable(String)"
+ type = "LowCardinality(String)"
}
column "metric_name" {
- type = "Nullable(String)"
+ type = "LowCardinality(String)"
}
column "metric_type" {
- type = "Nullable(String)"
+ type = "LowCardinality(String)"
}
column "value" {
- type = "Nullable(Float64)"
+ type = "Float64"
}
column "count" {
- type = "Nullable(Int64)"
+ type = "UInt64"
+ default = "1"
}
column "histogram_bounds" {
type = "Array(Float64)"
}
column "histogram_counts" {
- type = "Array(Int64)"
+ type = "Array(UInt64)"
}
column "unit" {
- type = "Nullable(String)"
+ type = "LowCardinality(String)"
}
column "aggregation_temporality" {
- type = "Nullable(String)"
+ type = "LowCardinality(String)"
}
column "is_monotonic" {
- type = "Nullable(UInt8)"
+ type = "Bool"
+ default = "false"
}
column "resource_attributes" {
- type = "Map(String, String)"
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "resource_fingerprint" {
+ type = "UInt64"
+ materialized = "cityHash64(resource_attributes)"
}
column "instrumentation_scope" {
- type = "Nullable(String)"
+ type = "String"
+ }
+ column "attributes_map_str" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "attributes_map_float" {
+ type = "Map(LowCardinality(String), Float64)"
+ }
+ column "time_minute" {
+ type = "DateTime"
+ alias = "toStartOfMinute(timestamp)"
}
column "attributes" {
- type = "Map(String, String)"
+ type = "Map(String, String)"
+ alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"
}
- column "series_fingerprint" {
- type = "Nullable(Int64)"
+ engine "distributed" {
+ cluster_name = "logs"
+ remote_database = "posthog"
+ remote_table = "metrics1"
}
- engine "kafka" {
- collection = "warpstream_metrics"
- topic_list = "clickhouse_metrics"
- group_name = "clickhouse-metrics-avro-new"
- format = "Avro"
- num_consumers = 4
- skip_broken_messages = 100
- poll_timeout_ms = 10000
- poll_max_batch_size = 1000
- flush_interval_ms = 10000
- thread_per_consumer = true
+ }
+
+ table "writable_metrics_kafka_metrics" {
+ column "_partition" {
+ type = "UInt32"
+ }
+ column "_topic" {
+ type = "String"
+ }
+ column "max_offset" {
+ type = "SimpleAggregateFunction(max, UInt64)"
+ }
+ column "max_observed_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(9))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(9))"
+ }
+ column "max_created_at" {
+ type = "SimpleAggregateFunction(max, DateTime64(9))"
+ }
+ column "max_lag" {
+ type = "SimpleAggregateFunction(max, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "logs"
+ remote_database = "posthog"
+ remote_table = "metrics_kafka_metrics"
}
}
- table "kafka_trace_spans_avro" {
- override = true
- settings = {
- input_format_avro_allow_missing_fields = "1"
+ table "writable_trace_spans" {
+ column "time_bucket" {
+ type = "DateTime"
+ materialized = "toStartOfInterval(timestamp, toIntervalHour(4))"
+ }
+ column "original_expiry_timestamp" {
+ type = "DateTime64(6)"
}
column "uuid" {
type = "String"
}
+ column "team_id" {
+ type = "Int32"
+ }
column "trace_id" {
type = "String"
}
@@ -170,17 +237,21 @@ database "posthog" {
column "parent_span_id" {
type = "String"
}
+ column "is_root_span" {
+ type = "Bool"
+ materialized = "replaceAll(trimRight(parent_span_id, '='), 'A', '') = ''"
+ }
column "trace_state" {
type = "String"
}
column "name" {
- type = "String"
+ type = "LowCardinality(String)"
}
column "kind" {
- type = "Int32"
+ type = "Int8"
}
column "flags" {
- type = "Int32"
+ type = "UInt32"
}
column "timestamp" {
type = "DateTime64(6)"
@@ -191,145 +262,65 @@ database "posthog" {
column "observed_timestamp" {
type = "DateTime64(6)"
}
+ column "created_at" {
+ type = "DateTime64(6)"
+ materialized = "now()"
+ }
+ column "duration_nano" {
+ type = "UInt64"
+ materialized = "toUInt64(dateDiff('microsecond', timestamp, end_time)) * 1000"
+ }
+ column "status_code" {
+ type = "Int16"
+ }
column "service_name" {
- type = "String"
+ type = "LowCardinality(String)"
}
column "resource_attributes" {
type = "Map(LowCardinality(String), String)"
}
+ column "resource_fingerprint" {
+ type = "UInt64"
+ materialized = "cityHash64(resource_attributes)"
+ }
column "instrumentation_scope" {
type = "String"
}
- column "attributes" {
+ column "attributes_map_str" {
type = "Map(LowCardinality(String), String)"
}
+ column "attributes" {
+ type = "Map(LowCardinality(String), String)"
+ alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"
+ }
+ column "attributes_map_float" {
+ type = "Map(LowCardinality(String), Float64)"
+ materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__float'), toFloat64OrNull(v)), attributes_map_str))"
+ }
+ column "attributes_map_datetime" {
+ type = "Map(LowCardinality(String), DateTime64(6))"
+ materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__datetime'), parseDateTimeBestEffortOrNull(v, 6)), attributes_map_str))"
+ }
column "dropped_attributes_count" {
- type = "Int32"
+ type = "UInt32"
+ }
+ column "dropped_events_count" {
+ type = "UInt32"
+ }
+ column "dropped_links_count" {
+ type = "UInt32"
}
column "events" {
type = "Array(String)"
}
- column "dropped_events_count" {
- type = "Int32"
- }
column "links" {
type = "Array(String)"
}
- column "dropped_links_count" {
- type = "Int32"
+ column "_partition" {
+ type = "UInt32"
}
- column "status_code" {
- type = "Int32"
- }
- engine "kafka" {
- collection = "warpstream_traces"
- topic_list = "clickhouse_traces"
- group_name = "clickhouse-traces-avro"
- format = "Avro"
- num_consumers = 4
- skip_broken_messages = 100
- poll_timeout_ms = 10000
- poll_max_batch_size = 1000
- flush_interval_ms = 10000
- thread_per_consumer = true
- }
- }
-
- table "writable_logs34" {
- override = true
- settings = {
- background_insert_batch = "1"
- }
- column "time_bucket" {
- type = "DateTime"
- materialized = "toStartOfDay(timestamp)"
- }
- column "original_expiry_timestamp" {
- type = "DateTime64(6)"
- }
- column "uuid" {
- type = "String"
- }
- column "team_id" {
- type = "Int32"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "trace_flags" {
- type = "Int32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- codec = "DoubleDelta"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "created_at" {
- type = "DateTime64(6)"
- materialized = "now()"
- }
- column "body" {
- type = "String"
- }
- column "severity_text" {
- type = "LowCardinality(String)"
- }
- column "severity_number" {
- type = "Int32"
- }
- column "service_name" {
- type = "LowCardinality(String)"
- }
- column "resource_attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "resource_fingerprint" {
- type = "UInt64"
- materialized = "cityHash64(resource_attributes)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "event_name" {
- type = "String"
- }
- column "attributes_map_str" {
- type = "Map(LowCardinality(String), String)"
- }
- column "level" {
- type = "String"
- alias = "severity_text"
- }
- column "mat_body_ipv4_matches" {
- type = "Array(String)"
- alias = "extractAll(body, '(\\\\d\\\\.((25[0-5]|(2[0-4]|1(0, 1)[0-9])(0, 1)[0-9])\\\\.)(2, 2)([0-9]))')"
- }
- column "time_minute" {
- type = "DateTime"
- alias = "toStartOfMinute(timestamp)"
- }
- column "attributes" {
- type = "Map(LowCardinality(String), String)"
- alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"
- }
- column "attributes_map_float" {
- type = "Map(LowCardinality(String), Float64)"
- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__float'), toFloat64OrNull(v)), attributes_map_str))"
- }
- column "attributes_map_datetime" {
- type = "Map(LowCardinality(String), DateTime64(6))"
- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__datetime'), parseDateTimeBestEffortOrNull(v, 6)), attributes_map_str))"
- }
- column "_partition" {
- type = "UInt32"
- }
- column "_topic" {
- type = "String"
+ column "_topic" {
+ type = "String"
}
column "_offset" {
type = "UInt64"
@@ -343,828 +334,109 @@ database "posthog" {
column "_record_count" {
type = "UInt64"
}
- column "pattern" {
- type = "String"
- }
- column "pattern_version" {
- type = "UInt8"
- }
engine "distributed" {
cluster_name = "logs"
remote_database = "posthog"
- remote_table = "logs34"
+ remote_table = "trace_spans"
}
}
- table "writable_metric_samples1" {
- column "team_id" {
- type = "Int32"
- }
- column "metric_name" {
- type = "LowCardinality(String)"
- }
- column "series_fingerprint" {
- type = "UInt64"
- codec = "DoubleDelta"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- codec = "DoubleDelta"
- }
- column "value" {
- type = "Float64"
- codec = "Gorilla(8)"
- }
- column "count" {
- type = "UInt64"
- default = "1"
- }
- 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"
- }
- engine "distributed" {
- cluster_name = "logs"
- remote_database = "posthog"
- remote_table = "metric_samples1"
+ patch_table "kafka_logs_avro" {
+ engine "kafka" {
+ collection = "warpstream_logs"
+ topic_list = "clickhouse_logs"
+ group_name = "clickhouse-logs-avro-new"
+ format = "Avro"
+ num_consumers = 4
+ skip_broken_messages = 100
+ poll_timeout_ms = 10000
+ poll_max_batch_size = 1000
+ flush_interval_ms = 10000
+ thread_per_consumer = true
}
}
- table "writable_metric_series1" {
- column "team_id" {
- type = "Int32"
- }
- column "metric_name" {
- type = "LowCardinality(String)"
- }
- column "series_fingerprint" {
- type = "UInt64"
- codec = "DoubleDelta"
- }
- column "metric_type" {
- type = "LowCardinality(String)"
- }
- column "unit" {
- type = "LowCardinality(String)"
- }
- column "aggregation_temporality" {
- type = "LowCardinality(String)"
- }
- column "is_monotonic" {
- type = "Bool"
- default = "false"
- }
- column "service_name" {
- type = "LowCardinality(String)"
- }
- column "resource_attributes" {
- type = "Map(LowCardinality(String), String)"
+ patch_table "kafka_metrics_avro" {
+ engine "kafka" {
+ collection = "warpstream_metrics"
+ topic_list = "clickhouse_metrics"
+ group_name = "clickhouse-metrics-avro-new"
+ format = "Avro"
+ num_consumers = 4
+ skip_broken_messages = 100
+ poll_timeout_ms = 10000
+ poll_max_batch_size = 1000
+ flush_interval_ms = 10000
+ thread_per_consumer = true
}
- column "attributes" {
- type = "Map(LowCardinality(String), String)"
+ settings = {
+ input_format_avro_allow_missing_fields = "1"
}
- column "last_seen" {
- type = "DateTime64(6)"
- codec = "DoubleDelta"
+ }
+
+ patch_table "kafka_trace_spans_avro" {
+ engine "kafka" {
+ collection = "warpstream_traces"
+ topic_list = "clickhouse_traces"
+ group_name = "clickhouse-traces-avro"
+ format = "Avro"
+ num_consumers = 4
+ skip_broken_messages = 100
+ poll_timeout_ms = 10000
+ poll_max_batch_size = 1000
+ flush_interval_ms = 10000
+ thread_per_consumer = true
}
- engine "distributed" {
- cluster_name = "logs"
- remote_database = "posthog"
- remote_table = "metric_series1"
+ settings = {
+ input_format_avro_allow_missing_fields = "1"
}
}
- table "writable_metrics1" {
- column "time_bucket" {
- type = "DateTime"
- materialized = "toStartOfDay(timestamp)"
+ # Same views the logs role runs, pointed at a different destination: the storage
+ # tables live on the logs nodes, so these write through the writable proxies above
+ # rather than straight into local tables.
+ #
+ # One is restated in full: its column set matches but the order does not, and no
+ # patch can reorder inherited columns. See PostHog/chschema#240.
+ patch_materialized_view "kafka_logs34_avro_mv" {
+ to_table = "posthog.writable_logs34"
+ modify_column "original_expiry_timestamp" {
+ type = "Nullable(DateTime64(6))"
}
- column "uuid" {
- type = "String"
+ modify_column "_bytes_uncompressed" {
+ type = "Nullable(Float64)"
}
- column "team_id" {
- type = "Int32"
+ modify_column "_bytes_compressed" {
+ type = "Nullable(Float64)"
}
- column "trace_id" {
- type = "String"
+ }
+
+ patch_materialized_view "kafka_metrics_avro_mv" {
+ to_table = "posthog.writable_metrics1"
+ }
+
+ patch_materialized_view "kafka_metrics_avro_kafka_metrics_mv" {
+ to_table = "posthog.writable_metrics_kafka_metrics"
+ }
+
+ patch_materialized_view "kafka_metrics_avro_to_metric_samples" {
+ to_table = "posthog.writable_metric_samples1"
+ }
+
+ patch_materialized_view "kafka_metrics_avro_to_metric_series" {
+ to_table = "posthog.writable_metric_series1"
+ }
+
+ patch_materialized_view "kafka_trace_spans_avro_mv" {
+ to_table = "posthog.writable_trace_spans"
+
+ modify_column "attributes_map_str" {
+ type = "Map(String, String)"
}
- column "span_id" {
- type = "String"
+ modify_column "resource_attributes" {
+ type = "Map(String, String)"
}
- column "trace_flags" {
- type = "Int32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "created_at" {
- type = "DateTime64(6)"
- materialized = "now()"
- }
- column "service_name" {
- type = "LowCardinality(String)"
- }
- column "metric_name" {
- type = "LowCardinality(String)"
- }
- column "metric_type" {
- type = "LowCardinality(String)"
- }
- column "value" {
- type = "Float64"
- }
- column "count" {
- type = "UInt64"
- default = "1"
- }
- column "histogram_bounds" {
- type = "Array(Float64)"
- }
- column "histogram_counts" {
- type = "Array(UInt64)"
- }
- column "unit" {
- type = "LowCardinality(String)"
- }
- column "aggregation_temporality" {
- type = "LowCardinality(String)"
- }
- column "is_monotonic" {
- type = "Bool"
- default = "false"
- }
- column "resource_attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "resource_fingerprint" {
- type = "UInt64"
- materialized = "cityHash64(resource_attributes)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "attributes_map_str" {
- type = "Map(LowCardinality(String), String)"
- }
- column "attributes_map_float" {
- type = "Map(LowCardinality(String), Float64)"
- }
- column "time_minute" {
- type = "DateTime"
- alias = "toStartOfMinute(timestamp)"
- }
- column "attributes" {
- type = "Map(String, String)"
- alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"
- }
- engine "distributed" {
- cluster_name = "logs"
- remote_database = "posthog"
- remote_table = "metrics1"
- }
- }
-
- table "writable_metrics_kafka_metrics" {
- column "_partition" {
- type = "UInt32"
- }
- column "_topic" {
- type = "String"
- }
- column "max_offset" {
- type = "SimpleAggregateFunction(max, UInt64)"
- }
- column "max_observed_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(9))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(9))"
- }
- column "max_created_at" {
- type = "SimpleAggregateFunction(max, DateTime64(9))"
- }
- column "max_lag" {
- type = "SimpleAggregateFunction(max, UInt64)"
- }
- engine "distributed" {
- cluster_name = "logs"
- remote_database = "posthog"
- remote_table = "metrics_kafka_metrics"
- }
- }
-
- table "writable_trace_spans" {
- column "time_bucket" {
- type = "DateTime"
- materialized = "toStartOfInterval(timestamp, toIntervalHour(4))"
- }
- column "original_expiry_timestamp" {
- type = "DateTime64(6)"
- }
- column "uuid" {
- type = "String"
- }
- column "team_id" {
- type = "Int32"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "parent_span_id" {
- type = "String"
- }
- column "is_root_span" {
- type = "Bool"
- materialized = "replaceAll(trimRight(parent_span_id, '='), 'A', '') = ''"
- }
- column "trace_state" {
- type = "String"
- }
- column "name" {
- type = "LowCardinality(String)"
- }
- column "kind" {
- type = "Int8"
- }
- column "flags" {
- type = "UInt32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "end_time" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "created_at" {
- type = "DateTime64(6)"
- materialized = "now()"
- }
- column "duration_nano" {
- type = "UInt64"
- materialized = "toUInt64(dateDiff('microsecond', timestamp, end_time)) * 1000"
- }
- column "status_code" {
- type = "Int16"
- }
- column "service_name" {
- type = "LowCardinality(String)"
- }
- column "resource_attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "resource_fingerprint" {
- type = "UInt64"
- materialized = "cityHash64(resource_attributes)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "attributes_map_str" {
- type = "Map(LowCardinality(String), String)"
- }
- column "attributes" {
- type = "Map(LowCardinality(String), String)"
- alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"
- }
- column "attributes_map_float" {
- type = "Map(LowCardinality(String), Float64)"
- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__float'), toFloat64OrNull(v)), attributes_map_str))"
- }
- column "attributes_map_datetime" {
- type = "Map(LowCardinality(String), DateTime64(6))"
- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__datetime'), parseDateTimeBestEffortOrNull(v, 6)), attributes_map_str))"
- }
- column "dropped_attributes_count" {
- type = "UInt32"
- }
- column "dropped_events_count" {
- type = "UInt32"
- }
- column "dropped_links_count" {
- type = "UInt32"
- }
- column "events" {
- type = "Array(String)"
- }
- column "links" {
- type = "Array(String)"
- }
- column "_partition" {
- type = "UInt32"
- }
- column "_topic" {
- type = "String"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_bytes_uncompressed" {
- type = "UInt64"
- }
- column "_bytes_compressed" {
- type = "UInt64"
- }
- column "_record_count" {
- type = "UInt64"
- }
- engine "distributed" {
- cluster_name = "logs"
- remote_database = "posthog"
- remote_table = "trace_spans"
- }
- }
-
- materialized_view "kafka_logs34_avro_mv" {
- override = true
- to_table = "posthog.writable_logs34"
- query = <<SQL
-SELECT
- uuid,
- trace_id,
- span_id,
- trace_flags,
- timestamp,
- observed_timestamp,
- body,
- severity_text,
- severity_number,
- service_name,
- instrumentation_scope,
- event_name,
- mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,
- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,
- observed_timestamp
- + toIntervalDay(
- if(
- (retention_days IS NOT NULL) AND (retention_days > 0),
- retention_days,
- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(15))
- )
- ) AS original_expiry_timestamp,
- _partition,
- _topic,
- _offset,
- toInt64OrDefault(_headers.value[indexOf(_headers.name, 'record_count')], toInt64(1)) AS _record_count,
- toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,
- toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,
- ifNull(pattern, '') AS pattern,
- toUInt8(ifNull(pattern_version, 0)) AS pattern_version
-FROM posthog.kafka_logs_avro
-SQL
-
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "trace_flags" {
- type = "Int32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "body" {
- type = "String"
- }
- column "severity_text" {
- type = "String"
- }
- column "severity_number" {
- type = "Int32"
- }
- column "service_name" {
- type = "String"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "event_name" {
- type = "String"
- }
- column "attributes_map_str" {
- type = "Map(String, String)"
- }
- column "resource_attributes" {
- type = "Map(String, String)"
- }
- column "team_id" {
- type = "Int32"
- }
- column "original_expiry_timestamp" {
- type = "Nullable(DateTime64(6))"
- }
- column "_partition" {
- type = "UInt64"
- }
- column "_topic" {
- type = "LowCardinality(String)"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_record_count" {
- type = "Int64"
- }
- column "_bytes_uncompressed" {
- type = "Nullable(Float64)"
- }
- column "_bytes_compressed" {
- type = "Nullable(Float64)"
- }
- column "pattern" {
- type = "String"
- }
- column "pattern_version" {
- type = "UInt8"
- }
- }
-
- materialized_view "kafka_metrics_avro_kafka_metrics_mv" {
- override = true
- to_table = "posthog.writable_metrics_kafka_metrics"
- query = <<SQL
-SELECT
- _partition,
- _topic,
- maxSimpleState(_offset) AS max_offset,
- maxSimpleState(observed_timestamp) AS max_observed_timestamp,
- maxSimpleState(timestamp) AS max_timestamp,
- maxSimpleState(now()) AS max_created_at,
- maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM posthog.kafka_metrics_avro
-GROUP BY
- _partition, _topic
-SQL
-
- column "_partition" {
- type = "UInt64"
- }
- column "_topic" {
- type = "LowCardinality(String)"
- }
- column "max_offset" {
- type = "SimpleAggregateFunction(max, UInt64)"
- }
- column "max_observed_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6))"
- }
- column "max_created_at" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
- column "max_lag" {
- type = "SimpleAggregateFunction(max, Decimal(18, 6))"
- }
- }
-
- materialized_view "kafka_metrics_avro_mv" {
- override = true
- to_table = "posthog.writable_metrics1"
- query = <<SQL
-SELECT
- uuid,
- trace_id,
- span_id,
- ifNull(trace_flags, 0) AS trace_flags,
- timestamp,
- observed_timestamp,
- ifNull(service_name, '') AS service_name,
- ifNull(metric_name, '') AS metric_name,
- ifNull(metric_type, '') AS metric_type,
- ifNull(value, 0) AS value,
- toUInt64(ifNull(count, 1)) AS count,
- histogram_bounds,
- arrayMap(x -> toUInt64(x), histogram_counts) AS histogram_counts,
- ifNull(unit, '') AS unit,
- ifNull(aggregation_temporality, '') AS aggregation_temporality,
- ifNull(is_monotonic, 0) AS is_monotonic,
- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
- ifNull(instrumentation_scope, '') AS instrumentation_scope,
- mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,
- mapSort(
- mapFilter(
- (k, v) -> isNotNull(v),
- mapApply(
- (k, v) -> (concat(k, '__float'), toFloat64OrNull(JSONExtract(v, 'String'))),
- attributes
- )
- )
- ) 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
-SQL
-
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "trace_flags" {
- type = "Int32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "service_name" {
- type = "String"
- }
- column "metric_name" {
- type = "String"
- }
- column "metric_type" {
- type = "String"
- }
- column "value" {
- type = "Float64"
- }
- column "count" {
- type = "UInt64"
- }
- column "histogram_bounds" {
- type = "Array(Float64)"
- }
- column "histogram_counts" {
- type = "Array(UInt64)"
- }
- column "unit" {
- type = "String"
- }
- column "aggregation_temporality" {
- type = "String"
- }
- column "is_monotonic" {
- type = "UInt8"
- }
- column "resource_attributes" {
- type = "Map(String, String)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "attributes_map_str" {
- type = "Map(String, String)"
- }
- column "attributes_map_float" {
- type = "Map(String, Nullable(Float64))"
- }
- column "team_id" {
- type = "Int32"
- }
- }
-
- materialized_view "kafka_metrics_avro_to_metric_samples" {
- override = true
- to_table = "posthog.writable_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" {
- override = true
- to_table = "posthog.writable_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 "kafka_trace_spans_avro_mv" {
- override = true
- to_table = "posthog.writable_trace_spans"
- query = <<SQL
-SELECT
- * EXCEPT(attributes, resource_attributes, kind, flags, dropped_attributes_count, dropped_events_count, dropped_links_count, status_code),
- toInt8(kind) AS kind,
- toUInt32(flags) AS flags,
- toUInt32(dropped_attributes_count) AS dropped_attributes_count,
- toUInt32(dropped_events_count) AS dropped_events_count,
- toUInt32(dropped_links_count) AS dropped_links_count,
- toInt16(status_code) AS status_code,
- mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,
- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,
- observed_timestamp
- + toIntervalDay(
- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(15))
- ) AS original_expiry_timestamp,
- _partition,
- _topic,
- _offset,
- toInt64OrDefault(_headers.value[indexOf(_headers.name, 'record_count')], toInt64(1)) AS _record_count,
- toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) AS _bytes_uncompressed,
- toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) AS _bytes_compressed
-FROM posthog.kafka_trace_spans_avro
-SQL
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "parent_span_id" {
- type = "String"
- }
- column "trace_state" {
- type = "String"
- }
- column "name" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "end_time" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "service_name" {
- type = "String"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "events" {
- type = "Array(String)"
- }
- column "links" {
- type = "Array(String)"
- }
- column "kind" {
- type = "Int8"
- }
- column "flags" {
- type = "UInt32"
- }
- column "dropped_attributes_count" {
- type = "UInt32"
- }
- column "dropped_events_count" {
- type = "UInt32"
- }
- column "dropped_links_count" {
- type = "UInt32"
- }
- column "status_code" {
- type = "Int16"
- }
- column "attributes_map_str" {
- type = "Map(String, String)"
- }
- column "resource_attributes" {
- type = "Map(String, String)"
- }
- column "team_id" {
- type = "Int32"
- }
- column "original_expiry_timestamp" {
- type = "DateTime64(6)"
- }
column "_partition" {
type = "UInt64"
}
diff --git a/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_kafka_metrics_mv.sql b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_kafka_metrics_mv.sql
new file mode 100644
index 000000000000..78119c311222
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_kafka_metrics_mv.sql
@@ -0,0 +1,11 @@
+SELECT
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
+ maxSimpleState(observed_timestamp) AS max_observed_timestamp,
+ maxSimpleState(timestamp) AS max_timestamp,
+ maxSimpleState(now()) AS max_created_at,
+ maxSimpleState(now() - observed_timestamp) AS max_lag
+FROM posthog.kafka_metrics_avro
+GROUP BY
+ _partition, _topic
diff --git a/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_mv.sql b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_mv.sql
new file mode 100644
index 000000000000..83238b61833c
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_mv.sql
@@ -0,0 +1,34 @@
+SELECT
+ uuid,
+ trace_id,
+ span_id,
+ ifNull(trace_flags, 0) AS trace_flags,
+ timestamp,
+ observed_timestamp,
+ ifNull(service_name, '') AS service_name,
+ ifNull(metric_name, '') AS metric_name,
+ ifNull(metric_type, '') AS metric_type,
+ ifNull(value, 0) AS value,
+ toUInt64(ifNull(count, 1)) AS count,
+ histogram_bounds,
+ arrayMap(x -> toUInt64(x), histogram_counts) AS histogram_counts,
+ ifNull(unit, '') AS unit,
+ ifNull(aggregation_temporality, '') AS aggregation_temporality,
+ ifNull(is_monotonic, 0) AS is_monotonic,
+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
+ ifNull(instrumentation_scope, '') AS instrumentation_scope,
+ mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,
+ mapSort(
+ mapFilter(
+ (k, v) -> isNotNull(v),
+ mapApply(
+ (k, v) -> (concat(k, '__float'), toFloat64OrNull(JSONExtract(v, 'String'))),
+ attributes
+ )
+ )
+ ) 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
diff --git a/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_to_metric_samples.sql b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_to_metric_samples.sql
new file mode 100644
index 000000000000..977ee9a7ea79
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_to_metric_samples.sql
@@ -0,0 +1,17 @@
+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
diff --git a/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_to_metric_series.sql b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_to_metric_series.sql
new file mode 100644
index 000000000000..6297629b5a01
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_to_metric_series.sql
@@ -0,0 +1,17 @@
+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/roles/coshared/apm_ingest/sql/kafka_trace_spans_avro_mv.sql b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_trace_spans_avro_mv.sql
new file mode 100644
index 000000000000..88af352654c4
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_trace_spans_avro_mv.sql
@@ -0,0 +1,22 @@
+SELECT
+ * EXCEPT(attributes, resource_attributes, kind, flags, dropped_attributes_count, dropped_events_count, dropped_links_count, status_code),
+ toInt8(kind) AS kind,
+ toUInt32(flags) AS flags,
+ toUInt32(dropped_attributes_count) AS dropped_attributes_count,
+ toUInt32(dropped_events_count) AS dropped_events_count,
+ toUInt32(dropped_links_count) AS dropped_links_count,
+ toInt16(status_code) AS status_code,
+ mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,
+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,
+ observed_timestamp
+ + toIntervalDay(
+ toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(15))
+ ) AS original_expiry_timestamp,
+ _partition,
+ _topic,
+ _offset,
+ toInt64OrDefault(_headers.value[indexOf(_headers.name, 'record_count')], toInt64(1)) AS _record_count,
+ toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) AS _bytes_uncompressed,
+ toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) AS _bytes_compressed
+FROM posthog.kafka_trace_spans_avro
diff --git a/posthog/clickhouse/hcl/roles/coshared/apm_ingest/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/tables.hcl
new file mode 100644
index 000000000000..0007acab2adf
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/tables.hcl
@@ -0,0 +1,401 @@
+# The Kafka ingest for metrics and traces: the consumers and the views that
+# drain them. dev runs this on its ingestion-apm nodes, the prod clusters on
+# their logs nodes, so it sits here rather than inside either role.
+database "posthog" {
+ table "kafka_metrics_avro" {
+ column "uuid" {
+ type = "String"
+ }
+ column "trace_id" {
+ type = "String"
+ }
+ column "span_id" {
+ type = "String"
+ }
+ column "trace_flags" {
+ type = "Nullable(Int32)"
+ }
+ column "timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "observed_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "service_name" {
+ type = "Nullable(String)"
+ }
+ column "metric_name" {
+ type = "Nullable(String)"
+ }
+ column "metric_type" {
+ type = "Nullable(String)"
+ }
+ column "value" {
+ type = "Nullable(Float64)"
+ }
+ column "count" {
+ type = "Nullable(Int64)"
+ }
+ column "histogram_bounds" {
+ type = "Array(Float64)"
+ }
+ column "histogram_counts" {
+ type = "Array(Int64)"
+ }
+ column "unit" {
+ type = "Nullable(String)"
+ }
+ column "aggregation_temporality" {
+ type = "Nullable(String)"
+ }
+ column "is_monotonic" {
+ type = "Nullable(UInt8)"
+ }
+ column "resource_attributes" {
+ type = "Map(String, String)"
+ }
+ column "instrumentation_scope" {
+ type = "Nullable(String)"
+ }
+ column "attributes" {
+ type = "Map(String, String)"
+ }
+ column "series_fingerprint" {
+ type = "Nullable(Int64)"
+ }
+ engine "kafka" {
+ collection = "warpstream_metrics"
+ topic_list = "clickhouse_metrics"
+ group_name = "clickhouse-metrics-avro-new"
+ format = "Avro"
+ num_consumers = 8
+ skip_broken_messages = 100
+ poll_timeout_ms = 3000
+ poll_max_batch_size = 1000
+ thread_per_consumer = true
+ }
+ }
+
+ materialized_view "kafka_metrics_avro_kafka_metrics_mv" {
+ to_table = "posthog.metrics_kafka_metrics"
+ query = file("sql/kafka_metrics_avro_kafka_metrics_mv.sql")
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "_topic" {
+ type = "LowCardinality(String)"
+ }
+ column "max_offset" {
+ type = "SimpleAggregateFunction(max, UInt64)"
+ }
+ column "max_observed_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6))"
+ }
+ column "max_timestamp" {
+ type = "SimpleAggregateFunction(max, DateTime64(6))"
+ }
+ column "max_created_at" {
+ type = "SimpleAggregateFunction(max, DateTime)"
+ }
+ column "max_lag" {
+ type = "SimpleAggregateFunction(max, Decimal(18, 6))"
+ }
+ }
+
+ materialized_view "kafka_metrics_avro_mv" {
+ to_table = "posthog.metrics1"
+ query = file("sql/kafka_metrics_avro_mv.sql")
+ column "uuid" {
+ type = "String"
+ }
+ column "trace_id" {
+ type = "String"
+ }
+ column "span_id" {
+ type = "String"
+ }
+ column "trace_flags" {
+ type = "Int32"
+ }
+ column "timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "observed_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "service_name" {
+ type = "String"
+ }
+ column "metric_name" {
+ type = "String"
+ }
+ column "metric_type" {
+ type = "String"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ }
+ column "histogram_bounds" {
+ type = "Array(Float64)"
+ }
+ column "histogram_counts" {
+ type = "Array(UInt64)"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "aggregation_temporality" {
+ type = "String"
+ }
+ column "is_monotonic" {
+ type = "UInt8"
+ }
+ column "resource_attributes" {
+ type = "Map(String, String)"
+ }
+ column "instrumentation_scope" {
+ type = "String"
+ }
+ column "attributes_map_str" {
+ type = "Map(String, String)"
+ }
+ column "attributes_map_float" {
+ type = "Map(String, Nullable(Float64))"
+ }
+ column "team_id" {
+ type = "Int32"
+ }
+ }
+
+ materialized_view "kafka_metrics_avro_to_metric_samples" {
+ to_table = "posthog.metric_samples1"
+ query = file("sql/kafka_metrics_avro_to_metric_samples.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 = file("sql/kafka_metrics_avro_to_metric_series.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)"
+ }
+ }
+
+ table "kafka_trace_spans_avro" {
+ column "uuid" {
+ type = "String"
+ }
+ column "trace_id" {
+ type = "String"
+ }
+ column "span_id" {
+ type = "String"
+ }
+ column "parent_span_id" {
+ type = "String"
+ }
+ column "trace_state" {
+ type = "String"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "kind" {
+ type = "Int32"
+ }
+ column "flags" {
+ type = "Int32"
+ }
+ column "timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "end_time" {
+ type = "DateTime64(6)"
+ }
+ column "observed_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "service_name" {
+ type = "String"
+ }
+ column "resource_attributes" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "instrumentation_scope" {
+ type = "String"
+ }
+ column "attributes" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "dropped_attributes_count" {
+ type = "Int32"
+ }
+ column "events" {
+ type = "Array(String)"
+ }
+ column "dropped_events_count" {
+ type = "Int32"
+ }
+ column "links" {
+ type = "Array(String)"
+ }
+ column "dropped_links_count" {
+ type = "Int32"
+ }
+ column "status_code" {
+ type = "Int32"
+ }
+ engine "kafka" {
+ collection = "warpstream_traces"
+ topic_list = "clickhouse_traces"
+ group_name = "clickhouse-traces-avro"
+ format = "Avro"
+ num_consumers = 8
+ skip_broken_messages = 100
+ poll_timeout_ms = 3000
+ poll_max_batch_size = 1000
+ thread_per_consumer = true
+ }
+ }
+
+ materialized_view "kafka_trace_spans_avro_mv" {
+ to_table = "posthog.trace_spans"
+ query = file("sql/kafka_trace_spans_avro_mv.sql")
+ column "uuid" {
+ type = "String"
+ }
+ column "trace_id" {
+ type = "String"
+ }
+ column "span_id" {
+ type = "String"
+ }
+ column "parent_span_id" {
+ type = "String"
+ }
+ column "trace_state" {
+ type = "String"
+ }
+ column "name" {
+ type = "String"
+ }
+ column "kind" {
+ type = "Int8"
+ }
+ column "flags" {
+ type = "UInt32"
+ }
+ column "timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "end_time" {
+ type = "DateTime64(6)"
+ }
+ column "observed_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "service_name" {
+ type = "String"
+ }
+ column "resource_attributes" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "instrumentation_scope" {
+ type = "String"
+ }
+ column "attributes_map_str" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "dropped_attributes_count" {
+ type = "UInt32"
+ }
+ column "events" {
+ type = "Array(String)"
+ }
+ column "dropped_events_count" {
+ type = "UInt32"
+ }
+ column "links" {
+ type = "Array(String)"
+ }
+ column "dropped_links_count" {
+ type = "UInt32"
+ }
+ column "status_code" {
+ type = "Int16"
+ }
+ column "team_id" {
+ type = "Int32"
+ }
+ column "original_expiry_timestamp" {
+ type = "DateTime64(6)"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/sql/kafka_logs34_avro_mv.sql b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/sql/kafka_logs34_avro_mv.sql
new file mode 100644
index 000000000000..267ac14d472c
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/sql/kafka_logs34_avro_mv.sql
@@ -0,0 +1,33 @@
+SELECT
+ uuid,
+ trace_id,
+ span_id,
+ trace_flags,
+ timestamp,
+ observed_timestamp,
+ body,
+ severity_text,
+ severity_number,
+ service_name,
+ instrumentation_scope,
+ event_name,
+ mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,
+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,
+ observed_timestamp
+ + toIntervalDay(
+ if(
+ (retention_days IS NOT NULL) AND (retention_days > 0),
+ retention_days,
+ toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(15))
+ )
+ ) AS original_expiry_timestamp,
+ _partition,
+ _topic,
+ _offset,
+ toInt64OrDefault(_headers.value[indexOf(_headers.name, 'record_count')], toInt64(1)) AS _record_count,
+ toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,
+ toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,
+ ifNull(pattern, '') AS pattern,
+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version
+FROM posthog.kafka_logs_avro
diff --git a/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/tables.hcl
new file mode 100644
index 000000000000..2eb8d14faf71
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/tables.hcl
@@ -0,0 +1,268 @@
+# The Kafka ingest for logs. dev runs this on its ingestion-apm nodes, the prod
+# clusters on their ingestion-events nodes.
+database "posthog" {
+ table "kafka_logs_avro" {
+ column "uuid" {
+ type = "String"
+ }
+ column "trace_id" {
+ type = "String"
+ }
+ column "span_id" {
+ type = "String"
+ }
+ column "trace_flags" {
+ type = "Int32"
+ }
+ column "timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "observed_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "body" {
+ type = "String"
+ }
+ column "severity_text" {
+ type = "String"
+ }
+ column "severity_number" {
+ type = "Int32"
+ }
+ column "service_name" {
+ type = "String"
+ }
+ column "resource_attributes" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "instrumentation_scope" {
+ type = "String"
+ }
+ column "event_name" {
+ type = "String"
+ }
+ column "attributes" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "retention_days" {
+ type = "Nullable(Int32)"
+ }
+ column "pattern" {
+ type = "Nullable(String)"
+ }
+ column "pattern_version" {
+ type = "Nullable(Int32)"
+ }
+ engine "kafka" {
+ collection = "warpstream_logs"
+ topic_list = "clickhouse_logs"
+ group_name = "clickhouse-logs-avro-new"
+ format = "Avro"
+ num_consumers = 8
+ skip_broken_messages = 100
+ poll_timeout_ms = 3000
+ poll_max_batch_size = 1000
+ thread_per_consumer = true
+ }
+ settings = {
+ input_format_avro_allow_missing_fields = "1"
+ }
+ }
+
+ materialized_view "kafka_logs34_avro_mv" {
+ to_table = "posthog.writable_logs34"
+ query = file("sql/kafka_logs34_avro_mv.sql")
+ column "uuid" {
+ type = "String"
+ }
+ column "trace_id" {
+ type = "String"
+ }
+ column "span_id" {
+ type = "String"
+ }
+ column "trace_flags" {
+ type = "Int32"
+ }
+ column "timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "observed_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "body" {
+ type = "String"
+ }
+ column "severity_text" {
+ type = "String"
+ }
+ column "severity_number" {
+ type = "Int32"
+ }
+ column "service_name" {
+ type = "String"
+ }
+ column "instrumentation_scope" {
+ type = "String"
+ }
+ column "event_name" {
+ type = "String"
+ }
+ column "attributes_map_str" {
+ type = "Map(String, String)"
+ }
+ column "resource_attributes" {
+ type = "Map(String, String)"
+ }
+ column "team_id" {
+ type = "Int32"
+ }
+ column "original_expiry_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "_partition" {
+ type = "UInt64"
+ }
+ column "_topic" {
+ type = "LowCardinality(String)"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_record_count" {
+ type = "Int64"
+ }
+ column "_bytes_uncompressed" {
+ type = "Nullable(Int64)"
+ }
+ column "_bytes_compressed" {
+ type = "Nullable(Int64)"
+ }
+ column "pattern" {
+ type = "String"
+ }
+ column "pattern_version" {
+ type = "UInt8"
+ }
+ }
+
+ table "writable_logs34" {
+ column "time_bucket" {
+ type = "DateTime"
+ materialized = "toStartOfDay(timestamp)"
+ }
+ column "original_expiry_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "uuid" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int32"
+ }
+ column "trace_id" {
+ type = "String"
+ }
+ column "span_id" {
+ type = "String"
+ }
+ column "trace_flags" {
+ type = "Int32"
+ }
+ column "timestamp" {
+ type = "DateTime64(6)"
+ codec = "DoubleDelta"
+ }
+ column "observed_timestamp" {
+ type = "DateTime64(6)"
+ }
+ column "created_at" {
+ type = "DateTime64(6)"
+ materialized = "now()"
+ }
+ column "body" {
+ type = "String"
+ }
+ column "severity_text" {
+ type = "LowCardinality(String)"
+ }
+ column "severity_number" {
+ type = "Int32"
+ }
+ column "service_name" {
+ type = "LowCardinality(String)"
+ }
+ column "resource_attributes" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "resource_fingerprint" {
+ type = "UInt64"
+ materialized = "cityHash64(resource_attributes)"
+ }
+ column "instrumentation_scope" {
+ type = "String"
+ }
+ column "event_name" {
+ type = "String"
+ }
+ column "attributes_map_str" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "level" {
+ type = "String"
+ alias = "severity_text"
+ }
+ column "mat_body_ipv4_matches" {
+ type = "Array(String)"
+ alias = "extractAll(body, '(\\\\d\\\\.((25[0-5]|(2[0-4]|1(0, 1)[0-9])(0, 1)[0-9])\\\\.)(2, 2)([0-9]))')"
+ }
+ column "time_minute" {
+ type = "DateTime"
+ alias = "toStartOfMinute(timestamp)"
+ }
+ column "attributes" {
+ type = "Map(LowCardinality(String), String)"
+ alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"
+ }
+ column "attributes_map_float" {
+ type = "Map(LowCardinality(String), Float64)"
+ materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__float'), toFloat64OrNull(v)), attributes_map_str))"
+ }
+ column "attributes_map_datetime" {
+ type = "Map(LowCardinality(String), DateTime64(6))"
+ materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__datetime'), parseDateTimeBestEffortOrNull(v, 6)), attributes_map_str))"
+ }
+ column "_partition" {
+ type = "UInt32"
+ }
+ column "_topic" {
+ type = "String"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "_bytes_uncompressed" {
+ type = "UInt64"
+ }
+ column "_bytes_compressed" {
+ type = "UInt64"
+ }
+ column "_record_count" {
+ type = "UInt64"
+ }
+ column "pattern" {
+ type = "String"
+ }
+ column "pattern_version" {
+ type = "UInt8"
+ }
+ settings = {
+ background_insert_batch = "1"
+ }
+ engine "distributed" {
+ cluster_name = "logs"
+ remote_database = "posthog"
+ remote_table = "logs34"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/data/cloud/tables.hcl b/posthog/clickhouse/hcl/roles/data/cloud/tables.hcl
index c622ac5d9400..65ed2da2b680 100644
--- a/posthog/clickhouse/hcl/roles/data/cloud/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/data/cloud/tables.hcl
@@ -83,134 +83,6 @@ database "posthog" {
}
}
- table "clickhouse_cleanup_deleted_persons" {
- override = true
- order_by = ["run_id", "team_id", "person_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "person_id" {
- type = "UUID"
- }
- column "max_version" {
- type = "UInt64"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_orphaned_distinct_ids" {
- override = true
- order_by = ["run_id", "team_id", "distinct_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "own_tombstone" {
- type = "UInt8"
- }
- column "max_version" {
- type = "Int64"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_revived_distinct_ids" {
- override = true
- order_by = ["run_id", "team_id", "distinct_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_revived_persons" {
- override = true
- order_by = ["run_id", "team_id", "person_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "person_id" {
- type = "UUID"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
table "cohortpeople" {
override = true
order_by = ["team_id", "cohort_id", "person_id", "version"]
@@ -239,300 +111,6 @@ database "posthog" {
}
}
- table "distributed_events_recent" {
- override = true
- column "uuid" {
- type = "UUID"
- }
- column "event" {
- type = "String"
- }
- column "properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "elements_chain" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- }
- column "person_id" {
- type = "UUID"
- }
- column "person_created_at" {
- type = "DateTime64(3)"
- }
- column "person_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group0_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group1_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group2_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group3_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group4_properties" {
- type = "String"
- codec = "ZSTD(3)"
- }
- column "group0_created_at" {
- type = "DateTime64(3)"
- }
- column "group1_created_at" {
- type = "DateTime64(3)"
- }
- column "group2_created_at" {
- type = "DateTime64(3)"
- }
- column "group3_created_at" {
- type = "DateTime64(3)"
- }
- column "group4_created_at" {
- type = "DateTime64(3)"
- }
- column "person_mode" {
- type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- column "inserted_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- column "_timestamp_ms" {
- type = "DateTime64(3)"
- }
- engine "distributed" {
- cluster_name = "batch_exports"
- remote_database = "posthog"
- remote_table = "sharded_events_recent"
- sharding_key = "sipHash64(distinct_id)"
- }
- }
-
- table "distributed_posthog_document_embeddings" {
- override = true
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "model_name" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- default = "''"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_posthog_document_embeddings"
- sharding_key = "cityHash64(document_id)"
- }
- }
-
- table "distributed_system_processes" {
- override = true
- settings = {
- skip_unavailable_shards = "1"
- }
- column "is_initial_query" {
- type = "UInt8"
- }
- column "user" {
- type = "String"
- }
- column "query_id" {
- type = "String"
- }
- column "address" {
- type = "IPv6"
- }
- column "port" {
- type = "UInt16"
- }
- column "initial_user" {
- type = "String"
- }
- column "initial_query_id" {
- type = "String"
- }
- column "initial_address" {
- type = "IPv6"
- }
- column "initial_port" {
- type = "UInt16"
- }
- column "interface" {
- type = "UInt8"
- }
- column "os_user" {
- type = "String"
- }
- column "client_hostname" {
- type = "String"
- }
- column "client_name" {
- type = "String"
- }
- column "client_revision" {
- type = "UInt64"
- }
- column "client_version_major" {
- type = "UInt64"
- }
- column "client_version_minor" {
- type = "UInt64"
- }
- column "client_version_patch" {
- type = "UInt64"
- }
- column "http_method" {
- type = "UInt8"
- }
- column "http_user_agent" {
- type = "String"
- }
- column "http_referer" {
- type = "String"
- }
- column "forwarded_for" {
- type = "String"
- }
- column "quota_key" {
- type = "String"
- }
- column "distributed_depth" {
- type = "UInt64"
- }
- column "elapsed" {
- type = "Float64"
- }
- column "is_cancelled" {
- type = "UInt8"
- }
- column "is_all_data_sent" {
- type = "UInt8"
- }
- column "read_rows" {
- type = "UInt64"
- }
- column "read_bytes" {
- type = "UInt64"
- }
- column "total_rows_approx" {
- type = "UInt64"
- }
- column "written_rows" {
- type = "UInt64"
- }
- column "written_bytes" {
- type = "UInt64"
- }
- column "memory_usage" {
- type = "Int64"
- }
- column "peak_memory_usage" {
- type = "Int64"
- }
- column "query" {
- type = "String"
- }
- column "query_kind" {
- type = "String"
- }
- column "thread_ids" {
- type = "Array(UInt64)"
- }
- column "ProfileEvents" {
- type = "Map(String, UInt64)"
- }
- column "Settings" {
- type = "Map(String, String)"
- }
- column "current_database" {
- type = "String"
- }
- column "ProfileEvents.Names" {
- type = "Array(String)"
- alias = "mapKeys(ProfileEvents)"
- }
- column "ProfileEvents.Values" {
- type = "Array(UInt64)"
- alias = "mapValues(ProfileEvents)"
- }
- column "Settings.Names" {
- type = "Array(String)"
- alias = "mapKeys(Settings)"
- }
- column "Settings.Values" {
- type = "Array(String)"
- alias = "mapValues(Settings)"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "system"
- remote_table = "processes"
- }
- }
-
table "events_dead_letter_queue" {
override = true
order_by = ["id", "event_uuid", "distinct_id", "team_id"]
@@ -601,74 +179,10 @@ database "posthog" {
}
}
- table "groups" {
- override = true
- order_by = ["team_id", "group_type_index", "group_key"]
- settings = {
- index_granularity = "8192"
- }
- column "group_type_index" {
- type = "UInt8"
- }
- column "group_key" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(3)"
- }
- column "team_id" {
- type = "Int64"
- }
- column "group_properties" {
- type = "String"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "is_deleted" {
- type = "Bool"
- }
- index "is_deleted_idx" {
- expr = "is_deleted"
- type = "minmax"
- granularity = 1
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.groups"
- replica_name = "{replica}-{shard}"
- version_column = "_timestamp"
- }
- }
-
- table "ingestion_warnings" {
- override = true
- column "team_id" {
- type = "Int64"
- }
- column "source" {
- type = "LowCardinality(String)"
- }
- column "type" {
+ patch_table "ingestion_warnings" {
+ modify_column "details" {
type = "String"
}
- column "details" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
engine "distributed" {
cluster_name = "aux"
remote_database = "posthog"
@@ -734,94 +248,7 @@ database "posthog" {
type = "Int8"
}
column "version" {
- type = "Int64"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- index "kafka_timestamp_minmax_person_distinct_id_overrides" {
- expr = "_timestamp"
- type = "minmax"
- granularity = 3
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id_overrides"
- replica_name = "{replica}-{shard}"
- version_column = "version"
- }
- }
-
- table "person_static_cohort" {
- override = true
- order_by = ["team_id", "cohort_id", "person_id", "id"]
- settings = {
- index_granularity = "8192"
- }
- column "id" {
- type = "UUID"
- }
- column "person_id" {
- type = "UUID"
- }
- column "cohort_id" {
- type = "Int64"
- }
- column "team_id" {
- type = "Int64"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.person_static_cohort"
- replica_name = "{replica}-{shard}"
- version_column = "_timestamp"
- }
- }
-
- table "plugin_log_entries" {
- override = true
- order_by = ["team_id", "id"]
- partition_by = "plugin_id"
- ttl = "toDate(timestamp) + toIntervalWeek(1)"
- settings = {
- index_granularity = "512"
- }
- column "id" {
- type = "UUID"
- }
- column "team_id" {
- type = "Int64"
- }
- column "plugin_id" {
- type = "Int64"
- }
- column "plugin_config_id" {
- type = "Int64"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "source" {
- type = "String"
- }
- column "type" {
- type = "String"
- }
- column "message" {
- type = "String"
- }
- column "instance_id" {
- type = "UUID"
+ type = "Int64"
}
column "_timestamp" {
type = "DateTime"
@@ -829,52 +256,56 @@ database "posthog" {
column "_offset" {
type = "UInt64"
}
+ column "_partition" {
+ type = "UInt64"
+ }
+ index "kafka_timestamp_minmax_person_distinct_id_overrides" {
+ expr = "_timestamp"
+ type = "minmax"
+ granularity = 3
+ }
engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.plugin_log_entries"
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_distinct_id_overrides"
replica_name = "{replica}-{shard}"
- version_column = "_timestamp"
+ version_column = "version"
}
}
- table "property_definitions" {
+ table "person_static_cohort" {
override = true
- order_by = ["team_id", "type", "coalesce(event, '')", "name", "coalesce(group_type_index, 255)"]
+ order_by = ["team_id", "cohort_id", "person_id", "id"]
settings = {
index_granularity = "8192"
}
- column "team_id" {
- type = "UInt32"
- }
- column "project_id" {
- type = "Nullable(UInt32)"
- }
- column "name" {
- type = "String"
- }
- column "property_type" {
- type = "Nullable(String)"
+ column "id" {
+ type = "UUID"
}
- column "event" {
- type = "Nullable(String)"
+ column "person_id" {
+ type = "UUID"
}
- column "group_type_index" {
- type = "Nullable(UInt8)"
+ column "cohort_id" {
+ type = "Int64"
}
- column "type" {
- type = "UInt8"
- default = "1"
+ column "team_id" {
+ type = "Int64"
}
- column "last_seen_at" {
+ column "_timestamp" {
type = "DateTime"
}
- column "version" {
- type = "UInt64"
- materialized = "bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))"
+ column "_offset" {
+ type = "UInt64"
}
engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.property_definitions"
+ zoo_path = "/clickhouse/tables/noshard/posthog.person_static_cohort"
replica_name = "{replica}-{shard}"
- version_column = "version"
+ version_column = "_timestamp"
+ }
+ }
+
+ patch_table "property_definitions" {
+ modify_column "version" {
+ type = "UInt64"
+ materialized = "bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))"
}
}
@@ -1030,246 +461,6 @@ database "posthog" {
}
}
- table "session_replay_events" {
- override = true
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "min_first_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_last_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "first_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "click_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "keypress_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "mouse_activity_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "active_milliseconds" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_log_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_warn_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_error_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "size" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "message_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "event_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
- column "snapshot_source" {
- type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
- }
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "snapshot_library" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
- }
- column "is_deleted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "ai_tags_fixed" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_tags_freeform" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_highlighted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "surfacing_score" {
- type = "SimpleAggregateFunction(max, Nullable(Float32))"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_session_replay_events"
- sharding_key = "sipHash64(distinct_id)"
- }
- }
-
- table "sharded_session_replay_events" {
- override = true
- order_by = ["toDate(min_first_timestamp)", "team_id", "session_id"]
- partition_by = "toYYYYMM(min_first_timestamp)"
- settings = {
- index_granularity = "512"
- }
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "min_first_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_last_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "first_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "click_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "keypress_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "mouse_activity_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "active_milliseconds" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_log_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_warn_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_error_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "size" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "message_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "event_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
- column "snapshot_source" {
- type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
- }
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "snapshot_library" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
- }
- column "is_deleted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "ai_tags_fixed" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_tags_freeform" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_highlighted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "surfacing_score" {
- type = "SimpleAggregateFunction(max, Nullable(Float32))"
- }
- engine "replicated_aggregating_merge_tree" {
- zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
- replica_name = "{replica}"
- }
- }
-
- table "tophog" {
- override = true
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "metric" {
- type = "LowCardinality(String)"
- }
- column "type" {
- type = "LowCardinality(String)"
- default = "'sum'"
- }
- column "key" {
- type = "Map(LowCardinality(String), String)"
- }
- column "value" {
- type = "Float64"
- }
- column "count" {
- type = "UInt64"
- default = "0"
- }
- column "pipeline" {
- type = "LowCardinality(String)"
- }
- column "lane" {
- type = "LowCardinality(String)"
- }
- column "labels" {
- type = "Map(LowCardinality(String), String)"
- }
- engine "distributed" {
- cluster_name = "ops"
- remote_database = "posthog"
- remote_table = "sharded_tophog"
- sharding_key = "cityHash64(toString(key))"
- }
- }
-
table "web_pre_aggregated_bounces" {
override = true
order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
@@ -2043,132 +1234,6 @@ database "posthog" {
}
}
- materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
- override = true
- to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
- query = <<SQL
-SELECT
- team_id,
- product,
- document_type,
- rendering,
- document_id,
- timestamp,
- inserted_at,
- content,
- metadata,
- embedding,
- _timestamp,
- _offset,
- _partition
-FROM posthog.sharded_posthog_document_embeddings_buffer
-WHERE model_name = 'text-embedding-3-large-3072'
-SQL
-
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- }
- column "metadata" {
- type = "String"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- }
-
- materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
- override = true
- to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
- query = <<SQL
-SELECT
- team_id,
- product,
- document_type,
- rendering,
- document_id,
- timestamp,
- inserted_at,
- content,
- metadata,
- embedding,
- _timestamp,
- _offset,
- _partition
-FROM posthog.sharded_posthog_document_embeddings_buffer
-WHERE model_name = 'text-embedding-3-small-1536'
-SQL
-
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- }
- column "metadata" {
- type = "String"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- }
-
patch_table "raw_sessions" {
drop_columns = ["initial_epik", "initial_qclid", "initial_sccid"]
}
diff --git a/posthog/clickhouse/hcl/roles/data/dev/tables.hcl b/posthog/clickhouse/hcl/roles/data/dev/tables.hcl
index e4f15e6145bb..7d5a6ecfe1cf 100644
--- a/posthog/clickhouse/hcl/roles/data/dev/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/data/dev/tables.hcl
@@ -507,78 +507,6 @@ database "posthog" {
}
}
- table "session_recording_events" {
- override = true
- column "uuid" {
- type = "UUID"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "session_id" {
- type = "String"
- }
- column "window_id" {
- type = "String"
- }
- column "snapshot_data" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- }
- column "has_full_snapshot" {
- type = "Int8"
- comment = "column_materializer::has_full_snapshot"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "events_summary" {
- type = "Array(String)"
- comment = "column_materializer::events_summary"
- }
- column "click_count" {
- type = "Int8"
- comment = "column_materializer::click_count"
- }
- column "keypress_count" {
- type = "Int8"
- comment = "column_materializer::keypress_count"
- }
- column "timestamps_summary" {
- type = "Array(DateTime64(6, 'UTC'))"
- comment = "column_materializer::timestamps_summary"
- }
- column "first_event_timestamp" {
- type = "DateTime64(6, 'UTC')"
- comment = "column_materializer::first_event_timestamp"
- }
- column "last_event_timestamp" {
- type = "DateTime64(6, 'UTC')"
- comment = "column_materializer::last_event_timestamp"
- }
- column "urls" {
- type = "Array(String)"
- comment = "column_materializer::urls"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_session_recording_events"
- sharding_key = "sipHash64(distinct_id)"
- }
- }
-
table "sharded_app_metrics" {
override = true
order_by = ["team_id", "plugin_config_id", "job_id", "category", "toStartOfHour(timestamp)", "error_type", "error_uuid"]
@@ -1891,183 +1819,6 @@ database "posthog" {
}
}
- table "billing_usage_records" {
- override = true
- column "schema_version" {
- type = "UInt8"
- }
- column "record_id" {
- type = "String"
- }
- column "producer_id" {
- type = "LowCardinality(String)"
- }
- column "team_id" {
- type = "Int64"
- }
- column "organization_id" {
- type = "UUID"
- }
- column "usage_key" {
- type = "LowCardinality(String)"
- }
- column "unit" {
- type = "LowCardinality(String)"
- }
- column "quantity" {
- type = "Int64"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(6, 'UTC')"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_billing_usage_records"
- sharding_key = "cityHash64(team_id)"
- }
- }
-
- table "clickhouse_cleanup_deleted_persons" {
- override = true
- order_by = ["run_id", "team_id", "person_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "person_id" {
- type = "UUID"
- }
- column "max_version" {
- type = "UInt64"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_orphaned_distinct_ids" {
- override = true
- order_by = ["run_id", "team_id", "distinct_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "own_tombstone" {
- type = "UInt8"
- }
- column "max_version" {
- type = "Int64"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_revived_distinct_ids" {
- override = true
- order_by = ["run_id", "team_id", "distinct_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_revived_persons" {
- override = true
- order_by = ["run_id", "team_id", "person_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "person_id" {
- type = "UUID"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
table "distributed_events_recent" {
override = true
column "uuid" {
@@ -2434,60 +2185,40 @@ SQL
}
- table "events_dead_letter_queue" {
+ table "plugin_log_entries" {
override = true
- order_by = ["id", "event_uuid", "distinct_id", "team_id"]
- ttl = "toDate(_timestamp) + toIntervalWeek(4)"
+ order_by = ["team_id", "id"]
+ partition_by = "plugin_id"
+ ttl = "toDate(timestamp) + toIntervalWeek(1)"
settings = {
index_granularity = "512"
}
column "id" {
type = "UUID"
}
- column "event_uuid" {
- type = "UUID"
- }
- column "event" {
- type = "String"
- }
- column "properties" {
- type = "String"
- }
- column "distinct_id" {
- type = "String"
- }
column "team_id" {
type = "Int64"
}
- column "elements_chain" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- }
- column "ip" {
- type = "String"
+ column "plugin_id" {
+ type = "Int64"
}
- column "site_url" {
- type = "String"
+ column "plugin_config_id" {
+ type = "Int64"
}
- column "now" {
+ column "timestamp" {
type = "DateTime64(6, 'UTC')"
}
- column "raw_payload" {
+ column "source" {
type = "String"
}
- column "error_timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "error_location" {
+ column "type" {
type = "String"
}
- column "error" {
+ column "message" {
type = "String"
}
- column "tags" {
- type = "Array(String)"
+ column "instance_id" {
+ type = "UUID"
}
column "_timestamp" {
type = "DateTime"
@@ -2496,1346 +2227,114 @@ SQL
type = "UInt64"
}
engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.events_dead_letter_queue"
+ zoo_path = "/clickhouse/tables/noshard/posthog.plugin_log_entries"
replica_name = "{replica}-{shard}"
version_column = "_timestamp"
}
}
- table "groups" {
- override = true
- order_by = ["team_id", "group_type_index", "group_key"]
- settings = {
- index_granularity = "8192"
- }
- column "group_type_index" {
- type = "UInt8"
- }
- column "group_key" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(3)"
- }
- column "team_id" {
- type = "Int64"
- }
- column "group_properties" {
- type = "String"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "is_deleted" {
- type = "Bool"
- }
- index "is_deleted_idx" {
- expr = "is_deleted"
- type = "minmax"
- granularity = 1
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.groups"
- replica_name = "{replica}-{shard}"
- version_column = "_timestamp"
- }
- }
-
- table "ingestion_warnings" {
- override = true
- column "team_id" {
- type = "Int64"
- }
- column "source" {
- type = "LowCardinality(String)"
- }
- column "type" {
- type = "String"
- }
- column "details" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- engine "distributed" {
- cluster_name = "aux"
- remote_database = "posthog"
- remote_table = "sharded_ingestion_warnings"
- sharding_key = "rand()"
- }
- }
-
- view "persons_batch_export" {
+ view "raw_sessions_v3_v" {
override = true
query = <<SQL
-WITH
- new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
- new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
- all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
SELECT
- p.team_id AS team_id,
- pd.distinct_id AS distinct_id,
- toString(p.id) AS person_id,
- p.properties AS properties,
- pd.version AS person_distinct_id_version,
- p.version AS person_version,
- p.created_at AS created_at,
- multiIf(
- ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
- AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
- pd._timestamp,
- ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
- AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
- p._timestamp,
- least(p._timestamp, pd._timestamp)
- ) AS _inserted_at
-FROM
- posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
-WHERE
- (team_id = {team_id: Int64})
-AND
- ((id, version) IN (all_new_persons))
-ORDER BY _inserted_at ASC
+ session_id_v7,
+ session_timestamp,
+ team_id,
+ argMaxMerge(distinct_id) AS distinct_id,
+ argMaxMerge(person_id) AS person_id,
+ groupUniqArrayMerge(distinct_ids) AS distinct_ids,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ max(max_inserted_at) AS max_inserted_at,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(end_url) AS end_url,
+ argMaxMerge(last_external_click_url) AS last_external_click_url,
+ argMinMerge(browser) AS browser,
+ argMinMerge(browser_version) AS browser_version,
+ argMinMerge(os) AS os,
+ argMinMerge(os_version) AS os_version,
+ argMinMerge(device_type) AS device_type,
+ argMinMerge(viewport_width) AS viewport_width,
+ argMinMerge(viewport_height) AS viewport_height,
+ argMinMerge(geoip_country_code) AS geoip_country_code,
+ argMinMerge(geoip_subdivision_1_code) AS geoip_subdivision_1_code,
+ argMinMerge(geoip_subdivision_1_name) AS geoip_subdivision_1_name,
+ argMinMerge(geoip_subdivision_city_name) AS geoip_subdivision_city_name,
+ argMinMerge(geoip_time_zone) AS geoip_time_zone,
+ argMinMerge(entry_utm_source) AS entry_utm_source,
+ argMinMerge(entry_utm_campaign) AS entry_utm_campaign,
+ argMinMerge(entry_utm_medium) AS entry_utm_medium,
+ argMinMerge(entry_utm_term) AS entry_utm_term,
+ argMinMerge(entry_utm_content) AS entry_utm_content,
+ argMinMerge(entry_referring_domain) AS entry_referring_domain,
+ argMinMerge(entry_gclid) AS entry_gclid,
+ argMinMerge(entry_gad_source) AS entry_gad_source,
+ argMinMerge(entry_fbclid) AS entry_fbclid,
+ argMinMerge(entry_has_gclid) AS entry_has_gclid,
+ argMinMerge(entry_has_fbclid) AS entry_has_fbclid,
+ argMinMerge(entry_ad_ids_map) AS entry_ad_ids_map,
+ argMinMerge(entry_ad_ids_set) AS entry_ad_ids_set,
+ argMinMerge(entry_channel_type_properties) AS entry_channel_type_properties,
+ uniqExactMerge(pageview_uniq) AS pageview_uniq,
+ uniqExactMerge(autocapture_uniq) AS autocapture_uniq,
+ uniqExactMerge(screen_uniq) AS screen_uniq,
+ uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,
+ groupUniqArrayMapMerge(flag_values) AS flag_values
+FROM posthog.raw_sessions_v3
+GROUP BY
+ session_id_v7, session_timestamp, team_id
SQL
}
- table "plugin_log_entries" {
- override = true
- order_by = ["team_id", "id"]
- partition_by = "plugin_id"
- ttl = "toDate(timestamp) + toIntervalWeek(1)"
- settings = {
- index_granularity = "512"
- }
- column "id" {
- type = "UUID"
- }
- column "team_id" {
- type = "Int64"
- }
- column "plugin_id" {
- type = "Int64"
- }
- column "plugin_config_id" {
- type = "Int64"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "source" {
- type = "String"
- }
- column "type" {
- type = "String"
- }
- column "message" {
- type = "String"
- }
- column "instance_id" {
- type = "UUID"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.plugin_log_entries"
- replica_name = "{replica}-{shard}"
- version_column = "_timestamp"
- }
- }
-
- materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
+ view "sessions_v" {
override = true
- to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
- query = <<SQL
+ query = <<SQL
SELECT
+ session_id,
team_id,
- product,
- document_type,
- rendering,
- document_id,
- timestamp,
- inserted_at,
- content,
- metadata,
- embedding,
- _timestamp,
- _offset,
- _partition
-FROM posthog.sharded_posthog_document_embeddings_buffer
-WHERE model_name = 'text-embedding-3-large-3072'
+ any(distinct_id) AS distinct_id,
+ min(min_timestamp) AS min_timestamp,
+ max(max_timestamp) AS max_timestamp,
+ arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
+ argMinMerge(entry_url) AS entry_url,
+ argMaxMerge(exit_url) AS exit_url,
+ argMinMerge(initial_utm_source) AS initial_utm_source,
+ argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
+ argMinMerge(initial_utm_medium) AS initial_utm_medium,
+ argMinMerge(initial_utm_term) AS initial_utm_term,
+ argMinMerge(initial_utm_content) AS initial_utm_content,
+ argMinMerge(initial_referring_domain) AS initial_referring_domain,
+ argMinMerge(initial_gclid) AS initial_gclid,
+ argMinMerge(initial_gad_source) AS initial_gad_source,
+ argMinMerge(initial_gclsrc) AS initial_gclsrc,
+ argMinMerge(initial_dclid) AS initial_dclid,
+ argMinMerge(initial_gbraid) AS initial_gbraid,
+ argMinMerge(initial_wbraid) AS initial_wbraid,
+ argMinMerge(initial_fbclid) AS initial_fbclid,
+ argMinMerge(initial_msclkid) AS initial_msclkid,
+ argMinMerge(initial_twclid) AS initial_twclid,
+ argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
+ argMinMerge(initial_mc_cid) AS initial_mc_cid,
+ argMinMerge(initial_igshid) AS initial_igshid,
+ argMinMerge(initial_ttclid) AS initial_ttclid,
+ sumMap(event_count_map) AS event_count_map,
+ sum(pageview_count) AS pageview_count,
+ sum(autocapture_count) AS autocapture_count
+FROM posthog.sessions
+GROUP BY
+ session_id, team_id
SQL
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- }
- column "metadata" {
- type = "String"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
}
- materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
- override = true
- to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
- query = <<SQL
-SELECT
- team_id,
- product,
- document_type,
- rendering,
- document_id,
- timestamp,
- inserted_at,
- content,
- metadata,
- embedding,
- _timestamp,
- _offset,
- _partition
-FROM posthog.sharded_posthog_document_embeddings_buffer
-WHERE model_name = 'text-embedding-3-small-1536'
-SQL
-
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- }
- column "metadata" {
- type = "String"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- }
-
- table "property_definitions" {
- override = true
- order_by = ["team_id", "type", "coalesce(event, '')", "name", "coalesce(group_type_index, 255)"]
- settings = {
- index_granularity = "8192"
- }
- column "team_id" {
- type = "UInt32"
- }
- column "project_id" {
- type = "Nullable(UInt32)"
- }
- column "name" {
- type = "String"
- }
- column "property_type" {
- type = "Nullable(String)"
- }
- column "event" {
- type = "Nullable(String)"
- }
- column "group_type_index" {
- type = "Nullable(UInt8)"
- }
- column "type" {
- type = "UInt8"
- default = "1"
- }
- column "last_seen_at" {
- type = "DateTime"
- }
- column "version" {
- type = "UInt64"
- materialized = "bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.property_definitions"
- replica_name = "{replica}-{shard}"
- version_column = "version"
- }
- }
-
- table "raw_sessions_v3" {
- override = true
- column "team_id" {
- type = "Int64"
- }
- column "session_id_v7" {
- type = "UInt128"
- }
- column "session_timestamp" {
- type = "DateTime64(3)"
- materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
- }
- column "distinct_id" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "distinct_ids" {
- type = "AggregateFunction(groupUniqArray, String)"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "max_inserted_at" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "end_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "last_external_click_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "browser" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "browser_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "os" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "os_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "device_type" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "viewport_width" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
- }
- column "viewport_height" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
- }
- column "geoip_country_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_1_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_1_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_city_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_time_zone" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_referring_domain" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_campaign" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_medium" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_term" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_content" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_gclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_gad_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_fbclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_has_gclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
- }
- column "entry_has_fbclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
- }
- column "entry_ad_ids_map" {
- type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
- }
- column "entry_ad_ids_set" {
- type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
- }
- column "entry_channel_type_properties" {
- type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
- }
- column "pageview_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "autocapture_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "screen_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "page_screen_uniq_up_to" {
- type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
- }
- column "has_autocapture" {
- type = "SimpleAggregateFunction(max, Bool)"
- }
- column "flag_values" {
- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
- }
- column "flag_keys" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "event_names" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "has_replay_events" {
- type = "SimpleAggregateFunction(max, Bool)"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_raw_sessions_v3"
- sharding_key = "cityHash64(session_id_v7)"
- }
- }
-
- view "raw_sessions_v3_v" {
- override = true
- query = <<SQL
-SELECT
- session_id_v7,
- session_timestamp,
- team_id,
- argMaxMerge(distinct_id) AS distinct_id,
- argMaxMerge(person_id) AS person_id,
- groupUniqArrayMerge(distinct_ids) AS distinct_ids,
- min(min_timestamp) AS min_timestamp,
- max(max_timestamp) AS max_timestamp,
- max(max_inserted_at) AS max_inserted_at,
- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
- argMinMerge(entry_url) AS entry_url,
- argMaxMerge(end_url) AS end_url,
- argMaxMerge(last_external_click_url) AS last_external_click_url,
- argMinMerge(browser) AS browser,
- argMinMerge(browser_version) AS browser_version,
- argMinMerge(os) AS os,
- argMinMerge(os_version) AS os_version,
- argMinMerge(device_type) AS device_type,
- argMinMerge(viewport_width) AS viewport_width,
- argMinMerge(viewport_height) AS viewport_height,
- argMinMerge(geoip_country_code) AS geoip_country_code,
- argMinMerge(geoip_subdivision_1_code) AS geoip_subdivision_1_code,
- argMinMerge(geoip_subdivision_1_name) AS geoip_subdivision_1_name,
- argMinMerge(geoip_subdivision_city_name) AS geoip_subdivision_city_name,
- argMinMerge(geoip_time_zone) AS geoip_time_zone,
- argMinMerge(entry_utm_source) AS entry_utm_source,
- argMinMerge(entry_utm_campaign) AS entry_utm_campaign,
- argMinMerge(entry_utm_medium) AS entry_utm_medium,
- argMinMerge(entry_utm_term) AS entry_utm_term,
- argMinMerge(entry_utm_content) AS entry_utm_content,
- argMinMerge(entry_referring_domain) AS entry_referring_domain,
- argMinMerge(entry_gclid) AS entry_gclid,
- argMinMerge(entry_gad_source) AS entry_gad_source,
- argMinMerge(entry_fbclid) AS entry_fbclid,
- argMinMerge(entry_has_gclid) AS entry_has_gclid,
- argMinMerge(entry_has_fbclid) AS entry_has_fbclid,
- argMinMerge(entry_ad_ids_map) AS entry_ad_ids_map,
- argMinMerge(entry_ad_ids_set) AS entry_ad_ids_set,
- argMinMerge(entry_channel_type_properties) AS entry_channel_type_properties,
- uniqExactMerge(pageview_uniq) AS pageview_uniq,
- uniqExactMerge(autocapture_uniq) AS autocapture_uniq,
- uniqExactMerge(screen_uniq) AS screen_uniq,
- uniqUpToMerge(1)(page_screen_autocapture_uniq_up_to) AS page_screen_autocapture_uniq_up_to,
- groupUniqArrayMapMerge(flag_values) AS flag_values
-FROM posthog.raw_sessions_v3
-GROUP BY
- session_id_v7, session_timestamp, team_id
-SQL
-
- }
-
- table "session_replay_events" {
- override = true
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "min_first_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_last_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "first_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "click_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "keypress_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "mouse_activity_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "active_milliseconds" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_log_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_warn_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_error_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "size" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "message_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "event_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
- column "snapshot_source" {
- type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
- }
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "snapshot_library" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
- }
- column "is_deleted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "ai_tags_fixed" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_tags_freeform" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_highlighted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "surfacing_score" {
- type = "SimpleAggregateFunction(max, Nullable(Float32))"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_session_replay_events"
- sharding_key = "sipHash64(distinct_id)"
- }
- }
-
- view "sessions_v" {
- override = true
- query = <<SQL
-SELECT
- session_id,
- team_id,
- any(distinct_id) AS distinct_id,
- min(min_timestamp) AS min_timestamp,
- max(max_timestamp) AS max_timestamp,
- arrayDistinct(arrayFlatten(groupArray(urls))) AS urls,
- argMinMerge(entry_url) AS entry_url,
- argMaxMerge(exit_url) AS exit_url,
- argMinMerge(initial_utm_source) AS initial_utm_source,
- argMinMerge(initial_utm_campaign) AS initial_utm_campaign,
- argMinMerge(initial_utm_medium) AS initial_utm_medium,
- argMinMerge(initial_utm_term) AS initial_utm_term,
- argMinMerge(initial_utm_content) AS initial_utm_content,
- argMinMerge(initial_referring_domain) AS initial_referring_domain,
- argMinMerge(initial_gclid) AS initial_gclid,
- argMinMerge(initial_gad_source) AS initial_gad_source,
- argMinMerge(initial_gclsrc) AS initial_gclsrc,
- argMinMerge(initial_dclid) AS initial_dclid,
- argMinMerge(initial_gbraid) AS initial_gbraid,
- argMinMerge(initial_wbraid) AS initial_wbraid,
- argMinMerge(initial_fbclid) AS initial_fbclid,
- argMinMerge(initial_msclkid) AS initial_msclkid,
- argMinMerge(initial_twclid) AS initial_twclid,
- argMinMerge(initial_li_fat_id) AS initial_li_fat_id,
- argMinMerge(initial_mc_cid) AS initial_mc_cid,
- argMinMerge(initial_igshid) AS initial_igshid,
- argMinMerge(initial_ttclid) AS initial_ttclid,
- sumMap(event_count_map) AS event_count_map,
- sum(pageview_count) AS pageview_count,
- sum(autocapture_count) AS autocapture_count
-FROM posthog.sessions
-GROUP BY
- session_id, team_id
-SQL
-
- }
-
- table "tophog" {
- override = true
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "metric" {
- type = "LowCardinality(String)"
- }
- column "type" {
- type = "LowCardinality(String)"
- default = "'sum'"
- }
- column "key" {
- type = "Map(LowCardinality(String), String)"
- }
- column "value" {
- type = "Float64"
- }
- column "count" {
- type = "UInt64"
- default = "0"
- }
- column "pipeline" {
- type = "LowCardinality(String)"
- }
- column "lane" {
- type = "LowCardinality(String)"
- }
- column "labels" {
- type = "Map(LowCardinality(String), String)"
- }
- engine "distributed" {
- cluster_name = "ops"
- remote_database = "posthog"
- remote_table = "sharded_tophog"
- sharding_key = "cityHash64(toString(key))"
- }
- }
-
- table "web_pre_aggregated_bounces" {
- override = true
- order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
- partition_by = "toYYYYMMDD(period_bucket)"
- settings = {
- index_granularity = "8192"
- }
- column "period_bucket" {
- type = "DateTime"
- }
- column "team_id" {
- type = "UInt64"
- }
- column "host" {
- type = "String"
- }
- column "device_type" {
- type = "String"
- }
- column "entry_pathname" {
- type = "String"
- }
- column "end_pathname" {
- type = "String"
- }
- column "browser" {
- type = "String"
- }
- column "os" {
- type = "String"
- }
- column "viewport_width" {
- type = "Int64"
- }
- column "viewport_height" {
- type = "Int64"
- }
- column "referring_domain" {
- type = "String"
- }
- column "utm_source" {
- type = "String"
- }
- column "utm_medium" {
- type = "String"
- }
- column "utm_campaign" {
- type = "String"
- }
- column "utm_term" {
- type = "String"
- }
- column "utm_content" {
- type = "String"
- }
- column "country_code" {
- type = "String"
- }
- column "city_name" {
- type = "String"
- }
- column "region_code" {
- type = "String"
- }
- column "region_name" {
- type = "String"
- }
- column "has_gclid" {
- type = "Bool"
- }
- column "has_gad_source_paid_search" {
- type = "Bool"
- }
- column "has_fbclid" {
- type = "Bool"
- }
- column "mat_metadata_backend" {
- type = "Nullable(String)"
- }
- column "persons_uniq_state" {
- type = "AggregateFunction(uniq, UUID)"
- }
- column "sessions_uniq_state" {
- type = "AggregateFunction(uniq, String)"
- }
- column "pageviews_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "bounces_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "total_session_duration_state" {
- type = "AggregateFunction(sum, Int64)"
- }
- column "total_session_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "mat_metadata_loggedIn" {
- type = "Nullable(Bool)"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces"
- replica_name = "{replica}-{shard}"
- }
- }
-
- table "web_pre_aggregated_stats" {
- override = true
- order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
- partition_by = "toYYYYMMDD(period_bucket)"
- settings = {
- index_granularity = "8192"
- }
- column "period_bucket" {
- type = "DateTime"
- }
- column "team_id" {
- type = "UInt64"
- }
- column "host" {
- type = "String"
- }
- column "device_type" {
- type = "String"
- }
- column "pathname" {
- type = "String"
- }
- column "entry_pathname" {
- type = "String"
- }
- column "end_pathname" {
- type = "String"
- }
- column "browser" {
- type = "String"
- }
- column "os" {
- type = "String"
- }
- column "viewport_width" {
- type = "Int64"
- }
- column "viewport_height" {
- type = "Int64"
- }
- column "referring_domain" {
- type = "String"
- }
- column "utm_source" {
- type = "String"
- }
- column "utm_medium" {
- type = "String"
- }
- column "utm_campaign" {
- type = "String"
- }
- column "utm_term" {
- type = "String"
- }
- column "utm_content" {
- type = "String"
- }
- column "country_code" {
- type = "String"
- }
- column "city_name" {
- type = "String"
- }
- column "region_code" {
- type = "String"
- }
- column "region_name" {
- type = "String"
- }
- column "has_gclid" {
- type = "Bool"
- }
- column "has_gad_source_paid_search" {
- type = "Bool"
- }
- column "has_fbclid" {
- type = "Bool"
- }
- column "mat_metadata_backend" {
- type = "Nullable(String)"
- }
- column "persons_uniq_state" {
- type = "AggregateFunction(uniq, UUID)"
- }
- column "sessions_uniq_state" {
- type = "AggregateFunction(uniq, String)"
- }
- column "pageviews_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "mat_metadata_loggedIn" {
- type = "Nullable(Bool)"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats"
- replica_name = "{replica}-{shard}"
- }
- }
-
- table "writable_raw_sessions" {
- override = true
- column "team_id" {
- type = "Int64"
- }
- column "session_id_v7" {
- type = "UInt128"
- }
- column "distinct_id" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "max_inserted_at" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "end_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "last_external_click_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "initial_browser" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_browser_version" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_os" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_os_version" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_device_type" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_viewport_width" {
- type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
- }
- column "initial_viewport_height" {
- type = "AggregateFunction(argMin, Int64, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_country_code" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_1_code" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_1_name" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_subdivision_city_name" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_geoip_time_zone" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_referring_domain" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_campaign" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_medium" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_term" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_content" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gad_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclsrc" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_dclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_wbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_fbclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_msclkid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_twclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_li_fat_id" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_mc_cid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_igshid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_ttclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_irclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "pageview_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "pageview_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "autocapture_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "autocapture_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "screen_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "screen_uniq" {
- type = "AggregateFunction(uniq, Nullable(UUID))"
- }
- column "maybe_has_session_replay" {
- type = "SimpleAggregateFunction(max, Bool)"
- }
- column "page_screen_autocapture_uniq_up_to" {
- type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
- }
- column "vitals_lcp" {
- type = "AggregateFunction(argMin, Nullable(Float64), DateTime64(6, 'UTC'))"
- }
- column "initial__kx" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_raw_sessions"
- sharding_key = "cityHash64(session_id_v7)"
- }
- }
-
- table "writable_raw_sessions_v3" {
- override = true
- column "team_id" {
- type = "Int64"
- }
- column "session_id_v7" {
- type = "UInt128"
- }
- column "session_timestamp" {
- type = "DateTime64(3)"
- materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
- }
- column "distinct_id" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "distinct_ids" {
- type = "AggregateFunction(groupUniqArray, String)"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "max_inserted_at" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "end_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "last_external_click_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "browser" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "browser_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "os" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "os_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "device_type" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "viewport_width" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
- }
- column "viewport_height" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
- }
- column "geoip_country_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_1_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_1_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_city_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_time_zone" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_referring_domain" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_campaign" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_medium" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_term" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_content" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_gclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_gad_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_fbclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_has_gclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
- }
- column "entry_has_fbclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
- }
- column "entry_ad_ids_map" {
- type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
- }
- column "entry_ad_ids_set" {
- type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
- }
- column "entry_channel_type_properties" {
- type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
- }
- column "pageview_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "autocapture_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "screen_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "page_screen_uniq_up_to" {
- type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
- }
- column "has_autocapture" {
- type = "SimpleAggregateFunction(max, Bool)"
- }
- column "flag_values" {
- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
- }
- column "flag_keys" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "event_names" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "has_replay_events" {
- type = "SimpleAggregateFunction(max, Bool)"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_raw_sessions_v3"
- sharding_key = "cityHash64(session_id_v7)"
- }
- }
-
- table "writable_sessions" {
- override = true
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "SimpleAggregateFunction(any, String)"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "exit_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "initial_referring_domain" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_campaign" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_medium" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_term" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_content" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gad_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclsrc" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_dclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_wbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_fbclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_msclkid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_twclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_li_fat_id" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_mc_cid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_igshid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_ttclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "event_count_map" {
- type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
- }
- column "pageview_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "autocapture_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
+ patch_table "tophog" {
engine "distributed" {
- cluster_name = "posthog"
+ cluster_name = "ops"
remote_database = "posthog"
- remote_table = "sharded_sessions"
- sharding_key = "sipHash64(session_id)"
+ remote_table = "sharded_tophog"
+ sharding_key = "cityHash64(toString(key))"
}
}
diff --git a/posthog/clickhouse/hcl/roles/data/prod-eu/tables.hcl b/posthog/clickhouse/hcl/roles/data/prod-eu/tables.hcl
index e70a51daef98..f2e5dc554cdc 100644
--- a/posthog/clickhouse/hcl/roles/data/prod-eu/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/data/prod-eu/tables.hcl
@@ -449,98 +449,7 @@ database "posthog" {
}
}
- table "new_writable_sessions" {
- override = true
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "SimpleAggregateFunction(any, String)"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "exit_url" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "initial_referring_domain" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_campaign" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_medium" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_term" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_utm_content" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gad_source" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gclsrc" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_dclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_gbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_wbraid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_fbclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_msclkid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_twclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_li_fat_id" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_mc_cid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_igshid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "initial_ttclid" {
- type = "AggregateFunction(argMin, String, DateTime64(6, 'UTC'))"
- }
- column "event_count_map" {
- type = "SimpleAggregateFunction(sumMap, Map(String, Int64))"
- }
- column "pageview_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "autocapture_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
+ patch_table "new_writable_sessions" {
engine "distributed" {
cluster_name = "posthog"
remote_database = "posthog"
@@ -666,78 +575,6 @@ database "posthog" {
}
}
- table "session_recording_events" {
- override = true
- column "uuid" {
- type = "UUID"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "session_id" {
- type = "String"
- }
- column "window_id" {
- type = "String"
- }
- column "snapshot_data" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- }
- column "has_full_snapshot" {
- type = "Int8"
- comment = "column_materializer::has_full_snapshot"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "events_summary" {
- type = "Array(String)"
- comment = "column_materializer::events_summary"
- }
- column "click_count" {
- type = "Int8"
- comment = "column_materializer::click_count"
- }
- column "keypress_count" {
- type = "Int8"
- comment = "column_materializer::keypress_count"
- }
- column "timestamps_summary" {
- type = "Array(DateTime64(6, 'UTC'))"
- comment = "column_materializer::timestamps_summary"
- }
- column "first_event_timestamp" {
- type = "DateTime64(6, 'UTC')"
- comment = "column_materializer::first_event_timestamp"
- }
- column "last_event_timestamp" {
- type = "DateTime64(6, 'UTC')"
- comment = "column_materializer::last_event_timestamp"
- }
- column "urls" {
- type = "Array(String)"
- comment = "column_materializer::urls"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_session_recording_events"
- sharding_key = "sipHash64(distinct_id)"
- }
- }
-
table "sharded_precalculated_person_properties" {
override = true
order_by = ["team_id", "condition", "distinct_id"]
@@ -2210,134 +2047,6 @@ SQL
}
- table "clickhouse_cleanup_deleted_persons" {
- override = true
- order_by = ["run_id", "team_id", "person_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "person_id" {
- type = "UUID"
- }
- column "max_version" {
- type = "UInt64"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_orphaned_distinct_ids" {
- override = true
- order_by = ["run_id", "team_id", "distinct_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "own_tombstone" {
- type = "UInt8"
- }
- column "max_version" {
- type = "Int64"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_revived_distinct_ids" {
- override = true
- order_by = ["run_id", "team_id", "distinct_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_revived_persons" {
- override = true
- order_by = ["run_id", "team_id", "person_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "person_id" {
- type = "UUID"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
table "distributed_events_recent" {
override = true
column "uuid" {
@@ -2632,320 +2341,7 @@ SQL
}
}
- table "events_dead_letter_queue" {
- override = true
- order_by = ["id", "event_uuid", "distinct_id", "team_id"]
- ttl = "toDate(_timestamp) + toIntervalWeek(4)"
- settings = {
- index_granularity = "512"
- }
- column "id" {
- type = "UUID"
- }
- column "event_uuid" {
- type = "UUID"
- }
- column "event" {
- type = "String"
- }
- column "properties" {
- type = "String"
- }
- column "distinct_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "elements_chain" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- }
- column "ip" {
- type = "String"
- }
- column "site_url" {
- type = "String"
- }
- column "now" {
- type = "DateTime64(6, 'UTC')"
- }
- column "raw_payload" {
- type = "String"
- }
- column "error_timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "error_location" {
- type = "String"
- }
- column "error" {
- type = "String"
- }
- column "tags" {
- type = "Array(String)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.events_dead_letter_queue"
- replica_name = "{replica}-{shard}"
- version_column = "_timestamp"
- }
- }
-
- table "groups" {
- override = true
- order_by = ["team_id", "group_type_index", "group_key"]
- settings = {
- index_granularity = "8192"
- }
- column "group_type_index" {
- type = "UInt8"
- }
- column "group_key" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(3)"
- }
- column "team_id" {
- type = "Int64"
- }
- column "group_properties" {
- type = "String"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "is_deleted" {
- type = "Bool"
- }
- index "is_deleted_idx" {
- expr = "is_deleted"
- type = "minmax"
- granularity = 1
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.groups"
- replica_name = "{replica}-{shard}"
- version_column = "_timestamp"
- }
- }
-
- view "persons_batch_export" {
- override = true
- query = <<SQL
-WITH
- new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
- new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
- all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
-SELECT
- p.team_id AS team_id,
- pd.distinct_id AS distinct_id,
- toString(p.id) AS person_id,
- p.properties AS properties,
- pd.version AS person_distinct_id_version,
- p.version AS person_version,
- p.created_at AS created_at,
- multiIf(
- ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
- AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
- pd._timestamp,
- ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
- AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
- p._timestamp,
- least(p._timestamp, pd._timestamp)
- ) AS _inserted_at
-FROM
- posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
-WHERE
- (team_id = {team_id: Int64})
-AND
- ((id, version) IN (all_new_persons))
-ORDER BY _inserted_at ASC
-SQL
-
- }
-
- materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
- override = true
- to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
- query = <<SQL
-SELECT
- team_id,
- product,
- document_type,
- rendering,
- document_id,
- timestamp,
- inserted_at,
- content,
- metadata,
- embedding,
- _timestamp,
- _offset,
- _partition
-FROM posthog.sharded_posthog_document_embeddings_buffer
-WHERE model_name = 'text-embedding-3-large-3072'
-SQL
-
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- }
- column "metadata" {
- type = "String"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- }
-
- materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
- override = true
- to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
- query = <<SQL
-SELECT
- team_id,
- product,
- document_type,
- rendering,
- document_id,
- timestamp,
- inserted_at,
- content,
- metadata,
- embedding,
- _timestamp,
- _offset,
- _partition
-FROM posthog.sharded_posthog_document_embeddings_buffer
-WHERE model_name = 'text-embedding-3-small-1536'
-SQL
-
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- }
- column "metadata" {
- type = "String"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- }
-
- table "property_definitions" {
- override = true
- order_by = ["team_id", "type", "coalesce(event, '')", "name", "coalesce(group_type_index, 255)"]
- settings = {
- index_granularity = "8192"
- }
- column "team_id" {
- type = "UInt32"
- }
- column "project_id" {
- type = "Nullable(UInt32)"
- }
- column "name" {
- type = "String"
- }
- column "property_type" {
- type = "Nullable(String)"
- }
- column "event" {
- type = "Nullable(String)"
- }
- column "group_type_index" {
- type = "Nullable(UInt8)"
- }
- column "type" {
- type = "UInt8"
- default = "1"
- }
- column "last_seen_at" {
- type = "DateTime"
- }
- column "version" {
- type = "UInt64"
- materialized = "bitShiftLeft(toUInt64(NOT (property_type IS NULL)), 48) + toUInt64(toUnixTimestamp(last_seen_at))"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.property_definitions"
- replica_name = "{replica}-{shard}"
- version_column = "version"
- }
- }
-
- view "raw_sessions_v3_v" {
+ view "raw_sessions_v3_v" {
override = true
query = <<SQL
SELECT
@@ -3000,105 +2396,6 @@ SQL
}
- table "session_replay_events" {
- override = true
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "min_first_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_last_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "first_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "click_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "keypress_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "mouse_activity_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "active_milliseconds" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_log_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_warn_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_error_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "size" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "message_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "event_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
- column "snapshot_source" {
- type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
- }
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "snapshot_library" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
- }
- column "is_deleted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "ai_tags_fixed" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_tags_freeform" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_highlighted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "surfacing_score" {
- type = "SimpleAggregateFunction(max, Nullable(Float32))"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_session_replay_events"
- sharding_key = "sipHash64(distinct_id)"
- }
- }
-
view "sessions_v" {
override = true
query = <<SQL
@@ -3140,37 +2437,7 @@ SQL
}
- table "tophog" {
- override = true
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "metric" {
- type = "LowCardinality(String)"
- }
- column "type" {
- type = "LowCardinality(String)"
- default = "'sum'"
- }
- column "key" {
- type = "Map(LowCardinality(String), String)"
- }
- column "value" {
- type = "Float64"
- }
- column "count" {
- type = "UInt64"
- default = "0"
- }
- column "pipeline" {
- type = "LowCardinality(String)"
- }
- column "lane" {
- type = "LowCardinality(String)"
- }
- column "labels" {
- type = "Map(LowCardinality(String), String)"
- }
+ patch_table "tophog" {
engine "distributed" {
cluster_name = "ops"
remote_database = "posthog"
@@ -3179,209 +2446,4 @@ SQL
}
}
- table "web_pre_aggregated_bounces" {
- override = true
- order_by = ["team_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
- partition_by = "toYYYYMMDD(period_bucket)"
- settings = {
- index_granularity = "8192"
- }
- column "period_bucket" {
- type = "DateTime"
- }
- column "team_id" {
- type = "UInt64"
- }
- column "host" {
- type = "String"
- }
- column "device_type" {
- type = "String"
- }
- column "entry_pathname" {
- type = "String"
- }
- column "end_pathname" {
- type = "String"
- }
- column "browser" {
- type = "String"
- }
- column "os" {
- type = "String"
- }
- column "viewport_width" {
- type = "Int64"
- }
- column "viewport_height" {
- type = "Int64"
- }
- column "referring_domain" {
- type = "String"
- }
- column "utm_source" {
- type = "String"
- }
- column "utm_medium" {
- type = "String"
- }
- column "utm_campaign" {
- type = "String"
- }
- column "utm_term" {
- type = "String"
- }
- column "utm_content" {
- type = "String"
- }
- column "country_code" {
- type = "String"
- }
- column "city_name" {
- type = "String"
- }
- column "region_code" {
- type = "String"
- }
- column "region_name" {
- type = "String"
- }
- column "has_gclid" {
- type = "Bool"
- }
- column "has_gad_source_paid_search" {
- type = "Bool"
- }
- column "has_fbclid" {
- type = "Bool"
- }
- column "mat_metadata_backend" {
- type = "Nullable(String)"
- }
- column "persons_uniq_state" {
- type = "AggregateFunction(uniq, UUID)"
- }
- column "sessions_uniq_state" {
- type = "AggregateFunction(uniq, String)"
- }
- column "pageviews_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "bounces_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "total_session_duration_state" {
- type = "AggregateFunction(sum, Int64)"
- }
- column "total_session_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "mat_metadata_loggedIn" {
- type = "Nullable(Bool)"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_bounces"
- replica_name = "{replica}-{shard}"
- }
- }
-
- table "web_pre_aggregated_stats" {
- override = true
- order_by = ["team_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid"]
- partition_by = "toYYYYMMDD(period_bucket)"
- settings = {
- index_granularity = "8192"
- }
- column "period_bucket" {
- type = "DateTime"
- }
- column "team_id" {
- type = "UInt64"
- }
- column "host" {
- type = "String"
- }
- column "device_type" {
- type = "String"
- }
- column "pathname" {
- type = "String"
- }
- column "entry_pathname" {
- type = "String"
- }
- column "end_pathname" {
- type = "String"
- }
- column "browser" {
- type = "String"
- }
- column "os" {
- type = "String"
- }
- column "viewport_width" {
- type = "Int64"
- }
- column "viewport_height" {
- type = "Int64"
- }
- column "referring_domain" {
- type = "String"
- }
- column "utm_source" {
- type = "String"
- }
- column "utm_medium" {
- type = "String"
- }
- column "utm_campaign" {
- type = "String"
- }
- column "utm_term" {
- type = "String"
- }
- column "utm_content" {
- type = "String"
- }
- column "country_code" {
- type = "String"
- }
- column "city_name" {
- type = "String"
- }
- column "region_code" {
- type = "String"
- }
- column "region_name" {
- type = "String"
- }
- column "has_gclid" {
- type = "Bool"
- }
- column "has_gad_source_paid_search" {
- type = "Bool"
- }
- column "has_fbclid" {
- type = "Bool"
- }
- column "mat_metadata_backend" {
- type = "Nullable(String)"
- }
- column "persons_uniq_state" {
- type = "AggregateFunction(uniq, UUID)"
- }
- column "sessions_uniq_state" {
- type = "AggregateFunction(uniq, String)"
- }
- column "pageviews_count_state" {
- type = "AggregateFunction(sum, UInt64)"
- }
- column "mat_metadata_loggedIn" {
- type = "Nullable(Bool)"
- }
- engine "replicated_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.web_pre_aggregated_stats"
- replica_name = "{replica}-{shard}"
- }
- }
}
diff --git a/posthog/clickhouse/hcl/roles/data/prod-us/tables.hcl b/posthog/clickhouse/hcl/roles/data/prod-us/tables.hcl
index ba18e29d3445..fffcfba37b44 100644
--- a/posthog/clickhouse/hcl/roles/data/prod-us/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/data/prod-us/tables.hcl
@@ -1753,134 +1753,6 @@ SQL
}
- table "clickhouse_cleanup_deleted_persons" {
- override = true
- order_by = ["run_id", "team_id", "person_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "person_id" {
- type = "UUID"
- }
- column "max_version" {
- type = "UInt64"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_deleted_persons"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_orphaned_distinct_ids" {
- override = true
- order_by = ["run_id", "team_id", "distinct_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "own_tombstone" {
- type = "UInt8"
- }
- column "max_version" {
- type = "Int64"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_orphaned_distinct_ids"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_revived_distinct_ids" {
- override = true
- order_by = ["run_id", "team_id", "distinct_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_distinct_ids"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
- table "clickhouse_cleanup_revived_persons" {
- override = true
- order_by = ["run_id", "team_id", "person_id"]
- partition_by = "run_id"
- ttl = "created_at + toIntervalDay(14)"
- settings = {
- index_granularity = "8192"
- ttl_only_drop_parts = "1"
- }
- column "run_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "person_id" {
- type = "UUID"
- }
- column "created_at" {
- type = "DateTime64(6, 'UTC')"
- default = "now64()"
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.clickhouse_cleanup_revived_persons"
- replica_name = "{replica}-{shard}"
- version_column = "created_at"
- }
- }
-
table "distributed_events_recent" {
override = true
column "uuid" {
@@ -2175,361 +2047,6 @@ SQL
}
}
- table "groups" {
- override = true
- order_by = ["team_id", "group_type_index", "group_key"]
- settings = {
- index_granularity = "8192"
- }
- column "group_type_index" {
- type = "UInt8"
- }
- column "group_key" {
- type = "String"
- }
- column "created_at" {
- type = "DateTime64(3)"
- }
- column "team_id" {
- type = "Int64"
- }
- column "group_properties" {
- type = "String"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "is_deleted" {
- type = "Bool"
- }
- index "is_deleted_idx" {
- expr = "is_deleted"
- type = "minmax"
- granularity = 1
- }
- engine "replicated_replacing_merge_tree" {
- zoo_path = "/clickhouse/tables/noshard/posthog.groups"
- replica_name = "{replica}-{shard}"
- version_column = "_timestamp"
- }
- }
-
- view "persons_batch_export" {
- override = true
- query = <<SQL
-WITH
- new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
- new_distinct_ids AS (SELECT argMax(person_id, person_distinct_id2.version) AS person_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (distinct_id IN (SELECT distinct_id FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY distinct_id HAVING (argMax(_timestamp, person_distinct_id2.version) >= {interval_start: DateTime64}) AND (argMax(_timestamp, person_distinct_id2.version) < {interval_end: DateTime64})),
- all_new_persons AS (SELECT id, version FROM new_persons UNION ALL SELECT id, max(version) FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (new_distinct_ids)) GROUP BY id)
-SELECT
- p.team_id AS team_id,
- pd.distinct_id AS distinct_id,
- toString(p.id) AS person_id,
- p.properties AS properties,
- pd.version AS person_distinct_id_version,
- p.version AS person_version,
- p.created_at AS created_at,
- multiIf(
- ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))
- AND (NOT ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))),
- pd._timestamp,
- ((p._timestamp >= {interval_start: DateTime64}) AND (p._timestamp < {interval_end: DateTime64}))
- AND (NOT ((pd._timestamp >= {interval_start: DateTime64}) AND (pd._timestamp < {interval_end: DateTime64}))),
- p._timestamp,
- least(p._timestamp, pd._timestamp)
- ) AS _inserted_at
-FROM
- posthog.person AS p INNER JOIN (SELECT distinct_id, max(version) AS version, argMax(person_id, person_distinct_id2.version) AS person_id2, argMax(_timestamp, person_distinct_id2.version) AS _timestamp FROM posthog.person_distinct_id2 WHERE (team_id = {team_id: Int64}) AND (person_id IN (SELECT id FROM all_new_persons)) GROUP BY distinct_id) AS pd ON p.id = pd.person_id2
-WHERE
- (team_id = {team_id: Int64})
-AND
- ((id, version) IN (all_new_persons))
-ORDER BY _inserted_at ASC
-SQL
-
- }
-
- materialized_view "posthog_document_embeddings_text_embedding_3_large_3072_mv" {
- override = true
- to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_large_3072"
- query = <<SQL
-SELECT
- team_id,
- product,
- document_type,
- rendering,
- document_id,
- timestamp,
- inserted_at,
- content,
- metadata,
- embedding,
- _timestamp,
- _offset,
- _partition
-FROM posthog.sharded_posthog_document_embeddings_buffer
-WHERE model_name = 'text-embedding-3-large-3072'
-SQL
-
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- }
- column "metadata" {
- type = "String"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- }
-
- materialized_view "posthog_document_embeddings_text_embedding_3_small_1536_mv" {
- override = true
- to_table = "posthog.writable_posthog_document_embeddings_text_embedding_3_small_1536"
- query = <<SQL
-SELECT
- team_id,
- product,
- document_type,
- rendering,
- document_id,
- timestamp,
- inserted_at,
- content,
- metadata,
- embedding,
- _timestamp,
- _offset,
- _partition
-FROM posthog.sharded_posthog_document_embeddings_buffer
-WHERE model_name = 'text-embedding-3-small-1536'
-SQL
-
- column "team_id" {
- type = "Int64"
- }
- column "product" {
- type = "LowCardinality(String)"
- }
- column "document_type" {
- type = "LowCardinality(String)"
- }
- column "rendering" {
- type = "LowCardinality(String)"
- }
- column "document_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(3, 'UTC')"
- }
- column "inserted_at" {
- type = "DateTime64(3, 'UTC')"
- }
- column "content" {
- type = "String"
- }
- column "metadata" {
- type = "String"
- }
- column "embedding" {
- type = "Array(Float64)"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_partition" {
- type = "UInt64"
- }
- }
-
- table "raw_sessions_v3" {
- override = true
- column "team_id" {
- type = "Int64"
- }
- column "session_id_v7" {
- type = "UInt128"
- }
- column "session_timestamp" {
- type = "DateTime64(3)"
- materialized = "fromUnixTimestamp64Milli(toUInt64(bitShiftRight(session_id_v7, 80)))"
- }
- column "distinct_id" {
- type = "AggregateFunction(argMax, String, DateTime64(6, 'UTC'))"
- }
- column "distinct_ids" {
- type = "AggregateFunction(groupUniqArray, String)"
- }
- column "min_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "max_inserted_at" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray(2000), Array(String))"
- }
- column "entry_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "end_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "last_external_click_url" {
- type = "AggregateFunction(argMax, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "browser" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "browser_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "os" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "os_version" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "device_type" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "viewport_width" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
- }
- column "viewport_height" {
- type = "AggregateFunction(argMin, Nullable(Int64), DateTime64(6, 'UTC'))"
- }
- column "geoip_country_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_1_code" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_1_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_subdivision_city_name" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "geoip_time_zone" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_referring_domain" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_campaign" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_medium" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_term" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_utm_content" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_gclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_gad_source" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_fbclid" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "entry_has_gclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
- }
- column "entry_has_fbclid" {
- type = "AggregateFunction(argMin, Bool, DateTime64(6, 'UTC'))"
- }
- column "entry_ad_ids_map" {
- type = "AggregateFunction(argMin, Map(String, String), DateTime64(6, 'UTC'))"
- }
- column "entry_ad_ids_set" {
- type = "AggregateFunction(argMin, Array(String), DateTime64(6, 'UTC'))"
- }
- column "entry_channel_type_properties" {
- type = "AggregateFunction(argMin, Tuple(Nullable(String), Nullable(String), Nullable(String), Nullable(String), Bool, Bool, Nullable(String)), DateTime64(6, 'UTC'))"
- }
- column "pageview_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "autocapture_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "screen_uniq" {
- type = "AggregateFunction(uniqExact, Nullable(UUID))"
- }
- column "page_screen_uniq_up_to" {
- type = "AggregateFunction(uniqUpTo(1), Nullable(UUID))"
- }
- column "has_autocapture" {
- type = "SimpleAggregateFunction(max, Bool)"
- }
- column "flag_values" {
- type = "AggregateFunction(groupUniqArrayMap, Map(String, String))"
- }
- column "flag_keys" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "event_names" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "has_replay_events" {
- type = "SimpleAggregateFunction(max, Bool)"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_raw_sessions_v3"
- sharding_key = "cityHash64(session_id_v7)"
- }
- }
-
view "raw_sessions_v3_v" {
override = true
query = <<SQL
@@ -2585,105 +2102,6 @@ SQL
}
- table "session_replay_events" {
- override = true
- column "session_id" {
- type = "String"
- }
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "min_first_timestamp" {
- type = "SimpleAggregateFunction(min, DateTime64(6, 'UTC'))"
- }
- column "max_last_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6, 'UTC'))"
- }
- column "first_url" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "click_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "keypress_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "mouse_activity_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "active_milliseconds" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_log_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_warn_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "console_error_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "size" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "message_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "event_count" {
- type = "SimpleAggregateFunction(sum, Int64)"
- }
- column "_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
- column "snapshot_source" {
- type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
- }
- column "all_urls" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "snapshot_library" {
- type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
- }
- column "block_first_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_last_timestamps" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC')))"
- }
- column "block_urls" {
- type = "SimpleAggregateFunction(groupArrayArray, Array(String))"
- }
- column "retention_period_days" {
- type = "SimpleAggregateFunction(max, Nullable(Int64))"
- }
- column "is_deleted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "ai_tags_fixed" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_tags_freeform" {
- type = "SimpleAggregateFunction(groupUniqArrayArray, Array(String))"
- }
- column "ai_highlighted" {
- type = "SimpleAggregateFunction(max, UInt8)"
- default = "0"
- }
- column "surfacing_score" {
- type = "SimpleAggregateFunction(max, Nullable(Float32))"
- }
- engine "distributed" {
- cluster_name = "posthog"
- remote_database = "posthog"
- remote_table = "sharded_session_replay_events"
- sharding_key = "sipHash64(distinct_id)"
- }
- }
-
view "sessions_v" {
override = true
query = <<SQL
@@ -2725,37 +2143,7 @@ SQL
}
- table "tophog" {
- override = true
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "metric" {
- type = "LowCardinality(String)"
- }
- column "type" {
- type = "LowCardinality(String)"
- default = "'sum'"
- }
- column "key" {
- type = "Map(LowCardinality(String), String)"
- }
- column "value" {
- type = "Float64"
- }
- column "count" {
- type = "UInt64"
- default = "0"
- }
- column "pipeline" {
- type = "LowCardinality(String)"
- }
- column "lane" {
- type = "LowCardinality(String)"
- }
- column "labels" {
- type = "Map(LowCardinality(String), String)"
- }
+ patch_table "tophog" {
engine "distributed" {
cluster_name = "ops"
remote_database = "posthog"
diff --git a/posthog/clickhouse/hcl/roles/ingestion_events/local/tables.hcl b/posthog/clickhouse/hcl/roles/ingestion_events/local/tables.hcl
index c7e1d69ffd87..0f6435ee5d87 100644
--- a/posthog/clickhouse/hcl/roles/ingestion_events/local/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/ingestion_events/local/tables.hcl
@@ -124,7 +124,6 @@ database "posthog" {
}
}
-
materialized_view "events_json_table_mv" {
to_table = "posthog.writable_events_json"
query = <<SQL
@@ -250,268 +249,4 @@ SQL
}
}
- table "writable_logs34" {
- column "time_bucket" {
- type = "DateTime"
- materialized = "toStartOfDay(timestamp)"
- }
- column "original_expiry_timestamp" {
- type = "DateTime64(6)"
- }
- column "uuid" {
- type = "String"
- }
- column "team_id" {
- type = "Int32"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "trace_flags" {
- type = "Int32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- codec = "DoubleDelta"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "created_at" {
- type = "DateTime64(6)"
- materialized = "now()"
- }
- column "body" {
- type = "String"
- }
- column "severity_text" {
- type = "LowCardinality(String)"
- }
- column "severity_number" {
- type = "Int32"
- }
- column "service_name" {
- type = "LowCardinality(String)"
- }
- column "resource_attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "resource_fingerprint" {
- type = "UInt64"
- materialized = "cityHash64(resource_attributes)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "event_name" {
- type = "String"
- }
- column "attributes_map_str" {
- type = "Map(LowCardinality(String), String)"
- }
- column "level" {
- type = "String"
- alias = "severity_text"
- }
- column "mat_body_ipv4_matches" {
- type = "Array(String)"
- alias = "extractAll(body, '(\\\\d\\\\.((25[0-5]|(2[0-4]|1(0, 1)[0-9])(0, 1)[0-9])\\\\.)(2, 2)([0-9]))')"
- }
- column "time_minute" {
- type = "DateTime"
- alias = "toStartOfMinute(timestamp)"
- }
- column "attributes" {
- type = "Map(LowCardinality(String), String)"
- alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"
- }
- column "attributes_map_float" {
- type = "Map(LowCardinality(String), Float64)"
- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__float'), toFloat64OrNull(v)), attributes_map_str))"
- }
- column "attributes_map_datetime" {
- type = "Map(LowCardinality(String), DateTime64(6))"
- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__datetime'), parseDateTimeBestEffortOrNull(v, 6)), attributes_map_str))"
- }
- column "_partition" {
- type = "UInt32"
- }
- column "_topic" {
- type = "String"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_bytes_uncompressed" {
- type = "UInt64"
- }
- column "_bytes_compressed" {
- type = "UInt64"
- }
- column "_record_count" {
- type = "UInt64"
- }
- column "pattern" {
- type = "String"
- }
- column "pattern_version" {
- type = "UInt8"
- }
- settings = {
- background_insert_batch = "1"
- }
- engine "distributed" {
- cluster_name = "logs"
- remote_database = "posthog"
- remote_table = "logs34"
- }
- }
-
- table "kafka_logs_avro" {
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "trace_flags" {
- type = "Int32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "body" {
- type = "String"
- }
- column "severity_text" {
- type = "String"
- }
- column "severity_number" {
- type = "Int32"
- }
- column "service_name" {
- type = "String"
- }
- column "resource_attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "event_name" {
- type = "String"
- }
- column "attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "retention_days" {
- type = "Nullable(Int32)"
- }
- column "pattern" {
- type = "Nullable(String)"
- }
- column "pattern_version" {
- type = "Nullable(Int32)"
- }
- engine "kafka" {
- collection = "warpstream_logs"
- topic_list = "clickhouse_logs"
- group_name = "clickhouse-logs-avro-new"
- format = "Avro"
- num_consumers = 8
- skip_broken_messages = 100
- poll_timeout_ms = 3000
- poll_max_batch_size = 1000
- thread_per_consumer = true
- }
- settings = {
- input_format_avro_allow_missing_fields = "1"
- }
- }
-
- materialized_view "kafka_logs34_avro_mv" {
- to_table = "posthog.writable_logs34"
- query = file("sql/kafka_logs34_avro_mv.sql")
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "trace_flags" {
- type = "Int32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "body" {
- type = "String"
- }
- column "severity_text" {
- type = "String"
- }
- column "severity_number" {
- type = "Int32"
- }
- column "service_name" {
- type = "String"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "event_name" {
- type = "String"
- }
- column "attributes_map_str" {
- type = "Map(String, String)"
- }
- column "resource_attributes" {
- type = "Map(String, String)"
- }
- column "team_id" {
- type = "Int32"
- }
- column "original_expiry_timestamp" {
- type = "DateTime64(6)"
- }
- column "_partition" {
- type = "UInt64"
- }
- column "_topic" {
- type = "LowCardinality(String)"
- }
- column "_offset" {
- type = "UInt64"
- }
- column "_record_count" {
- type = "Int64"
- }
- column "_bytes_uncompressed" {
- type = "Nullable(Int64)"
- }
- column "_bytes_compressed" {
- type = "Nullable(Int64)"
- }
- column "pattern" {
- type = "String"
- }
- column "pattern_version" {
- type = "UInt8"
- }
- }
}
diff --git a/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl b/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl
index a78d38135f23..9908cd2694bd 100644
--- a/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl
+++ b/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl
@@ -14,24 +14,6 @@ database "posthog" {
}
}
- # dev runs the metrics consumer small: a fraction of prod volume arrives here,
- # so it waits longer for smaller batches on fewer threads.
- patch_table "kafka_metrics_avro" {
- engine "kafka" {
- collection = "warpstream_metrics"
- topic_list = "clickhouse_metrics"
- group_name = "clickhouse-metrics-avro-new"
- format = "Avro"
- num_consumers = 2
- max_block_size = 4096
- skip_broken_messages = 100
- poll_timeout_ms = 10000
- poll_max_batch_size = 4096
- flush_interval_ms = 10000
- thread_per_consumer = true
- }
- }
-
patch_table "kafka_metrics_avro2" {
engine "kafka" {
collection = "warpstream_metrics"
diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl b/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl
index 457fd7883462..93377d826f41 100644
--- a/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl
@@ -6,171 +6,6 @@
# roles/logs/prod. The local codec deltas (value/count, matching prod) sit in
# roles/logs/local.
database "posthog" {
- table "kafka_metrics_avro" {
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "trace_flags" {
- type = "Nullable(Int32)"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "service_name" {
- type = "Nullable(String)"
- }
- column "metric_name" {
- type = "Nullable(String)"
- }
- column "metric_type" {
- type = "Nullable(String)"
- }
- column "value" {
- type = "Nullable(Float64)"
- }
- column "count" {
- type = "Nullable(Int64)"
- }
- column "histogram_bounds" {
- type = "Array(Float64)"
- }
- column "histogram_counts" {
- type = "Array(Int64)"
- }
- column "unit" {
- type = "Nullable(String)"
- }
- column "aggregation_temporality" {
- type = "Nullable(String)"
- }
- column "is_monotonic" {
- type = "Nullable(UInt8)"
- }
- column "resource_attributes" {
- type = "Map(String, String)"
- }
- column "instrumentation_scope" {
- type = "Nullable(String)"
- }
- column "attributes" {
- type = "Map(String, String)"
- }
- column "series_fingerprint" {
- type = "Nullable(Int64)"
- }
- engine "kafka" {
- collection = "warpstream_metrics"
- topic_list = "clickhouse_metrics"
- group_name = "clickhouse-metrics-avro-new"
- format = "Avro"
- num_consumers = 8
- skip_broken_messages = 100
- poll_timeout_ms = 3000
- poll_max_batch_size = 1000
- thread_per_consumer = true
- }
- }
- materialized_view "kafka_metrics_avro_kafka_metrics_mv" {
- to_table = "posthog.metrics_kafka_metrics"
- query = file("sql/kafka_metrics_avro_kafka_metrics_mv.sql")
- column "_partition" {
- type = "UInt64"
- }
- column "_topic" {
- type = "LowCardinality(String)"
- }
- column "max_offset" {
- type = "SimpleAggregateFunction(max, UInt64)"
- }
- column "max_observed_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6))"
- }
- column "max_timestamp" {
- type = "SimpleAggregateFunction(max, DateTime64(6))"
- }
- column "max_created_at" {
- type = "SimpleAggregateFunction(max, DateTime)"
- }
- column "max_lag" {
- type = "SimpleAggregateFunction(max, Decimal(18, 6))"
- }
- }
- materialized_view "kafka_metrics_avro_mv" {
- to_table = "posthog.metrics1"
- query = file("sql/kafka_metrics_avro_mv.sql")
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "trace_flags" {
- type = "Int32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "service_name" {
- type = "String"
- }
- column "metric_name" {
- type = "String"
- }
- column "metric_type" {
- type = "String"
- }
- column "value" {
- type = "Float64"
- }
- column "count" {
- type = "UInt64"
- }
- column "histogram_bounds" {
- type = "Array(Float64)"
- }
- column "histogram_counts" {
- type = "Array(UInt64)"
- }
- column "unit" {
- type = "String"
- }
- column "aggregation_temporality" {
- type = "String"
- }
- column "is_monotonic" {
- type = "UInt8"
- }
- column "resource_attributes" {
- type = "Map(String, String)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "attributes_map_str" {
- type = "Map(String, String)"
- }
- column "attributes_map_float" {
- type = "Map(String, Nullable(Float64))"
- }
- column "team_id" {
- type = "Int32"
- }
- }
table "metric_attributes" {
order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value"]
partition_by = "toDate(time_bucket)"
@@ -551,82 +386,6 @@ SQL
replica_name = "{replica}"
}
}
- materialized_view "kafka_metrics_avro_to_metric_samples" {
- to_table = "posthog.metric_samples1"
- query = file("sql/kafka_metrics_avro_to_metric_samples.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 = file("sql/kafka_metrics_avro_to_metric_series.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)"
- }
- }
table "kafka_metrics_avro2" {
column "uuid" {
diff --git a/posthog/clickhouse/hcl/roles/logs/traces/tables.hcl b/posthog/clickhouse/hcl/roles/logs/traces/tables.hcl
index d49bcd0919c8..1103a675d341 100644
--- a/posthog/clickhouse/hcl/roles/logs/traces/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/logs/traces/tables.hcl
@@ -161,83 +161,6 @@ database "posthog" {
}
}
- table "kafka_trace_spans_avro" {
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "parent_span_id" {
- type = "String"
- }
- column "trace_state" {
- type = "String"
- }
- column "name" {
- type = "String"
- }
- column "kind" {
- type = "Int32"
- }
- column "flags" {
- type = "Int32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "end_time" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "service_name" {
- type = "String"
- }
- column "resource_attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "dropped_attributes_count" {
- type = "Int32"
- }
- column "events" {
- type = "Array(String)"
- }
- column "dropped_events_count" {
- type = "Int32"
- }
- column "links" {
- type = "Array(String)"
- }
- column "dropped_links_count" {
- type = "Int32"
- }
- column "status_code" {
- type = "Int32"
- }
- engine "kafka" {
- collection = "warpstream_traces"
- topic_list = "clickhouse_traces"
- group_name = "clickhouse-traces-avro"
- format = "Avro"
- num_consumers = 8
- skip_broken_messages = 100
- poll_timeout_ms = 3000
- poll_max_batch_size = 1000
- thread_per_consumer = true
- }
- }
-
table "trace_spans" {
order_by = ["team_id", "time_bucket", "service_name", "resource_fingerprint", "status_code", "name", "timestamp"]
partition_by = "toDate(original_expiry_timestamp)"
@@ -732,77 +655,4 @@ SQL
}
}
- materialized_view "kafka_trace_spans_avro_mv" {
- to_table = "posthog.trace_spans"
- query = file("sql/kafka_trace_spans_avro_mv.sql")
- column "uuid" {
- type = "String"
- }
- column "trace_id" {
- type = "String"
- }
- column "span_id" {
- type = "String"
- }
- column "parent_span_id" {
- type = "String"
- }
- column "trace_state" {
- type = "String"
- }
- column "name" {
- type = "String"
- }
- column "kind" {
- type = "Int8"
- }
- column "flags" {
- type = "UInt32"
- }
- column "timestamp" {
- type = "DateTime64(6)"
- }
- column "end_time" {
- type = "DateTime64(6)"
- }
- column "observed_timestamp" {
- type = "DateTime64(6)"
- }
- column "service_name" {
- type = "String"
- }
- column "resource_attributes" {
- type = "Map(LowCardinality(String), String)"
- }
- column "instrumentation_scope" {
- type = "String"
- }
- column "attributes_map_str" {
- type = "Map(LowCardinality(String), String)"
- }
- column "dropped_attributes_count" {
- type = "UInt32"
- }
- column "events" {
- type = "Array(String)"
- }
- column "dropped_events_count" {
- type = "UInt32"
- }
- column "links" {
- type = "Array(String)"
- }
- column "dropped_links_count" {
- type = "UInt32"
- }
- column "status_code" {
- type = "Int16"
- }
- column "team_id" {
- type = "Int32"
- }
- column "original_expiry_timestamp" {
- type = "DateTime64(6)"
- }
- }
}
diff --git a/posthog/clickhouse/hcl/sql/dev/apm.sql b/posthog/clickhouse/hcl/sql/dev/apm.sql
index 27f92cb7bbbb..293096979c48 100644
--- a/posthog/clickhouse/hcl/sql/dev/apm.sql
+++ b/posthog/clickhouse/hcl/sql/dev/apm.sql
@@ -347,7 +347,7 @@ 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_trace_spans_avro_mv TO posthog.writable_trace_spans (uuid String, trace_id String, span_id String, parent_span_id String, trace_state String, name String, timestamp DateTime64(6), end_time DateTime64(6), observed_timestamp DateTime64(6), service_name String, instrumentation_scope String, events Array(String), links Array(String), kind Int8, flags UInt32, dropped_attributes_count UInt32, dropped_events_count UInt32, dropped_links_count UInt32, status_code Int16, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64)) AS SELECT
+CREATE MATERIALIZED VIEW posthog.kafka_trace_spans_avro_mv TO posthog.writable_trace_spans (uuid String, trace_id String, span_id String, parent_span_id String, trace_state String, name String, kind Int8, flags UInt32, timestamp DateTime64(6), end_time DateTime64(6), observed_timestamp DateTime64(6), service_name String, resource_attributes Map(String, String), instrumentation_scope String, attributes_map_str Map(String, String), dropped_attributes_count UInt32, events Array(String), dropped_events_count UInt32, links Array(String), dropped_links_count UInt32, status_code Int16, team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64)) AS SELECT
* EXCEPT(attributes, resource_attributes, kind, flags, dropped_attributes_count, dropped_events_count, dropped_links_count, status_code),
toInt8(kind) AS kind,
toUInt32(flags) AS flags,
diff --git a/posthog/clickhouse/hcl/sql/dev/data.sql b/posthog/clickhouse/hcl/sql/dev/data.sql
index 767532040c20..74d538d79768 100644
--- a/posthog/clickhouse/hcl/sql/dev/data.sql
+++ b/posthog/clickhouse/hcl/sql/dev/data.sql
@@ -1433,7 +1433,11 @@ CREATE TABLE posthog.sharded_session_replay_events (
distinct_id String,
min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
click_count SimpleAggregateFunction(sum, Int64),
keypress_count SimpleAggregateFunction(sum, Int64),
mouse_activity_count SimpleAggregateFunction(sum, Int64),
@@ -1444,19 +1448,15 @@ CREATE TABLE posthog.sharded_session_replay_events (
size SimpleAggregateFunction(sum, Int64),
message_count SimpleAggregateFunction(sum, Int64),
event_count SimpleAggregateFunction(sum, Int64),
- _timestamp SimpleAggregateFunction(max, DateTime),
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
- all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
- block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ _timestamp SimpleAggregateFunction(max, DateTime),
is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
- surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.session_replay_events', '{replica}') ORDER BY (toDate(min_first_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
CREATE TABLE posthog.sharded_sessions (
session_id String,
@@ -2773,9 +2773,9 @@ CREATE TABLE posthog.session_recording_events (
window_id String,
snapshot_data String,
created_at DateTime64(6, 'UTC'),
- has_full_snapshot Int8 COMMENT 'column_materializer::has_full_snapshot',
_timestamp DateTime,
_offset UInt64,
+ has_full_snapshot Int8 COMMENT 'column_materializer::has_full_snapshot',
events_summary Array(String) COMMENT 'column_materializer::events_summary',
click_count Int8 COMMENT 'column_materializer::click_count',
keypress_count Int8 COMMENT 'column_materializer::keypress_count',
@@ -2798,7 +2798,11 @@ CREATE TABLE posthog.session_replay_events (
distinct_id String,
min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
click_count SimpleAggregateFunction(sum, Int64),
keypress_count SimpleAggregateFunction(sum, Int64),
mouse_activity_count SimpleAggregateFunction(sum, Int64),
@@ -2809,19 +2813,15 @@ CREATE TABLE posthog.session_replay_events (
size SimpleAggregateFunction(sum, Int64),
message_count SimpleAggregateFunction(sum, Int64),
event_count SimpleAggregateFunction(sum, Int64),
- _timestamp SimpleAggregateFunction(max, DateTime),
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
- all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
- block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ _timestamp SimpleAggregateFunction(max, DateTime),
is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
- surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
CREATE TABLE posthog.sessions (
session_id String,
diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sql
index 693bbeda924f..875696ebfbf3 100644
--- a/posthog/clickhouse/hcl/sql/dev/logs.sql
+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql
@@ -1,28 +1,6 @@
-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit.
-- Full CREATE schema for the dev/logs node. Apply to a fresh ClickHouse to build it.
-CREATE TABLE posthog.kafka_metrics_avro (
- uuid String,
- trace_id String,
- span_id String,
- trace_flags Nullable(Int32),
- timestamp DateTime64(6),
- observed_timestamp DateTime64(6),
- service_name Nullable(String),
- metric_name Nullable(String),
- metric_type Nullable(String),
- value Nullable(Float64),
- count Nullable(Int64),
- histogram_bounds Array(Float64),
- histogram_counts Array(Int64),
- unit Nullable(String),
- aggregation_temporality Nullable(String),
- is_monotonic Nullable(UInt8),
- resource_attributes Map(String, String),
- instrumentation_scope Nullable(String),
- attributes Map(String, String),
- series_fingerprint Nullable(Int64)
-) ENGINE = Kafka(warpstream_metrics) SETTINGS kafka_flush_interval_ms = 10000, kafka_format = 'Avro', kafka_group_name = 'clickhouse-metrics-avro-new', kafka_max_block_size = 4096, kafka_num_consumers = 2, kafka_poll_max_batch_size = 4096, kafka_poll_timeout_ms = 10000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'clickhouse_metrics';
CREATE TABLE posthog.kafka_metrics_avro2 (
uuid String,
trace_id String,
@@ -47,29 +25,6 @@ CREATE TABLE posthog.kafka_metrics_avro2 (
has_labels Nullable(UInt8),
retention_days Nullable(Int32)
) ENGINE = Kafka(warpstream_metrics) SETTINGS input_format_avro_allow_missing_fields = 1, kafka_flush_interval_ms = 10000, kafka_format = 'Avro', kafka_group_name = 'clickhouse-metrics-avro2', kafka_max_block_size = 4096, kafka_num_consumers = 2, kafka_poll_max_batch_size = 4096, kafka_poll_timeout_ms = 10000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'clickhouse_metrics';
-CREATE TABLE posthog.kafka_trace_spans_avro (
- uuid String,
- trace_id String,
- span_id String,
- parent_span_id String,
- trace_state String,
- name String,
- kind Int32,
- flags Int32,
- timestamp DateTime64(6),
- end_time DateTime64(6),
- observed_timestamp DateTime64(6),
- service_name String,
- resource_attributes Map(LowCardinality(String), String),
- instrumentation_scope String,
- attributes Map(LowCardinality(String), String),
- dropped_attributes_count Int32,
- events Array(String),
- dropped_events_count Int32,
- links Array(String),
- dropped_links_count Int32,
- status_code Int32
-) ENGINE = Kafka(warpstream_traces) SETTINGS kafka_format = 'Avro', kafka_group_name = 'clickhouse-traces-avro', kafka_num_consumers = 8, kafka_poll_max_batch_size = 1000, kafka_poll_timeout_ms = 3000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'clickhouse_traces';
CREATE TABLE posthog.log_attributes2 (
team_id Int32,
time_bucket DateTime64(0),
@@ -910,107 +865,6 @@ WHERE kafka_metrics_avro2.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_kafka_metrics_mv TO posthog.metrics_kafka_metrics (_partition UInt64, _topic LowCardinality(String), max_offset SimpleAggregateFunction(max, UInt64), max_observed_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_created_at SimpleAggregateFunction(max, DateTime), max_lag SimpleAggregateFunction(max, Decimal(18, 6))) AS SELECT
- _partition,
- _topic,
- maxSimpleState(_offset) AS max_offset,
- maxSimpleState(observed_timestamp) AS max_observed_timestamp,
- maxSimpleState(timestamp) AS max_timestamp,
- maxSimpleState(now()) AS max_created_at,
- maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM posthog.kafka_metrics_avro
-GROUP BY
- _partition, _topic;
-CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_mv TO posthog.metrics1 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), service_name String, metric_name String, metric_type String, value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), unit String, aggregation_temporality String, is_monotonic UInt8, resource_attributes Map(String, String), instrumentation_scope String, attributes_map_str Map(String, String), attributes_map_float Map(String, Nullable(Float64)), team_id Int32) AS SELECT
- uuid,
- trace_id,
- span_id,
- ifNull(trace_flags, 0) AS trace_flags,
- timestamp,
- observed_timestamp,
- ifNull(service_name, '') AS service_name,
- ifNull(metric_name, '') AS metric_name,
- ifNull(metric_type, '') AS metric_type,
- ifNull(value, 0) AS value,
- toUInt64(ifNull(count, 1)) AS count,
- histogram_bounds,
- arrayMap(x -> toUInt64(x), histogram_counts) AS histogram_counts,
- ifNull(unit, '') AS unit,
- ifNull(aggregation_temporality, '') AS aggregation_temporality,
- ifNull(is_monotonic, 0) AS is_monotonic,
- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
- ifNull(instrumentation_scope, '') AS instrumentation_scope,
- mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,
- mapSort(
- mapFilter(
- (k, v) -> isNotNull(v),
- mapApply(
- (k, v) -> (concat(k, '__float'), toFloat64OrNull(JSONExtract(v, 'String'))),
- attributes
- )
- )
- ) 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;
-CREATE MATERIALIZED VIEW posthog.kafka_trace_spans_avro_mv TO posthog.trace_spans (uuid String, trace_id String, span_id String, parent_span_id String, trace_state String, name String, kind Int8, flags UInt32, timestamp DateTime64(6), end_time DateTime64(6), observed_timestamp DateTime64(6), service_name String, resource_attributes Map(LowCardinality(String), String), instrumentation_scope String, attributes_map_str Map(LowCardinality(String), String), dropped_attributes_count UInt32, events Array(String), dropped_events_count UInt32, links Array(String), dropped_links_count UInt32, status_code Int16, team_id Int32, original_expiry_timestamp DateTime64(6)) AS SELECT
- * EXCEPT(attributes, resource_attributes, kind, flags, dropped_attributes_count, dropped_events_count, dropped_links_count, status_code),
- toInt8(kind) AS kind,
- toUInt32(flags) AS flags,
- toUInt32(dropped_attributes_count) AS dropped_attributes_count,
- toUInt32(dropped_events_count) AS dropped_events_count,
- toUInt32(dropped_links_count) AS dropped_links_count,
- toInt16(status_code) AS status_code,
- mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,
- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,
- observed_timestamp
- + toIntervalDay(
- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(15))
- ) AS original_expiry_timestamp,
- _partition,
- _topic,
- _offset,
- toInt64OrDefault(_headers.value[indexOf(_headers.name, 'record_count')], toInt64(1)) AS _record_count,
- toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) AS _bytes_uncompressed,
- toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) AS _bytes_compressed
-FROM posthog.kafka_trace_spans_avro;
CREATE MATERIALIZED VIEW posthog.logs34_to_log_attributes3 TO posthog.log_attributes3 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), severity_text LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT
team_id,
time_bucket,
diff --git a/posthog/clickhouse/hcl/sql/prod-eu/data.sql b/posthog/clickhouse/hcl/sql/prod-eu/data.sql
index e9c63b4547de..f626d4b4af09 100644
--- a/posthog/clickhouse/hcl/sql/prod-eu/data.sql
+++ b/posthog/clickhouse/hcl/sql/prod-eu/data.sql
@@ -1601,7 +1601,11 @@ CREATE TABLE posthog.sharded_session_replay_events (
distinct_id String,
min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
click_count SimpleAggregateFunction(sum, Int64),
keypress_count SimpleAggregateFunction(sum, Int64),
mouse_activity_count SimpleAggregateFunction(sum, Int64),
@@ -1612,19 +1616,15 @@ CREATE TABLE posthog.sharded_session_replay_events (
size SimpleAggregateFunction(sum, Int64),
message_count SimpleAggregateFunction(sum, Int64),
event_count SimpleAggregateFunction(sum, Int64),
- _timestamp SimpleAggregateFunction(max, DateTime),
snapshot_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
- all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
- block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ _timestamp SimpleAggregateFunction(max, DateTime),
is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
- surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.session_replay_events', '{replica}') ORDER BY (toDate(min_first_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
CREATE TABLE posthog.swap_person_distinct_id (
distinct_id String,
@@ -3043,9 +3043,9 @@ CREATE TABLE posthog.session_recording_events (
window_id String,
snapshot_data String,
created_at DateTime64(6, 'UTC'),
- has_full_snapshot Int8 COMMENT 'column_materializer::has_full_snapshot',
_timestamp DateTime,
_offset UInt64,
+ has_full_snapshot Int8 COMMENT 'column_materializer::has_full_snapshot',
events_summary Array(String) COMMENT 'column_materializer::events_summary',
click_count Int8 COMMENT 'column_materializer::click_count',
keypress_count Int8 COMMENT 'column_materializer::keypress_count',
@@ -3068,7 +3068,11 @@ CREATE TABLE posthog.session_replay_events (
distinct_id String,
min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
click_count SimpleAggregateFunction(sum, Int64),
keypress_count SimpleAggregateFunction(sum, Int64),
mouse_activity_count SimpleAggregateFunction(sum, Int64),
@@ -3079,19 +3083,15 @@ CREATE TABLE posthog.session_replay_events (
size SimpleAggregateFunction(sum, Int64),
message_count SimpleAggregateFunction(sum, Int64),
event_count SimpleAggregateFunction(sum, Int64),
- _timestamp SimpleAggregateFunction(max, DateTime),
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
- all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
- block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ _timestamp SimpleAggregateFunction(max, DateTime),
is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
- surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
CREATE VIEW posthog.custom_metrics AS SELECT * REPLACE(toFloat64(value) AS value)
FROM posthog.custom_metrics_test
diff --git a/posthog/clickhouse/hcl/sql/prod-us/data.sql b/posthog/clickhouse/hcl/sql/prod-us/data.sql
index fcef5b8f24c9..d90a464d69fd 100644
--- a/posthog/clickhouse/hcl/sql/prod-us/data.sql
+++ b/posthog/clickhouse/hcl/sql/prod-us/data.sql
@@ -1433,7 +1433,11 @@ CREATE TABLE posthog.sharded_session_replay_events (
distinct_id String,
min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
click_count SimpleAggregateFunction(sum, Int64),
keypress_count SimpleAggregateFunction(sum, Int64),
mouse_activity_count SimpleAggregateFunction(sum, Int64),
@@ -1444,19 +1448,15 @@ CREATE TABLE posthog.sharded_session_replay_events (
size SimpleAggregateFunction(sum, Int64),
message_count SimpleAggregateFunction(sum, Int64),
event_count SimpleAggregateFunction(sum, Int64),
- _timestamp SimpleAggregateFunction(max, DateTime),
snapshot_source AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
- all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
- block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ _timestamp SimpleAggregateFunction(max, DateTime),
is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
- surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.session_replay_events', '{replica}') ORDER BY (toDate(min_first_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512;
CREATE TABLE posthog.swap_person_distinct_id (
distinct_id String,
@@ -2905,7 +2905,11 @@ CREATE TABLE posthog.session_replay_events (
distinct_id String,
min_first_timestamp SimpleAggregateFunction(min, DateTime64(6, 'UTC')),
max_last_timestamp SimpleAggregateFunction(max, DateTime64(6, 'UTC')),
+ block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
+ block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
click_count SimpleAggregateFunction(sum, Int64),
keypress_count SimpleAggregateFunction(sum, Int64),
mouse_activity_count SimpleAggregateFunction(sum, Int64),
@@ -2916,19 +2920,15 @@ CREATE TABLE posthog.session_replay_events (
size SimpleAggregateFunction(sum, Int64),
message_count SimpleAggregateFunction(sum, Int64),
event_count SimpleAggregateFunction(sum, Int64),
- _timestamp SimpleAggregateFunction(max, DateTime),
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
- all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
- block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))),
- block_urls SimpleAggregateFunction(groupArrayArray, Array(String)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ _timestamp SimpleAggregateFunction(max, DateTime),
is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
- surfacing_score SimpleAggregateFunction(max, Nullable(Float32))
+ surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
CREATE TABLE posthog.writable_raw_sessions_v3 (
team_id Int64,