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

Avoid having to cast time arg for cagg policy #2387

Merged
merged 1 commit into from Sep 21, 2020

Conversation

pmwkaa
Copy link
Contributor

@pmwkaa pmwkaa commented Sep 14, 2020

This patch does a minor refactoring and adds a way to guess
interval argument type based on used cagg

Issue: #2286

@pmwkaa pmwkaa requested a review from a team as a code owner September 14, 2020 12:40
@pmwkaa pmwkaa requested review from k-rus, WireBaron and svenklemm and removed request for a team September 14, 2020 12:40
@codecov
Copy link

codecov bot commented Sep 14, 2020

Codecov Report

Merging #2387 into master will increase coverage by 0.14%.
The diff coverage is 95.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2387      +/-   ##
==========================================
+ Coverage   89.95%   90.10%   +0.14%     
==========================================
  Files         213      213              
  Lines       34354    34326      -28     
==========================================
+ Hits        30904    30928      +24     
+ Misses       3450     3398      -52     
Impacted Files Coverage Δ
src/catalog.h 100.00% <ø> (ø)
src/chunk_index.h 100.00% <ø> (ø)
src/dimension.c 95.41% <ø> (ø)
src/utils.c 80.05% <ø> (ø)
src/utils.h 44.44% <ø> (ø)
src/time_utils.c 98.12% <88.88%> (+0.04%) ⬆️
tsl/src/bgw_policy/continuous_aggregate_api.c 92.19% <96.42%> (+0.28%) ⬆️
src/bgw/job.c 95.07% <96.96%> (+0.28%) ⬆️
src/chunk_index.c 94.72% <100.00%> (-0.03%) ⬇️
tsl/src/fdw/deparse.c 63.34% <100.00%> (-0.12%) ⬇️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e1a00eb...14448fb. Read the comment docs.

static void
check_valid_interval(Oid dim_type, Oid interval_type, const char *str_msg)
static Datum
convert_interval_arg(Oid dim_type, Datum interval, Oid *interval_type, const char *str_msg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this conversion useful for other policies as well (e.g., retention)? I figured this would be in time_utils or policy_utils for use by all policies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought maybe to do that in another PR related to the retention policy.

@pmwkaa pmwkaa marked this pull request as draft September 15, 2020 12:31
@pmwkaa pmwkaa marked this pull request as ready for review September 16, 2020 12:36
@pmwkaa pmwkaa requested a review from a team September 16, 2020 12:36
\set ON_ERROR_STOP 1
SELECT add_continuous_aggregate_policy('max_mat_view_date', '2 day'::interval, '1 day'::interval , '1 day'::interval) as job_id \gset
SELECT add_continuous_aggregate_policy('max_mat_view_date', '2 day', '1 day', '1 day'::interval) as job_id \gset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Would be nice to get rid of the cast on schedule_interval too. Perhaps also for a separate PR?

Suggested change
SELECT add_continuous_aggregate_policy('max_mat_view_date', '2 day', '1 day', '1 day'::interval) as job_id \gset
SELECT add_continuous_aggregate_policy('max_mat_view_date', '2 days', '1 day', '1 day'::interval) as job_id \gset

@erimatnor erimatnor added the bgw The background worker subsystem, including the scheduler label Sep 18, 2020
Copy link
Contributor

@k-rus k-rus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
It might be useful to give short comment describing the function.
And I am not favour of reusing variable names, especially it is set to a different value.

@@ -41,6 +41,45 @@ subtract_interval_from_now(Oid timetype, const Interval *interval)
return res;
}

Datum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth do document this function as it is part of internal API, so it is clear what to expect from it and how to use it. Currently I cannot guess from the function name what to expect from it.

{
case 1:
/* Functions that take one input argument, e.g., the Date function */
arg = OidFunctionCall1(infuncid, arg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct that this is a reuse of variable arg, which first contains the original argument, and then assigned the converted argument? I suggest to use different variable and actually it will contain different object to my understanding.

}
/* If no explicit cast was done by the user, try to convert the argument
* to the time type used by the continuous aggregate. */
arg = ts_time_datum_convert_arg(arg, &argtype, timetype);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here, since arg will contain different object after the call. To avoid code changes, the original variable can be called arg_in.

Comment on lines +71 to +74
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid time argument"),
errhint("Time argument requires an explicit cast.")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to test this case? Codecov complains that it's not covered.

Copy link
Contributor Author

@pmwkaa pmwkaa Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most of those cases already covered by continuous agg refresh function tests, which are reusing the same functionality.

Copy link
Contributor

@k-rus k-rus Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess Codecov would not complain if it is covered ;) I searched that such error is never expected in our tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this case is actually possible right now, it was made more like a precaution in case new time functions will arrive in future versions I believe

This patch does a minor refactoring and adds a way to guess
interval argument type based on used cagg

Issue: timescale#2286
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bgw The background worker subsystem, including the scheduler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants