Hello, how can I select 2 fields and group them wi...
# support
r
Hello, how can I select 2 fields and group them with a clickhouse query? I'm trying this but the status is not shown in the graph
Copy code
SELECT
      toStartOfInterval(timestamp, INTERVAL 1 MINUTE) AS interval,
      stringTagMap['net.host.name'] AS host,
      numberTagMap['http.status_code'] as http_status,
      count() AS value 
FROM signoz_traces.distributed_signoz_index_v2
WHERE timestamp > {{.start_datetime}} AND timestamp < {{.end_datetime}}
      AND (stringTagMap['net.host.name'] = 'some_host' OR stringTagMap['net.host.name'] = 'other_host')
      AND stringTagMap['http.target'] = '/api/webhooks/1'
GROUP BY (host, http_status), interval
ORDER BY host ASC, http_status ASC, interval
I'm not seeing the
http_status
in the graph altough I'm selecting it
I'm trying to use this field from the trace:
Seems that the http_status is not a tag? 🤔 not sure
s
Copy code
SELECT
      count() AS value,
      toStartOfInterval(timestamp, INTERVAL 1 MINUTE) AS interval,
      stringTagMap['net.host.name'] AS host,
      numberTagMap['http.status_code'] as http_status
FROM signoz_traces.distributed_signoz_index_v2
WHERE timestamp > {{.start_datetime}} AND timestamp < {{.end_datetime}}
      AND (stringTagMap['net.host.name'] = 'some_host' OR stringTagMap['net.host.name'] = 'other_host')
      AND stringTagMap['http.target'] = '/api/webhooks/1'
GROUP BY (host, http_status), interval
ORDER BY host ASC, http_status ASC, interval
Try this instead
r
What's the difference? Just the order of the selecte fields?
Didn't work
s
I think there is conflict between using the value vs http status code for the chart value since both are numbers. The reorder should have worked. I will check. You can also try
toString
explicitly since you are not doing anything with status code.
r
The reorder left me with the graph I shared. How do I use the
toString
thing?
s
Copy code
SELECT
      count() AS value,
      toStartOfInterval(timestamp, INTERVAL 1 MINUTE) AS interval,
      stringTagMap['net.host.name'] AS host,
      toString(numberTagMap['http.status_code']) as http_status
FROM signoz_traces.distributed_signoz_index_v2
WHERE timestamp > {{.start_datetime}} AND timestamp < {{.end_datetime}}
      AND (stringTagMap['net.host.name'] = 'some_host' OR stringTagMap['net.host.name'] = 'other_host')
      AND stringTagMap['http.target'] = '/api/webhooks/1'
GROUP BY (host, http_status), interval
ORDER BY host ASC, http_status ASC, interval
r
Yes! That worked