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

time_weight average with null values gives an error

Open pacmanmati opened this issue 3 years ago • 0 comments

Relevant system information:

  • OS: macOS Monterey 12.0.1
  • PostgreSQL version (output of SELECT version();): 14.0
  • TimescaleDB Toolkit version (output of \dx timescaledb_toolkit in psql): 1.4
  • Installation method: docker

Describe the bug When performing a time weighted average on a bucket beginning with null data, the query fails and gives an error.

To Reproduce

create table example (
	time timestamptz,
	val int
);

insert into example values
	('2021-11-20 9:00', null),
	('2021-11-20 9:10', null),
	('2021-11-20 9:20', 1.0);

select 
	time_bucket('60 minute', time) as _time,
	average(time_weight('LINEAR', time, val))
from example
group by time_bucket('60 minute', time);

Expected behavior It returns an average of 1.

Actual behavior Receive an error upon running the query:

SQL Error [XX000]: ERROR: returned Datum was NULL
  Where: extension/src/time_weighted_average.rs:109:1

pacmanmati avatar Dec 20 '21 11:12 pacmanmati