Druid syntax to group by time periods of an hour?

334 views
Skip to first unread message

Sofia Valdez

unread,
Jun 3, 2021, 1:17:19 PM6/3/21
to Druid User

I have the following columns: time, device, metric, value, count.

There are 3 devices: A, B, C. Each device has two metrics: 1, 2. And each metric has a "value" for that time stamp (float values).

For device A, metric 1, I want to get the average value for every hour within a certain time period (i.e. a certain day).

I'm having trouble figuring out how to write this into the query or how to call it from a python code (either using time series or groupby)?

I'd appreciate any suggestions/examples for this. Thanks!

Nishant Bangarwa

unread,
Jun 15, 2021, 3:00:24 AM6/15/21
to druid...@googlegroups.com
Hi Sofia,
Below is a sample SQL query that would probably work for your case, Hope it is helpful.

Select FLOOR("__time" to HOUR), avg(value) from datasource_name
WHERE "__time" BETWEEN 'start_day' AND 'end_day' AND device = 'A' AND metric = '1'
group by 1

--
Nishant Bangarwa

Co-founder & Head of Engineering

+91-9729200044 LinkedIn




--
You received this message because you are subscribed to the Google Groups "Druid User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to druid-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/druid-user/b1a35b2b-28c3-497e-a773-d6ff695e1b84n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages