-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvement: Add toStartOfInterval() function #1201
Comments
Hello again! :) I would like to add one more example which illustrates what I want to see in the nearest future (I hope). TimeScale database offers SELECT
time_bucket('5 minutes', time) AS period,
avg(value) AS avgValue
FROM history
GROUP BY period Finally, I expect behaviour like in the example below. Table create table history
(
sensorId String,
date Date default toDate(time),
time DateTime,
value Float64
)
ENGINE = MergeTree(date, (sensorId, date, time), 8192) Request SELECT
toStartOfInterval(time, 5, 'minutes') AS period,
avg(value) AS avgValue
FROM history
GROUP BY period
ORDER BY period DESC
LIMIT 10 Result
P.s. Now I need to do an aggregation for every 1, 5, 10, and etc. minutes and think about some workaround to do that. Maybe you have some ideas how to do it now? Also I'm interesting is it real to implement described functionality? If 'yes' then when we can expect this? |
It's very easy to workaround. Use that as a template
replace 300 with your time interval (in seconds). But that question is quite popular, may be the shortcut function should be added. |
Maybe the function like |
@sundy-li I don't mind. I just used the existing 'naming convention'. |
Implemented syntax |
Hello!
ClickHouse
has a good kind of functions liketoStartOf*(time)
which round down a time to the specified part (minute, hour, day and etc.). It's quite enough but it would be good if there were an universal function which could accept an interval (in seconds, for example).where
time
- a DateTime column,interval
- an integer time interval for rounding, units - an optional time unit (by defaultseconds
, possible values:seconds
,minutes
,hours
,days
and etc.).For example, the function
toStartOfFiveMinute(time)
could be represented astoStartOfInterval(time, 5, 'minutes')
. And consequently we could group our data by user defined time interval.I think it will be powerful and useful feature to analyze time-series data.
The text was updated successfully, but these errors were encountered: