Skip to content

Commit 6932966

Browse files
carderneTrigger.dev RepoOps
authored andcommitted
perf(clickhouse): drop the task event attributes_input column
Removes the transitional attributes input column from the task events table now that writers serialize attributes themselves. Mono-RevId: eea5932cc8936c5a12f20160ad44d94f4808de1b
1 parent 3f67c71 commit 6932966

2 files changed

Lines changed: 25 additions & 66 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- +goose Up
2+
3+
-- Every writer now supplies attributes_text directly, so the DEFAULT bridge and
4+
-- the ephemeral attributes_input column it replaced are no longer needed. Both
5+
-- statements are metadata-only. Apply only once no writer relies on the
6+
-- computed default.
7+
ALTER TABLE trigger_dev.task_events_v2
8+
MODIFY COLUMN IF EXISTS attributes_text REMOVE DEFAULT;
9+
10+
ALTER TABLE trigger_dev.task_events_v2
11+
DROP COLUMN IF EXISTS attributes_input;
12+
13+
-- +goose Down
14+
15+
ALTER TABLE trigger_dev.task_events_v2
16+
ADD COLUMN IF NOT EXISTS attributes_input JSON
17+
EPHEMERAL defaultValueOfTypeName('JSON')
18+
CODEC(ZSTD(1))
19+
AFTER attributes;
20+
21+
ALTER TABLE trigger_dev.task_events_v2
22+
MODIFY COLUMN IF EXISTS attributes_text String
23+
DEFAULT toJSONString(attributes);

internal-packages/clickhouse/src/taskEvents.test.ts

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -101,78 +101,14 @@ describe("task events v2", () => {
101101
}
102102
);
103103

104-
clickhouseTest(
105-
"computes attributes_text for a writer that omits it",
106-
async ({ clickhouseContainer }) => {
107-
const ch = new ClickHouse({ url: clickhouseContainer.getConnectionUrl(), name: "test" });
108-
const spanId = "span_computed_attributes";
109-
110-
// An older writer that only sends the JSON column still gets attributes_text
111-
// from the DEFAULT expression, so both writer generations can coexist.
112-
const insert = ch.writer.insertUnsafe<Record<string, unknown>>({
113-
name: "insertTaskEventsV2WithoutAttributesText",
114-
table: "trigger_dev.task_events_v2",
115-
columns: [
116-
"environment_id",
117-
"organization_id",
118-
"project_id",
119-
"task_identifier",
120-
"run_id",
121-
"start_time",
122-
"duration",
123-
"trace_id",
124-
"span_id",
125-
"parent_span_id",
126-
"message",
127-
"kind",
128-
"status",
129-
"attributes",
130-
"metadata",
131-
"expires_at",
132-
],
133-
settings: { enable_json_type: 1 },
134-
});
135-
136-
const [insertError] = await insert([
137-
{
138-
...baseEvent(spanId),
139-
attributes: { z: 1, a: "hello" },
140-
},
141-
]);
142-
expect(insertError).toBeNull();
143-
144-
const [readError, rows] = await readAttributesText(ch)({
145-
environmentId: "env_attributes_text",
146-
spanId,
147-
});
148-
expect(readError).toBeNull();
149-
expect(rows).toEqual([
150-
{
151-
attributes_text: '{"a":"hello","z":1}',
152-
attributes_json: '{"a":"hello","z":1}',
153-
has_inserted_at: 1,
154-
},
155-
]);
156-
}
157-
);
158-
159-
clickhouseTest("attributes_text is a DEFAULT column", async ({ clickhouseContainer }) => {
104+
clickhouseTest("attributes_text is a plain stored column", async ({ clickhouseContainer }) => {
160105
const ch = new ClickHouse({ url: clickhouseContainer.getConnectionUrl(), name: "test" });
161106

162107
const [columnError, columns] = await readColumnKinds(ch)({});
163108
expect(columnError).toBeNull();
164109
expect(columns).toEqual([
165110
{ name: "attributes", default_kind: "", default_expression: "" },
166-
{
167-
name: "attributes_input",
168-
default_kind: "EPHEMERAL",
169-
default_expression: "defaultValueOfTypeName('JSON')",
170-
},
171-
{
172-
name: "attributes_text",
173-
default_kind: "DEFAULT",
174-
default_expression: "toJSONString(attributes)",
175-
},
111+
{ name: "attributes_text", default_kind: "", default_expression: "" },
176112
]);
177113
});
178114

0 commit comments

Comments
 (0)