Open
Description
timescaledb toolkit is the latest from the main branch as of now (1.19.0-dev - beac6d5).
timescaledb is 2.17.0
when refreshing an aggregate, i get this error:
ERROR: called `Option::unwrap()` on a `None` value
CONTEXT: SQL statement "INSERT INTO _timescaledb_internal._materialized_hypertable_28 SELECT * FROM _timescaledb_internal._partial_view_28 AS I WHERE I.bar_start >= $1 AND I.bar_start < $2 ;"
SQL statement "CALL refresh_continuous_aggregate(p_aggregate_name, start_timestamp, end_timestamp)"
PL/pgSQL function refresh_aggregates(text,timestamp without time zone,timestamp without time zone,interval) line 7 at CALL
it is caused by this statement in the aggregate sql:
raw_mcv_agg(100, bid_price) FILTER (WHERE (bid_price <> (0)::double precision)) AS bid_price_freq
i tracked down the issue to one ticker that has only one record for the specified period and that record is filtered out by the filter clause. this is the complete simplified select:
SELECT ticker,
time_bucket('00:00:01'::interval, "timestamp") AS bar_start,
raw_mcv_agg(100, bid_price) FILTER (WHERE (bid_price <> (0)::double precision)) AS bid_price_freq
FROM ticks_bid_ask
WHERE "timestamp" >= '2024-06-03 04:00:00' and "timestamp" < '2024-06-03 05:00:00'
GROUP BY ticker, (time_bucket('00:00:01'::interval, "timestamp"))
ORDER BY ticker, (time_bucket('00:00:01'::interval, "timestamp"));
removing the filter clause makes the select work without issues.
so my guess is, when checking whether there are any records to be aggregated, the filter clause is ignored, which in this case results in no records being provided and crashing on the unwrap.
i did not notice this issue with timescaledb < 1.17.0 before, but i didn't test it now.