Skip to content

Commit

Permalink
Remove two_buckets_to_str() procedure
Browse files Browse the repository at this point in the history
The two_buckets_to_str() procedure relies on fixed bucket_width
which is not going to be fixed in the future. Since the procedure
is used only to generate a hint that accompanies an error message,
the simplest solution is to remove this procedure. We can improve
error messages later if that would be necessary.
  • Loading branch information
afiskon committed Jun 14, 2021
1 parent f1ae646 commit 3b93695
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 39 deletions.
31 changes: 1 addition & 30 deletions tsl/src/bgw_policy/continuous_aggregate_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,32 +342,6 @@ interval_to_int64(Datum interval, Oid type)
return 0;
}

static const char *
two_buckets_to_str(const ContinuousAgg *cagg)
{
Oid bucket_type;
Oid outfuncid;
int64 two_buckets;
Datum min_range;
bool isvarlena;

if (IS_TIMESTAMP_TYPE(cagg->partition_type))
bucket_type = INTERVALOID;
else
bucket_type = cagg->partition_type;

two_buckets = ts_time_saturating_add(cagg->data.bucket_width,
cagg->data.bucket_width,
cagg->partition_type);

min_range = ts_internal_to_interval_value(two_buckets, bucket_type);

getTypeOutputInfo(bucket_type, &outfuncid, &isvarlena);
Assert(!isvarlena);

return DatumGetCString(OidFunctionCall1(outfuncid, min_range));
}

/*
* Enforce that a policy has a refresh window of at least two buckets to
* ensure we materialize at least one bucket each run.
Expand Down Expand Up @@ -401,10 +375,7 @@ validate_window_size(const ContinuousAgg *cagg, const CaggPolicyConfig *config)
errmsg("policy refresh window too small"),
errdetail("The start and end offsets must cover at least"
" two buckets in the valid time range of type \"%s\".",
format_type_be(cagg->partition_type)),
errhint("Use a start and end offset that specifies"
" a window of at least %s.",
two_buckets_to_str(cagg))));
format_type_be(cagg->partition_type))));
}

static void
Expand Down
9 changes: 0 additions & 9 deletions tsl/test/expected/continuous_aggs_policy.out
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@ HINT: Use time interval of type integer with the continuous aggregate.
SELECT add_continuous_aggregate_policy('mat_m1', 5, 10, '1h'::interval);
ERROR: policy refresh window too small
DETAIL: The start and end offsets must cover at least two buckets in the valid time range of type "integer".
HINT: Use a start and end offset that specifies a window of at least 2.
--refresh window less than two buckets
SELECT add_continuous_aggregate_policy('mat_m1', 11, 10, '1h'::interval);
ERROR: policy refresh window too small
DETAIL: The start and end offsets must cover at least two buckets in the valid time range of type "integer".
HINT: Use a start and end offset that specifies a window of at least 2.
SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval) as job_id \gset
--adding again should warn/error
SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>false);
Expand Down Expand Up @@ -165,20 +163,16 @@ HINT: Use time interval with a continuous aggregate using timestamp-based time
SELECT add_continuous_aggregate_policy('max_mat_view_date', '1 day'::interval, '2 days'::interval , '1 day'::interval) ;
ERROR: policy refresh window too small
DETAIL: The start and end offsets must cover at least two buckets in the valid time range of type "date".
HINT: Use a start and end offset that specifies a window of at least @ 14 days.
--interval less than two buckets
SELECT add_continuous_aggregate_policy('max_mat_view_date', '7 days', '1 day', '1 day'::interval);
ERROR: policy refresh window too small
DETAIL: The start and end offsets must cover at least two buckets in the valid time range of type "date".
HINT: Use a start and end offset that specifies a window of at least @ 14 days.
SELECT add_continuous_aggregate_policy('max_mat_view_date', '14 days', '1 day', '1 day'::interval);
ERROR: policy refresh window too small
DETAIL: The start and end offsets must cover at least two buckets in the valid time range of type "date".
HINT: Use a start and end offset that specifies a window of at least @ 14 days.
SELECT add_continuous_aggregate_policy('max_mat_view_date', '13 days', '-10 hours', '1 day'::interval);
ERROR: policy refresh window too small
DETAIL: The start and end offsets must cover at least two buckets in the valid time range of type "date".
HINT: Use a start and end offset that specifies a window of at least @ 14 days.
\set VERBOSITY terse
\set ON_ERROR_STOP 1
-- Negative start offset gives two bucket window:
Expand Down Expand Up @@ -256,11 +250,9 @@ SELECT remove_continuous_aggregate_policy('max_mat_view_timestamp');
SELECT add_continuous_aggregate_policy('max_mat_view_timestamp', '1000000 years', '900000 years' , '1 h'::interval);
ERROR: policy refresh window too small
DETAIL: The start and end offsets must cover at least two buckets in the valid time range of type "timestamp without time zone".
HINT: Use a start and end offset that specifies a window of at least @ 14 days.
SELECT add_continuous_aggregate_policy('max_mat_view_timestamp', '301 days', '10 months' , '1 h'::interval);
ERROR: policy refresh window too small
DETAIL: The start and end offsets must cover at least two buckets in the valid time range of type "timestamp without time zone".
HINT: Use a start and end offset that specifies a window of at least @ 14 days.
\set VERBOSITY terse
\set ON_ERROR_STOP 1
SELECT add_continuous_aggregate_policy('max_mat_view_timestamp', '15 days', '1 h'::interval , '1 h'::interval) as job_id \gset
Expand Down Expand Up @@ -325,7 +317,6 @@ ERROR: smallint out of range
SELECT add_continuous_aggregate_policy('mat_smallint', 5::smallint, 10::smallint , '1 h'::interval) as job_id \gset
ERROR: policy refresh window too small
DETAIL: The start and end offsets must cover at least two buckets in the valid time range of type "smallint".
HINT: Use a start and end offset that specifies a window of at least 2.
\set VERBOSITY terse
\set ON_ERROR_STOP 1
SELECT add_continuous_aggregate_policy('mat_smallint', 15::smallint, 0::smallint , '1 h'::interval) as job_id \gset
Expand Down

0 comments on commit 3b93695

Please sign in to comment.