Skip to content
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

Rolling window function's alternative support #138

Open
aayush0310 opened this issue May 13, 2021 · 2 comments
Open

Rolling window function's alternative support #138

aayush0310 opened this issue May 13, 2021 · 2 comments
Labels
feature-request And area of analysis that could be made easier

Comments

@aayush0310
Copy link

It would be nice if we can use rolling window functions on continuous aggregate.
If not rolling functions directly , there can be a workaround which can provide the similar functionality.
Just to give you more context I was trying to run a query
the query is -

create view public.test As
      -- with (timescaledb.continuous) As
       select time_bucket('3600',"timestamp") as bucket,
             partition_id,
             avg(hr) as avg_hr,
             avg(avg_rest_hr) as avg_rest
             from (
                   select "timestamp" ,
                   partition_id ,
                   hr,
                   avg(hr) over(partition by partition_id rows between 6 preceding and current row) as avg_rest_hr
                   from vitals_measurement_data vmd
             ) d
       group by bucket , partition_id

this works fine if I don't use continuous aggregates,
but as soon as I uncomment timescaledb.continuous , the query fails.

Some additional context or reference
@davidkohn88 mentioned in the slack community
to get a true average with that you'll have to use sum() and count() in order to do that properly.

@aayush0310 aayush0310 added the feature-request And area of analysis that could be made easier label May 13, 2021
@davidkohn88
Copy link
Contributor

Hey @aayush0310

We're beginning some work on this, you can see some of our thoughts here: https://github.com/timescale/timescale-analytics/blob/stats-agg/docs/rolling_average_api_working.md

I'm not 100% sure I understand what you're trying to accomplish with that query, can you explain exactly what the data looks like and what you're trying to accomplish? is the data already an hourly aggregate and you're going for the 6 hours preceding as a rolling number?

@davidkohn88 davidkohn88 mentioned this issue May 25, 2021
@JLockerman
Copy link
Contributor

we added stats agg to solve this. It wants some more testing esp fuzzing against postgres's stats functions before stabilization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request And area of analysis that could be made easier
Projects
None yet
Development

No branches or pull requests

3 participants