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
Fix sub-second intervals in hierarchical caggs #5304
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@svenklemm, @akuzm: please review this pull request.
|
konskov
force-pushed
the
cagg_on_cagg_millis_micros
branch
2 times, most recently
from
February 10, 2023 14:47
d6459ba
to
51c7dae
Compare
Codecov Report
@@ Coverage Diff @@
## main #5304 +/- ##
==========================================
- Coverage 90.70% 90.67% -0.03%
==========================================
Files 227 227
Lines 52589 52584 -5
==========================================
- Hits 47702 47683 -19
- Misses 4887 4901 +14
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
konskov
force-pushed
the
cagg_on_cagg_millis_micros
branch
from
February 10, 2023 15:30
51c7dae
to
20bd957
Compare
akuzm
reviewed
Feb 10, 2023
RafiaSabih
approved these changes
Feb 22, 2023
@konskov isn't easier to use diff --git a/tsl/src/continuous_aggs/create.c b/tsl/src/continuous_aggs/create.c
index 6dc311712..349f7fa86 100644
--- a/tsl/src/continuous_aggs/create.c
+++ b/tsl/src/continuous_aggs/create.c
@@ -58,6 +58,7 @@
#include <utils/typcache.h>
#include <optimizer/prep.h>
+#include "math.h"
#include "create.h"
#include "ts_catalog/catalog.h"
@@ -1121,10 +1122,10 @@ cagg_query_supported(const Query *query, StringInfo hint, StringInfo detail, con
return true; /* Query was OK and is supported. */
}
-static inline int64
+static inline float8
get_bucket_width(CAggTimebucketInfo bucket_info)
{
- int64 width = 0;
+ float8 width = 0;
/* Calculate the width. */
switch (bucket_info.bucket_width_type)
@@ -1132,7 +1133,7 @@ get_bucket_width(CAggTimebucketInfo bucket_info)
case INT8OID:
case INT4OID:
case INT2OID:
- width = bucket_info.bucket_width;
+ width = (float8) bucket_info.bucket_width;
break;
case INTERVALOID:
{
@@ -1150,8 +1151,7 @@ get_bucket_width(CAggTimebucketInfo bucket_info)
Datum epoch = DirectFunctionCall2(interval_part,
PointerGetDatum(cstring_to_text("epoch")),
IntervalPGetDatum(bucket_info.interval));
- /* Cast float8 to int8. */
- width = DatumGetInt64(DirectFunctionCall1(dtoi8, epoch));
+ width = DatumGetFloat8(epoch);
break;
}
default:
@@ -1505,7 +1505,7 @@ cagg_validate_query(const Query *query, const bool finalized, const char *cagg_s
/* hierarchical cagg validations */
if (is_hierarchical)
{
- int64 bucket_width = 0, bucket_width_parent = 0;
+ float8 bucket_width = 0, bucket_width_parent = 0;
bool is_greater_or_equal_than_parent = true, is_multiple_of_parent = true;
Assert(prev_query->groupClause);
@@ -1542,9 +1542,9 @@ cagg_validate_query(const Query *query, const bool finalized, const char *cagg_s
if (bucket_width_parent != 0)
{
if (bucket_width_parent > bucket_width && bucket_width != 0)
- is_multiple_of_parent = ((bucket_width_parent % bucket_width) == 0);
+ is_multiple_of_parent = (fmod(bucket_width_parent, bucket_width) == 0);
else
- is_multiple_of_parent = ((bucket_width % bucket_width_parent) == 0);
+ is_multiple_of_parent = (fmod(bucket_width, bucket_width_parent) == 0);
}
/* Proceed with validation errors. */ |
konskov
force-pushed
the
cagg_on_cagg_millis_micros
branch
2 times, most recently
from
March 3, 2023 14:31
9472665
to
66bfdc2
Compare
Thank you very much @fabriziomello! |
fabriziomello
previously approved these changes
Mar 3, 2023
gayyappan
reviewed
Mar 3, 2023
konskov
force-pushed
the
cagg_on_cagg_millis_micros
branch
2 times, most recently
from
March 6, 2023 07:31
0aec692
to
542a98d
Compare
konskov
force-pushed
the
cagg_on_cagg_millis_micros
branch
2 times, most recently
from
March 6, 2023 15:28
04973b0
to
ac11a04
Compare
fabriziomello
changed the title
Support sub-second intervals in hierarchical caggs
Fix sub-second intervals in hierarchical caggs
Mar 6, 2023
fabriziomello
approved these changes
Mar 6, 2023
konskov
force-pushed
the
cagg_on_cagg_millis_micros
branch
2 times, most recently
from
March 6, 2023 16:29
06d685f
to
dba6d38
Compare
Previously we used date_part("epoch", interval) and integer division internally to determine whether the top cagg's interval is a multiple of its parent's. This led to precision loss and wrong results in the case of intervals with sub-second components. Fixed by using the `ts_interval_value_to_internal` function to convert intervals to appropriate integer representation for division. Fixes timescale#5277
konskov
force-pushed
the
cagg_on_cagg_millis_micros
branch
from
March 7, 2023 07:21
dba6d38
to
b97210d
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously we used date_part("epoch", interval) and integer division
internally to determine whether the top cagg's interval is a
multiple of its parent's.
This led to precision loss and wrong results
in the case of intervals with sub-second components.
Fixed by using the
ts_interval_value_to_internal
function to convertintervals to appropriate integer representation for division.
Fixes #5277