Skip to content

Commit 7135b71

Browse files
committed
Do the text query in ClickHouse
1 parent 76b3085 commit 7135b71

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

apps/webapp/app/services/runsRepository/clickhouseRunsRepository.server.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,24 @@ export class ClickHouseRunsRepository implements IRunsRepository {
195195
queryBuilder.where("created_at <= fromUnixTimestamp64Milli({to: Int64})", { to: options.to });
196196
}
197197

198+
// Filter by query (case-insensitive contains search)
199+
if (options.query && options.query.trim().length > 0) {
200+
queryBuilder.where("positionCaseInsensitiveUTF8(tag, {query: String}) > 0", {
201+
query: options.query,
202+
});
203+
}
204+
205+
// Add ordering and pagination
206+
queryBuilder.orderBy("tag ASC").limit(options.limit);
207+
198208
const [queryError, result] = await queryBuilder.execute();
199209

200210
if (queryError) {
201211
throw queryError;
202212
}
203213

204-
if (result.length === 0) {
205-
return {
206-
tags: [],
207-
};
208-
}
209-
210214
return {
211-
tags: result.flatMap((row) => row.tags),
215+
tags: result.map((row) => row.tag),
212216
};
213217
}
214218
}

internal-packages/clickhouse/src/taskRuns.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,17 @@ export function getTaskRunsCountQueryBuilder(ch: ClickhouseReader, settings?: Cl
115115
});
116116
}
117117

118+
export const TaskRunTagsQueryResult = z.object({
119+
tag: z.string(),
120+
});
121+
122+
export type TaskRunTagsQueryResult = z.infer<typeof TaskRunTagsQueryResult>;
123+
118124
export function getTaskRunTagsQueryBuilder(ch: ClickhouseReader, settings?: ClickHouseSettings) {
119125
return ch.queryBuilder({
120126
name: "getTaskRunTags",
121-
baseQuery: "SELECT DISTINCT tags FROM trigger_dev.task_runs_v2",
122-
schema: z.object({
123-
tags: z.array(z.string()),
124-
}),
127+
baseQuery: "SELECT DISTINCT arrayJoin(tags) as tag FROM trigger_dev.task_runs_v2",
128+
schema: TaskRunTagsQueryResult,
125129
settings,
126130
});
127131
}

0 commit comments

Comments
 (0)