Skip to content

Commit f10ef4f

Browse files
committed
sort columns and indices
1 parent 783c7ae commit f10ef4f

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

packages/migrations/src/clickhouse-actions/015-otel-trace.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,32 @@ export const action: Action = async exec => {
9292
, "trace_id" String CODEC(ZSTD(1))
9393
, "span_id" String CODEC(ZSTD(1))
9494
, "timestamp" DateTime('UTC') CODEC(DoubleDelta, LZ4)
95-
, "operation_name" String CODEC(ZSTD(1))
96-
, "operation_type" LowCardinality(String) CODEC(ZSTD(1))
97-
, "operation_body" String CODEC(ZSTD(1))
9895
, "duration" UInt64 CODEC(T64, ZSTD(1))
99-
, "subgraph_names" Array(LowCardinality(String)) CODEC(ZSTD(1))
10096
, "http_status_code" String CODEC(ZSTD(1))
10197
, "http_method" String CODEC(ZSTD(1))
10298
, "http_host" String CODEC(ZSTD(1))
10399
, "http_route" String CODEC(ZSTD(1))
104100
, "http_url" String CODEC(ZSTD(1))
105-
, INDEX "idx_operation_name" "operation_name" TYPE bloom_filter(0.01) GRANULARITY 1
106-
, INDEX "idx_operation_type" "operation_type" TYPE bloom_filter(0.01) GRANULARITY 1
101+
, "client_name" String Codec(ZSTD(1))
102+
, "client_version" String Codec(ZSTD(1))
103+
, "graphql_operation_name" String CODEC(ZSTD(1))
104+
, "graphql_operation_type" LowCardinality(String) CODEC(ZSTD(1))
105+
, "graphql_operation_document" String CODEC(ZSTD(1))
106+
, "subgraph_names" Array(LowCardinality(String)) CODEC(ZSTD(1))
107107
, INDEX "idx_duration" "duration" TYPE minmax GRANULARITY 1
108-
, INDEX "idx_subgraph_names" "subgraph_names" TYPE bloom_filter(0.01) GRANULARITY 1
109108
, INDEX "idx_http_status_code" "http_status_code" TYPE bloom_filter(0.01) GRANULARITY 1
110109
, INDEX "idx_http_method" "http_method" TYPE bloom_filter(0.01) GRANULARITY 1
111110
, INDEX "idx_http_host" "http_host" TYPE bloom_filter(0.01) GRANULARITY 1
112111
, INDEX "idx_http_route" "http_route" TYPE bloom_filter(0.01) GRANULARITY 1
113112
, INDEX "idx_http_url" "http_url" TYPE bloom_filter(0.01) GRANULARITY 1
113+
, INDEX "idx_client_name" "client_name" TYPE bloom_filter(0.01) GRANULARITY 1
114+
, INDEX "idx_client_version" "client_version" TYPE bloom_filter(0.01) GRANULARITY 1
115+
, INDEX "idx_graphql_operation_name" "graphql_operation_name" TYPE bloom_filter(0.01) GRANULARITY 1
116+
, INDEX "idx_graphql_operation_type" "graphql_operation_type" TYPE bloom_filter(0.01) GRANULARITY 1
117+
, INDEX "idx_subgraph_names" "subgraph_names" TYPE bloom_filter(0.01) GRANULARITY 1
114118
)
115119
ENGINE = MergeTree
116-
PARTITION BY toDate(timestamp)
120+
PARTITION BY toDate("timestamp")
117121
ORDER BY ("target_id", "timestamp")
118122
TTL toDateTime(timestamp) + toIntervalDay(365)
119123
SETTINGS
@@ -123,37 +127,41 @@ export const action: Action = async exec => {
123127

124128
await exec(`
125129
CREATE MATERIALIZED VIEW IF NOT EXISTS "otel_traces_normalized_mv" TO "otel_traces_normalized" (
126-
"trace_id" String
130+
, "target_id" LowCardinality(String)
131+
, "trace_id" String
127132
, "span_id" String
128133
, "timestamp" DateTime('UTC')
129-
, "operation_name" String
130-
, "operation_type" LowCardinality(String)
131-
, "target_id" LowCardinality(String)
132134
, "duration" UInt64
133-
, "operation_body" String
134-
, "subgraph_names" Array(String)
135135
, "http_status_code" String
136136
, "http_host" String
137137
, "http_method" String
138138
, "http_route" String
139139
, "http_url" String
140+
, "client_name" String
141+
, "client_version" String
142+
, "graphql_operation_name" String
143+
, "graphql_operation_type" LowCardinality(String)
144+
, "graphql_operation_document" String
145+
, "subgraph_names" Array(String)
140146
)
141147
AS (
142148
SELECT
143-
"TraceId" as "trace_id"
149+
toLowCardinality("SpanAttributes"['hive.target_id']) AS "target_id"
150+
, "TraceId" as "trace_id"
144151
, "SpanId" AS "span_id"
145152
, toDateTime("Timestamp", 'UTC') AS "timestamp"
146-
, "SpanAttributes"['graphql.operation.name'] AS operation_name
147-
, toLowCardinality("SpanAttributes"['graphql.operation.type']) AS "operation_type"
148-
, toLowCardinality("SpanAttributes"['hive.target_id']) AS "target_id"
149153
, "Duration" AS "duration"
150-
, "SpanAttributes"['graphql.operation.document'] AS "operation_body"
151-
, arrayMap(x -> toLowCardinality(x), splitByChar(',', "SpanAttributes"['subgraph.names'])) AS "subgraph_names"
152154
, "SpanAttributes"['http.status_code'] AS "http_status_code"
153155
, "SpanAttributes"['http.host'] AS "http_host"
154156
, "SpanAttributes"['http.method'] AS "http_method"
155157
, "SpanAttributes"['http.route'] AS "http_route"
156158
, "SpanAttributes"['http.url'] AS "http_url"
159+
, "SpanAttributes"['hive.client.name'] AS "client_name"
160+
, "SpanAttributes"['hive.client.version'] AS "client_version"
161+
, "SpanAttributes"['graphql.operation.name'] AS "graphql_operation_name"
162+
, toLowCardinality("SpanAttributes"['graphql.operation.type']) AS "graphql_operation_type"
163+
, "SpanAttributes"['graphql.operation.document'] AS "graphql_operation_document"
164+
, arrayMap(x -> toLowCardinality(x), splitByChar(',', "SpanAttributes"['hive.subgraph.names'])) AS "subgraph_names"
157165
FROM
158166
"otel_traces"
159167
WHERE

0 commit comments

Comments
 (0)