|
| 1 | +DROP VIEW IF EXISTS raw_traces_v0; |
| 2 | +CREATE VIEW IF NOT EXISTS raw_traces_v0 SQL SECURITY INVOKER AS |
| 3 | + SELECT |
| 4 | + MIN(spans.start_time) AS start_time, |
| 5 | + MAX(spans.end_time) AS end_time, |
| 6 | + SUM(input_tokens) AS input_tokens, |
| 7 | + SUM(output_tokens) AS output_tokens, |
| 8 | + SUM(total_tokens) AS total_tokens, |
| 9 | + SUM(input_cost) AS input_cost, |
| 10 | + SUM(output_cost) AS output_cost, |
| 11 | + SUM(total_cost) AS total_cost, |
| 12 | + MAX(spans.end_time) - MIN(spans.start_time) AS duration, |
| 13 | + argMax(trace_metadata, length(trace_metadata)) AS metadata, |
| 14 | + anyIf(session_id, session_id != '<null>' AND session_id != '') AS session_id, |
| 15 | + anyIf(user_id, user_id != '<null>' AND user_id != '') AS user_id, |
| 16 | + CASE WHEN countIf(spans.status = 'error') > 0 THEN 'error' ELSE 'success' END AS status, |
| 17 | + anyIf(span_id, parent_span_id='00000000-0000-0000-0000-000000000000') AS top_span_id, |
| 18 | + anyIf(name, parent_span_id='00000000-0000-0000-0000-000000000000') AS top_span_name, |
| 19 | + anyIf(CASE |
| 20 | + WHEN span_type = 0 THEN 'DEFAULT' |
| 21 | + WHEN span_type = 1 THEN 'LLM' |
| 22 | + WHEN span_type = 3 THEN 'EXECUTOR' |
| 23 | + WHEN span_type = 4 THEN 'EVALUATOR' |
| 24 | + WHEN span_type = 5 THEN 'EVALUATION' |
| 25 | + WHEN span_type = 6 THEN 'TOOL' |
| 26 | + WHEN span_type = 7 THEN 'HUMAN_EVALUATOR' |
| 27 | + WHEN span_type = 8 THEN 'EVENT' |
| 28 | + ELSE 'UNKNOWN' |
| 29 | + END, parent_span_id='00000000-0000-0000-0000-000000000000') AS top_span_type, |
| 30 | + CASE WHEN countIf(span_type IN (3, 4, 5)) > 0 THEN 'EVALUATION' ELSE 'DEFAULT' END AS trace_type, |
| 31 | + arrayDistinct(arrayFlatten(arrayConcat(groupArray(tags_array)))) AS tags, |
| 32 | + trace_id id, |
| 33 | + project_id |
| 34 | + FROM spans |
| 35 | + WHERE project_id={project_id:UUID} AND spans.start_time>={start_time:DateTime64} AND spans.start_time<={end_time:DateTime64} |
| 36 | + GROUP BY id, project_id; |
| 37 | + |
| 38 | +DROP VIEW IF EXISTS spans_v0; |
| 39 | +CREATE VIEW IF NOT EXISTS spans_v0 SQL SECURITY INVOKER AS |
| 40 | + SELECT |
| 41 | + span_id, |
| 42 | + name, |
| 43 | + CASE |
| 44 | + WHEN span_type = 0 THEN 'DEFAULT' |
| 45 | + WHEN span_type = 1 THEN 'LLM' |
| 46 | + WHEN span_type = 3 THEN 'EXECUTOR' |
| 47 | + WHEN span_type = 4 THEN 'EVALUATOR' |
| 48 | + WHEN span_type = 5 THEN 'EVALUATION' |
| 49 | + WHEN span_type = 6 THEN 'TOOL' |
| 50 | + WHEN span_type = 7 THEN 'HUMAN_EVALUATOR' |
| 51 | + WHEN span_type = 8 THEN 'EVENT' |
| 52 | + ELSE 'UNKNOWN' |
| 53 | + END AS span_type, |
| 54 | + start_time, |
| 55 | + end_time, |
| 56 | + end_time - start_time AS duration, |
| 57 | + input_cost, |
| 58 | + output_cost, |
| 59 | + total_cost, |
| 60 | + input_tokens, |
| 61 | + output_tokens, |
| 62 | + total_tokens, |
| 63 | + request_model, |
| 64 | + response_model, |
| 65 | + model, |
| 66 | + trace_id, |
| 67 | + provider, |
| 68 | + path, |
| 69 | + input, |
| 70 | + output, |
| 71 | + CASE |
| 72 | + WHEN status = 'error' THEN 'error' |
| 73 | + WHEN status = 'success' THEN 'success' |
| 74 | + ELSE 'success' |
| 75 | + END AS status, |
| 76 | + parent_span_id, |
| 77 | + attributes, |
| 78 | + tags_array as tags |
| 79 | + FROM spans |
| 80 | + WHERE project_id={project_id:UUID}; |
0 commit comments