-
Notifications
You must be signed in to change notification settings - Fork 25.4k
ESQL: Enhanced DATE_TRUNC
with arbitrary intervals
#120302
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
ESQL: Enhanced DATE_TRUNC
with arbitrary intervals
#120302
Conversation
Although it is possible to specify an arbitrary interval of months or years in this PR, wouldn't it be clearer to allow users to specify a reference time from which to start calculating the interval? I'm not sure. |
Pinging @elastic/es-analytical-engine (Team:Analytics) |
@bpintea , do you maybe want to have a look at this one? It's related to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it looks good. Left some minor comments.
-
Let's rename the PR and its description to reflect the impact on
DATE_TRUNC
.BUCKET
is a side effect (despite the issue being about it). -
Could we please add more CSV test with the new intervals, which should make it easy to check, in the lines of:
ROW x = ["1970-04-10", "1970-04-11", "1970-04-12"]::DATETIME | MV_EXPAND x | EVAL y = DATE_TRUNC(2 days, x)
and/or similar with...| STATS COUNT(*) BY BUCKET(...)
for the newly available intervals.
CC @not-napoleon this updates some utils used by the histogram aggs, should you want to have a look.
server/src/main/java/org/elasticsearch/common/time/DateUtils.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/common/time/DateUtils.java
Outdated
Show resolved
Hide resolved
@elasticsearchmachine test this please |
BUCKET
DATE_TRUNC
with arbitrary intervals
Co-authored-by: Bogdan Pintea <pintea@mailbox.org>
There are some failing tests in |
I believe this PR is now ready for review. It would be great if you could take a moment to look through it @bpintea ! |
buildkite test this |
Sorry I forgot to run the |
buildkite test this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
It LGTM, but will ask for a review from other aggs-contributors, since the changes affect those too.
Hi, "other aggs-contributor" here. I am a little concerned about performance here. This adds a lot more math, especially in the month case, and the rounding logic often runs in very hot loops so we need to be careful about performance there. At a minimum, I'd like us to delegate the "multiplier" == 1 case to the original methods. @bpintea we should make sure to keep an eye on the benchmarks after merging this too. Also, it would be nice if you added some more comments about how the date math works. This stuff is always tricky, and any help to our future selves when we need to modify it would be nice. Thank you! |
Thank you for reviewing, @bpintea @not-napoleon! I've implemented some minor performance improvements and added detailed comments to clarify |
buildkite test this |
buildkite test this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This addresses my concerns from a classic aggregations perspective. And thank you for adding more explicit comments about the date math, future me will be very happy the next time I need to touch that code.
Thanks @kanoshiou for this contribution and your patience. |
Originally, `DATE_TRUNC` only supported 1-month and 3-month intervals for months, and 1-year interval for years, while arbitrary intervals were supported for weeks and days. This PR adds support for `DATE_TRUNC` with arbitrary month and year intervals. Closes elastic#120094
Originally, `DATE_TRUNC` only supported 1-month and 3-month intervals for months, and 1-year interval for years, while arbitrary intervals were supported for weeks and days. This PR adds support for `DATE_TRUNC` with arbitrary month and year intervals. Closes elastic#120094
Originally, `DATE_TRUNC` only supported 1-month and 3-month intervals for months, and 1-year interval for years, while arbitrary intervals were supported for weeks and days. This PR adds support for `DATE_TRUNC` with arbitrary month and year intervals. Closes #120094 Co-authored-by: kanoshiou <73424326+kanoshiou@users.noreply.github.com>
Manual backport: #129643 |
Originally,
DATE_TRUNC
only supported 1-month and 3-month intervals for months, and 1-year interval for years, while arbitrary intervals were supported for weeks and days. This PR adds support forDATE_TRUNC
with arbitrary month and year intervals.Closes #120094