timescaledb-toolkit icon indicating copy to clipboard operation
timescaledb-toolkit copied to clipboard

[Bug]: `interpolated_delta` doesn't handle `NULL` summaries

Open darwin67 opened this issue 2 years ago • 2 comments

What type of bug is this?

Incorrect result

What subsystems and features are affected?

Query executor

What happened?

When using interpolated_delta with time_bucket_gapfill, the returned summaries could result in NULL.

Instead of passing on the NULL like delta does, interpolated_delta will error. error

When ran with delta, it works fine. delta

TimescaleDB version affected

2.10.2

PostgreSQL version used

15.2

What operating system did you use?

Arch 6.1.39-3-lts

What installation method did you use?

Docker

What platform did you run on?

Not applicable

Relevant log output and stack trace

No response

How can we reproduce the bug?

create table if not exists test (
  time timestamptz not null,
  val double precision
);

insert into test
  (time, val)
values
  (CURRENT_TIMESTAMP - interval '2 hours', 0),
  (CURRENT_TIMESTAMP - interval '16 minutes', 3),
  (CURRENT_TIMESTAMP - interval '15 minutes', 10),
  (CURRENT_TIMESTAMP - interval '12 minutes', 100),
  (CURRENT_TIMESTAMP - interval '10 minutes', 200),
  (CURRENT_TIMESTAMP - interval '9 minutes', 210),
  (CURRENT_TIMESTAMP - interval '8 minutes', 3),
  (CURRENT_TIMESTAMP - interval '5 minutes', 10),
  (CURRENT_TIMESTAMP - interval '3 minutes', 20);

with agg as (
  select
    counter_agg(time, val) as summary,
    time_bucket_gapfill(interval '5 minutes', time) as bucket
  from test
  where time >= now() - interval '1 day' and time <= now()
  group by bucket
)
select
  bucket,
  interpolated_delta(summary, bucket, interval '5 minutes', null, null)
from agg
order by bucket desc

darwin67 avatar Aug 16 '23 17:08 darwin67

Also side note, the docs says interpolated_delta's last 2 arguments are optional but that's not the case, and requires to put NULL explicitly. probably just a matter of adding a function that accepts 3 args instead of 5.

darwin67 avatar Aug 17 '23 01:08 darwin67

I encountered the same annoying error, see here https://github.com/timescale/timescaledb-toolkit/issues/634

jledentu avatar Sep 06 '23 12:09 jledentu