Using ClickHouse for time-series data

1,544 views
Skip to first unread message

Alex Kurkin

unread,
Jun 20, 2016, 4:07:52 AM6/20/16
to ClickHouse
hey guys,
is there any example of working with time-series data?

For example, to start with, something as simple as elastic's date_histogram aggregation 

I've seen the timeSlots function, but there's no usage example, I'd appreciate any hints. 

Thanks,
Alex

man...@gmail.com

unread,
Jun 20, 2016, 5:02:18 PM6/20/16
to ClickHouse
You could use functions https://clickhouse.yandex/reference_en.html#Functions%20for%20working%20with%20dates%20and%20times
to transform and round dates and datetimes.

Example: https://gist.github.com/alexey-milovidov/6fd9246ce44b48345bee3a0df3da5ab0

When rounding to small intervals (for example, 5 seconds), you could convert DateTime to UInt32, then use intDiv function, then multiply and convert back.

Example: https://gist.github.com/alexey-milovidov/2dee968eb95df63b271208f89d3697c3


Alex Kurkin

unread,
Jun 21, 2016, 1:38:31 PM6/21/16
to ClickHouse
Fantastic, the 5-second example is brilliant, exactly what I was looking for. 

Thanks much for spending time to explain this.

Alex

Burak Emre Kabakcı

unread,
Jun 21, 2016, 11:13:51 PM6/21/16
to ClickHouse
For small intervals, it works but for bigger intervals such as week, month and year a date truncation function would be great. Here is the Postgresql implementation: https://www.postgresql.org/docs/8.4/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
Reply all
Reply to author
Forward
0 new messages