:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(metrics): drop legacy metrics1 materialized views (#99988)
Frank Hamandfac9deb772e2
diff --git a/posthog/clickhouse/hcl/golden/dev/apm.hcl b/posthog/clickhouse/hcl/golden/dev/apm.hclindex 63a5e870f28a..111791677da6 100644--- a/posthog/clickhouse/hcl/golden/dev/apm.hcl+++ b/posthog/clickhouse/hcl/golden/dev/apm.hcl@@ -937,224 +937,6 @@ SQL}}- materialized_view "kafka_metrics_avro_mv" {- 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" {- 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" {- 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" {to_table = "posthog.writable_trace_spans"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hclindex 8daa1d004735..84ab631e0045 100644--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl@@ -3292,119 +3292,6 @@ SQL}}- materialized_view "metrics1_to_metric_attributes" {- to_table = "posthog.metric_attributes"- query = <<SQL-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics1_to_resource_attributes" {- to_table = "posthog.metric_attributes"- query = <<SQL-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, resource_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-materialized_view "metrics2_input_to_metric_attributes" {to_table = "posthog.metric_attributes2"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl b/posthog/clickhouse/hcl/golden/local-multi/logs.hclindex 25cb1a07e2f6..87d146c28936 100644--- a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl@@ -3621,224 +3621,6 @@ SQL}}- 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@@ -4254,119 +4036,6 @@ SQL}}- materialized_view "metrics1_to_metric_attributes" {- to_table = "posthog.metric_attributes"- query = <<SQL-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics1_to_resource_attributes" {- to_table = "posthog.metric_attributes"- query = <<SQL-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, resource_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-materialized_view "metrics2_input_to_metric_attributes" {to_table = "posthog.metric_attributes2"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hclindex cbf0ef199360..e201c0fa23b9 100644--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl@@ -20627,224 +20627,6 @@ SQL}}- 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@@ -21437,119 +21219,6 @@ SQL}}- materialized_view "metrics1_to_metric_attributes" {- to_table = "posthog.metric_attributes"- query = <<SQL-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics1_to_resource_attributes" {- to_table = "posthog.metric_attributes"- query = <<SQL-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, resource_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-materialized_view "metrics2_input_to_metric_attributes" {to_table = "posthog.metric_attributes2"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl b/posthog/clickhouse/hcl/golden/prod-eu/logs.hclindex 03289bd84e76..99aa4e2baa9e 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl@@ -3326,224 +3326,6 @@ SQL}}- 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@@ -3836,119 +3618,6 @@ SQL}}- materialized_view "metrics1_to_metric_attributes" {- to_table = "posthog.metric_attributes"- query = <<SQL-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics1_to_resource_attributes" {- to_table = "posthog.metric_attributes"- query = <<SQL-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, resource_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-materialized_view "metrics2_input_to_metric_attributes" {to_table = "posthog.metric_attributes2"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl b/posthog/clickhouse/hcl/golden/prod-us/logs.hclindex fb5bce738952..e566f4b7574e 100644--- a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl@@ -3308,224 +3308,6 @@ SQL}}- 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@@ -3818,119 +3600,6 @@ SQL}}- materialized_view "metrics1_to_metric_attributes" {- to_table = "posthog.metric_attributes"- query = <<SQL-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics1_to_resource_attributes" {- to_table = "posthog.metric_attributes"- query = <<SQL-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, resource_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-materialized_view "metrics2_input_to_metric_attributes" {to_table = "posthog.metric_attributes2"query = <<SQLdiff --git a/posthog/clickhouse/hcl/roles/apm/dev/tables.hcl b/posthog/clickhouse/hcl/roles/apm/dev/tables.hclindex 4e88bec6c582..2fdbf1268290 100644--- a/posthog/clickhouse/hcl/roles/apm/dev/tables.hcl+++ b/posthog/clickhouse/hcl/roles/apm/dev/tables.hcl@@ -411,22 +411,10 @@ database "posthog" {}}- 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"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.sqldeleted file mode 100644index 83238b61833c..000000000000--- a/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_mv.sql+++ /dev/null@@ -1,34 +0,0 @@-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 = 0diff --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.sqldeleted file mode 100644index 977ee9a7ea79..000000000000--- a/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_to_metric_samples.sql+++ /dev/null@@ -1,17 +0,0 @@-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 = 0diff --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.sqldeleted file mode 100644index 6297629b5a01..000000000000--- a/posthog/clickhouse/hcl/roles/coshared/apm_ingest/sql/kafka_metrics_avro_to_metric_series.sql+++ /dev/null@@ -1,17 +0,0 @@-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 = 0diff --git a/posthog/clickhouse/hcl/roles/coshared/apm_ingest/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/tables.hclindex 0007acab2adf..4556acc71898 100644--- a/posthog/clickhouse/hcl/roles/coshared/apm_ingest/tables.hcl+++ b/posthog/clickhouse/hcl/roles/coshared/apm_ingest/tables.hcl@@ -102,152 +102,6 @@ database "posthog" {}}- 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"diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro_mv.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro_mv.sqldeleted file mode 100644index 83238b61833c..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro_mv.sql+++ /dev/null@@ -1,34 +0,0 @@-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 = 0diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro_to_metric_samples.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro_to_metric_samples.sqldeleted file mode 100644index 977ee9a7ea79..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro_to_metric_samples.sql+++ /dev/null@@ -1,17 +0,0 @@-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 = 0diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro_to_metric_series.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro_to_metric_series.sqldeleted file mode 100644index 6297629b5a01..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro_to_metric_series.sql+++ /dev/null@@ -1,17 +0,0 @@-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 = 0diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics1_to_metric_attributes.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics1_to_metric_attributes.sqldeleted file mode 100644index a43fd58c454c..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics1_to_metric_attributes.sql+++ /dev/null@@ -1,26 +0,0 @@-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, attributes- )diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics1_to_resource_attributes.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics1_to_resource_attributes.sqldeleted file mode 100644index eb2c5b822254..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics1_to_resource_attributes.sql+++ /dev/null@@ -1,25 +0,0 @@-SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, resource_attributes- )diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl b/posthog/clickhouse/hcl/roles/logs/metrics/tables.hclindex 79de6ad784a9..bc28422ddeaf 100644--- a/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl@@ -1,10 +1,8 @@-# LOGS role, all envs — the Kafka metrics ingest chain: kafka_metrics_avro + the MVs-# into metrics1 (raw), metric_samples1/metric_series1, metric_attributes, and the-# metrics_kafka_metrics lag bookkeeping. Declared in the local single-shard shape-# migration 0309 creates; the cloud envs restore their /clickhouse/tables/logs/{shard}-# ZK paths via patches in roles/logs/shared, and the prod codec deltas sit in-# roles/logs/prod. The local codec deltas (value/count, matching prod) sit in-# roles/logs/local.+# This layer defines LOGS role metric storage and the metrics2 ingest chain.+# The legacy Kafka table remains for lag bookkeeping.+# Patches in roles/logs/shared restore the cloud ZK paths.+# The prod codec deltas sit in roles/logs/prod.+# The local codec deltas for value and count sit in roles/logs/local.database "posthog" {table "metric_attributes" {order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value"]@@ -63,62 +61,6 @@ database "posthog" {replica_name = "{replica}"}}- materialized_view "metrics1_to_metric_attributes" {- to_table = "posthog.metric_attributes"- query = file("sql/metrics1_to_metric_attributes.sql")- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }- materialized_view "metrics1_to_resource_attributes" {- to_table = "posthog.metric_attributes"- query = file("sql/metrics1_to_resource_attributes.sql")- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }table "metrics_kafka_metrics" {order_by = ["_topic", "_partition"]settings = {diff --git a/posthog/clickhouse/hcl/sql/dev/apm.sql b/posthog/clickhouse/hcl/sql/dev/apm.sqlindex 293096979c48..244c9f73f20a 100644--- a/posthog/clickhouse/hcl/sql/dev/apm.sql+++ b/posthog/clickhouse/hcl/sql/dev/apm.sql@@ -279,74 +279,6 @@ CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_kafka_metrics_mv TO posthog.FROM posthog.kafka_metrics_avroGROUP BY_partition, _topic;-CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_mv TO posthog.writable_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.writable_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.writable_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.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,diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sqlindex 60a4633f5418..c8fa667fa4d4 100644--- a/posthog/clickhouse/hcl/sql/dev/logs.sql+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql@@ -940,57 +940,6 @@ FROM)GROUP BYteam_id, time_bucket, service_name, namespace, environment, severity_text;-CREATE MATERIALIZED VIEW posthog.metrics1_to_metric_attributes TO posthog.metric_attributes (team_id Int32, time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, attributes- );-CREATE MATERIALIZED VIEW posthog.metrics1_to_resource_attributes TO posthog.metric_attributes (team_id Int32, time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, resource_attributes- );CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,diff --git a/posthog/clickhouse/hcl/sql/local-multi/logs.sql b/posthog/clickhouse/hcl/sql/local-multi/logs.sqlindex 4e2bce35bbcd..71a31b4f0828 100644--- a/posthog/clickhouse/hcl/sql/local-multi/logs.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/logs.sql@@ -944,74 +944,6 @@ CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_kafka_metrics_mv TO posthog.FROM posthog.kafka_metrics_avroGROUP 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,@@ -1181,57 +1113,6 @@ FROM)GROUP BYteam_id, time_bucket, service_name, namespace, environment, severity_text;-CREATE MATERIALIZED VIEW posthog.metrics1_to_metric_attributes TO posthog.metric_attributes (team_id Int32, time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, attributes- );-CREATE MATERIALIZED VIEW posthog.metrics1_to_resource_attributes TO posthog.metric_attributes (team_id Int32, time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, resource_attributes- );CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sqlindex 767d35628ec8..276a69b487d6 100644--- a/posthog/clickhouse/hcl/sql/local-single/all.sql+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql@@ -4763,74 +4763,6 @@ CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_kafka_metrics_mv TO posthog.FROM posthog.kafka_metrics_avroGROUP 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,@@ -5045,57 +4977,6 @@ CREATE MATERIALIZED VIEW posthog.message_assets_mv TO posthog.message_assets_dat_offset,_partitionFROM posthog.kafka_message_assets;-CREATE MATERIALIZED VIEW posthog.metrics1_to_metric_attributes TO posthog.metric_attributes (team_id Int32, time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, attributes- );-CREATE MATERIALIZED VIEW posthog.metrics1_to_resource_attributes TO posthog.metric_attributes (team_id Int32, time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, resource_attributes- );CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql b/posthog/clickhouse/hcl/sql/prod-eu/logs.sqlindex 076245d9572f..b2e0c4bd2f44 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql@@ -919,74 +919,6 @@ CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_kafka_metrics_mv TO posthog.FROM posthog.kafka_metrics_avroGROUP 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,@@ -1101,57 +1033,6 @@ FROM)GROUP BYteam_id, time_bucket, service_name, namespace, environment, severity_text;-CREATE MATERIALIZED VIEW posthog.metrics1_to_metric_attributes TO posthog.metric_attributes (team_id Int32, time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, attributes- );-CREATE MATERIALIZED VIEW posthog.metrics1_to_resource_attributes TO posthog.metric_attributes (team_id Int32, time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, resource_attributes- );CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,diff --git a/posthog/clickhouse/hcl/sql/prod-us/logs.sql b/posthog/clickhouse/hcl/sql/prod-us/logs.sqlindex 705e8aafcf16..1ff859fcf4d0 100644--- a/posthog/clickhouse/hcl/sql/prod-us/logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/logs.sql@@ -913,74 +913,6 @@ CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_kafka_metrics_mv TO posthog.FROM posthog.kafka_metrics_avroGROUP 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,@@ -1095,57 +1027,6 @@ FROM)GROUP BYteam_id, time_bucket, service_name, namespace, environment, severity_text;-CREATE MATERIALIZED VIEW posthog.metrics1_to_metric_attributes TO posthog.metric_attributes (team_id Int32, time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, attributes- );-CREATE MATERIALIZED VIEW posthog.metrics1_to_resource_attributes TO posthog.metric_attributes (team_id Int32, time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics1- GROUP BY- team_id, time_bucket, service_name, resource_fingerprint, resource_attributes- );CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,diff --git a/posthog/clickhouse/migrations/0321_drop_metrics1_materialized_views.py b/posthog/clickhouse/migrations/0321_drop_metrics1_materialized_views.pynew file mode 100644index 000000000000..267f55efd7c7--- /dev/null+++ b/posthog/clickhouse/migrations/0321_drop_metrics1_materialized_views.py@@ -0,0 +1,12 @@+from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions++# metrics2 owns ingestion and attribute extraction now. Remove the legacy metrics1+# views so Kafka inserts no longer write to metrics1, metric_samples1, or metric_series1.+operations = [+ run_sql_with_exceptions("DROP TABLE IF EXISTS metrics1_to_metric_attributes", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS metrics1_to_resource_attributes", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS kafka_metrics_avro_mv", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS kafka_metrics_avro_to_metric_samples", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS kafka_metrics_avro_to_metric_series", node_roles=[NodeRole.LOGS]),+]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex 638956861648..5cd3683c56b6 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0320_metric_series2_last_seen_index+0321_drop_metrics1_materialized_viewsdiff --git a/posthog/clickhouse/schema.py b/posthog/clickhouse/schema.pyindex 6bbee3b3b796..9e984733cc18 100644--- a/posthog/clickhouse/schema.py+++ b/posthog/clickhouse/schema.py@@ -36,9 +36,7 @@ from posthog.clickhouse.logs import (from posthog.clickhouse.metrics import (METRIC_ATTRIBUTES2_DISTRIBUTED_TABLE_SQL,METRIC_ATTRIBUTES2_TABLE_SQL,- METRIC_ATTRIBUTES_MV,METRIC_ATTRIBUTES_TABLE_SQL,- METRIC_RESOURCE_ATTRIBUTES_MV,METRIC_SAMPLES_DISTRIBUTED_TABLE_SQL,METRIC_SAMPLES_TABLE_SQL,METRIC_SERIES2_DISTRIBUTED_TABLE_SQL,@@ -640,8 +638,6 @@ CREATE_MV_TABLE_QUERIES = (LOGS34_TO_LOG_ATTRIBUTES3_MV,LOGS34_TO_RESOURCE_ATTRIBUTES3_MV,LOGS34_TO_VOLUME_BUCKETS_MV,- METRIC_ATTRIBUTES_MV,- METRIC_RESOURCE_ATTRIBUTES_MV,METRICS2_INPUT_TO_METRICS_MV,METRICS2_INPUT_TO_METRIC_SERIES_MV,METRICS2_INPUT_TO_METRIC_ATTRIBUTES_MV,diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex 5b22bd65c142..54b8e67a040f 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -4296,99 +4296,6 @@'''# ----# name: test_create_table_query[metrics1_to_metric_attributes]- '''-- CREATE MATERIALIZED VIEW IF NOT EXISTS posthog_test.metrics1_to_metric_attributes TO posthog_test.metric_attributes- (- `team_id` Int32,- `time_bucket` DateTime64(0),- `service_name` LowCardinality(String),- `resource_fingerprint` UInt64,- `attribute_key` LowCardinality(String),- `attribute_value` String,- `attribute_type` LowCardinality(String),- `attribute_count` SimpleAggregateFunction(sum, UInt64)- )- AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count- FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,- arrayJoin(attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog_test.metrics1- GROUP BY- team_id,- time_bucket,- service_name,- resource_fingerprint,- attributes- )-- '''-# ----# name: test_create_table_query[metrics1_to_resource_attributes]- '''-- CREATE MATERIALIZED VIEW IF NOT EXISTS posthog_test.metrics1_to_resource_attributes TO posthog_test.metric_attributes- (- `team_id` Int32,- `time_bucket` DateTime64(0),- `service_name` LowCardinality(String),- `resource_fingerprint` UInt64,- `attribute_key` LowCardinality(String),- `attribute_value` String,- `attribute_type` LowCardinality(String),- `attribute_count` SimpleAggregateFunction(sum, UInt64)- )- AS SELECT- team_id,- time_bucket,- service_name,- resource_fingerprint,- attribute_key,- attribute_value,- attribute_type,- attribute_count- FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,- service_name AS service_name,- resource_fingerprint,- arrayJoin(resource_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog_test.metrics1- GROUP BY- team_id,- time_bucket,- service_name,- resource_fingerprint,- resource_attributes- )-- '''-# ---# name: test_create_table_query[metrics2]'''