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

Remove two_buckets_to_str() procedure #3334

Merged
merged 1 commit into from Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 1 addition & 30 deletions tsl/src/bgw_policy/continuous_aggregate_api.c
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
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