@@ -4,6 +4,7 @@ const { standardBuilder } = require('./shared')
4
4
* @type {ProcessFn }
5
5
*/
6
6
const processFn = ( sel , ctx ) => {
7
+ const _in = ctx . isCluster ? 'global in' : 'in'
7
8
const table = ! ctx . isCluster ? ctx . tracesTable : ctx . tracesDistTable
8
9
const withMain = new Sql . With ( 'index_grouped' , sel )
9
10
const withTraceIds = new Sql . With ( 'trace_ids' , ( new Sql . Select ( ) )
@@ -17,18 +18,18 @@ const processFn = (sel, ctx) => {
17
18
. with ( withMain , withTraceIds , withTraceIdsSpanIds )
18
19
. select (
19
20
[ new Sql . Raw ( 'lower(hex(traces.trace_id))' ) , 'trace_id' ] ,
20
- [ new Sql . Raw ( `arrayMap(x -> lower(hex(x)), groupArrayIf(traces.span_id, (traces.trace_id, traces.span_id) IN ${ new Sql . WithReference ( withTraceIdsSpanIds ) } ))` ) , 'span_id' ] ,
21
- [ new Sql . Raw ( `groupArrayIf(traces.duration_ns, (traces.trace_id, traces.span_id) IN ${ new Sql . WithReference ( withTraceIdsSpanIds ) } )` ) , 'duration' ] ,
22
- [ new Sql . Raw ( `groupArrayIf(traces.timestamp_ns, (traces.trace_id, traces.span_id) IN ${ new Sql . WithReference ( withTraceIdsSpanIds ) } )` ) , 'timestamp_ns' ] ,
21
+ [ new Sql . Raw ( `arrayMap(x -> lower(hex(x)), groupArrayIf(traces.span_id, (traces.trace_id, traces.span_id) ${ _in } ${ new Sql . WithReference ( withTraceIdsSpanIds ) } ))` ) , 'span_id' ] ,
22
+ [ new Sql . Raw ( `groupArrayIf(traces.duration_ns, (traces.trace_id, traces.span_id) ${ _in } ${ new Sql . WithReference ( withTraceIdsSpanIds ) } )` ) , 'duration' ] ,
23
+ [ new Sql . Raw ( `groupArrayIf(traces.timestamp_ns, (traces.trace_id, traces.span_id) ${ _in } ${ new Sql . WithReference ( withTraceIdsSpanIds ) } )` ) , 'timestamp_ns' ] ,
23
24
[ new Sql . Raw ( 'min(traces.timestamp_ns)' ) , 'start_time_unix_nano' ] ,
24
25
[ new Sql . Raw (
25
26
'toFloat64(max(traces.timestamp_ns + traces.duration_ns) - min(traces.timestamp_ns)) / 1000000'
26
27
) , 'duration_ms' ] ,
27
28
[ new Sql . Raw ( 'argMin(traces.name, traces.timestamp_ns)' , 'root_service_name' ) , 'root_service_name' ] ,
28
- [ new Sql . Raw ( `groupArrayIf(base64Encode(traces.payload), (traces.trace_id, traces.span_id) IN ${ new Sql . WithReference ( withTraceIdsSpanIds ) } )` ) , 'payload' ] ,
29
- [ new Sql . Raw ( `groupArrayIf(traces.payload_type, (traces.trace_id, traces.span_id) IN ${ new Sql . WithReference ( withTraceIdsSpanIds ) } )` ) , 'payload_type' ]
29
+ [ new Sql . Raw ( `groupArrayIf(base64Encode(traces.payload), (traces.trace_id, traces.span_id) ${ _in } ${ new Sql . WithReference ( withTraceIdsSpanIds ) } )` ) , 'payload' ] ,
30
+ [ new Sql . Raw ( `groupArrayIf(traces.payload_type, (traces.trace_id, traces.span_id) ${ _in } ${ new Sql . WithReference ( withTraceIdsSpanIds ) } )` ) , 'payload_type' ]
30
31
) . from ( [ table , 'traces' ] ) . where ( Sql . And (
31
- new Sql . In ( new Sql . Raw ( 'traces.trace_id' ) , 'in' , new Sql . WithReference ( withTraceIds ) )
32
+ new Sql . In ( new Sql . Raw ( 'traces.trace_id' ) , _in , new Sql . WithReference ( withTraceIds ) )
32
33
) ) . groupBy ( 'traces.trace_id' )
33
34
. orderBy ( [ 'start_time_unix_nano' , 'desc' ] )
34
35
}
0 commit comments