Skip to content

Commit

Permalink
Allow changing real-time flag on deprecated CAggs
Browse files Browse the repository at this point in the history
PR timescale#6798 prevents the usage of time_bucket_ng in CAgg definitions.
However, flipping the real-time functionality should still be possible.
  • Loading branch information
jnidzwetzki committed Apr 18, 2024
1 parent ecf6bea commit 793aa09
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
9 changes: 7 additions & 2 deletions tsl/src/continuous_aggs/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,13 @@ caggtimebucket_validate(CAggTimebucketInfo *tbinfo, List *groupClause, List *tar
continue;
}

/* Do we have a bucketing function that is not allowed in the CAgg definition */
if (!function_allowed_in_cagg_definition(fe->funcid))
/* Do we have a bucketing function that is not allowed in the CAgg definition?
*
* This is only validated upon creation. If an older TSDB version has allowed us to use
* the function and it's now removed from the list of allowed functions, we should not
* error out (e.g., materialized_only setting is changed on a CAgg that uses the
* deprecated time_bucket_ng function). */
if (is_cagg_create && !function_allowed_in_cagg_definition(fe->funcid))
{
if (IS_DEPRECATED_BUCKET_FUNC(finfo))
{
Expand Down
2 changes: 1 addition & 1 deletion tsl/src/continuous_aggs/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ cagg_flip_realtime_view_definition(ContinuousAgg *agg, Hypertable *mat_ht)
agg->data.finalized,
NameStr(agg->data.user_view_schema),
NameStr(agg->data.user_view_name),
true);
false);

/* Flip */
agg->data.materialized_only = !agg->data.materialized_only;
Expand Down
2 changes: 1 addition & 1 deletion tsl/src/continuous_aggs/repair.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ cagg_rebuild_view_definition(ContinuousAgg *agg, Hypertable *mat_ht, bool force_
finalized,
NameStr(agg->data.user_view_schema),
NameStr(agg->data.user_view_name),
true);
false);

mattablecolumninfo_init(&mattblinfo, copyObject(direct_query->groupClause));
fqi.finalized = finalized;
Expand Down
3 changes: 3 additions & 0 deletions tsl/test/expected/exp_cagg_next_gen.out
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,8 @@ FROM _timescaledb_catalog.continuous_aggs_bucket_function ORDER BY 1;
timescaledb_experimental.time_bucket_ng(interval,timestamp without time zone) | @ 1 mon | | | f
(2 rows)

-- Try to toggle realtime feature on existing CAgg using timescaledb_experimental.time_bucket_ng
ALTER MATERIALIZED VIEW conditions_summary_monthly SET (timescaledb.materialized_only=false);
ALTER MATERIALIZED VIEW conditions_summary_monthly SET (timescaledb.materialized_only=true);
\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE test WITH (FORCE);
4 changes: 4 additions & 0 deletions tsl/test/sql/exp_cagg_next_gen.sql
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,9 @@ WITH NO DATA;
SELECT bucket_func, bucket_width, bucket_origin, bucket_timezone, bucket_fixed_width
FROM _timescaledb_catalog.continuous_aggs_bucket_function ORDER BY 1;

-- Try to toggle realtime feature on existing CAgg using timescaledb_experimental.time_bucket_ng
ALTER MATERIALIZED VIEW conditions_summary_monthly SET (timescaledb.materialized_only=false);
ALTER MATERIALIZED VIEW conditions_summary_monthly SET (timescaledb.materialized_only=true);

\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE test WITH (FORCE);

0 comments on commit 793aa09

Please sign in to comment.