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

raw_mcv_agg() ERROR: called Option::unwrap() on a None value when filter clause is used #822

Open
fordfrog opened this issue Oct 24, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@fordfrog
Copy link

fordfrog commented Oct 24, 2024

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.

@fordfrog fordfrog added the bug Something isn't working label Oct 24, 2024
@fordfrog
Copy link
Author

issue #815 is probably related

@fordfrog
Copy link
Author

so i tried the patch from the mentioned issue but it didn't solve my issue:

# call refresh_continuous_aggregate('public.tick_market_bars_s1', '2024-06-03 04:00:00', '2024-06-03 04:10:00');
ERROR:  bytes_ is null
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 ;"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant