-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
DateMath: Fix semantics of rounding with inclusive/exclusive ranges. #8556
Conversation
Date math rounding currently works by rounding the date up or down based on the scope of the rounding. For example, if you have the date `2009-12-24||/d` it will round down to the inclusive lower end `2009-12-24T00:00:00.000` and round up to the non-inclusive date `2009-12-25T00:00:00.000`. The range endpoint semantics work as follows: gt - round D down, and use > that value gte - round D down, and use >= that value lt - round D down, and use < lte - round D up, and use <= There are 2 problems with these semantics: 1. lte ends up including the upper value, which should be non-inclusive 2. gt only excludes the beginning of the date, not the entire rounding scope This change makes the range endpoint semantics symmetrical. First, it changes the parser to round up and down using the first (same as before) and last (1 ms less than before) values of the rounding scope. This makes both rounded endpoints inclusive. The range endpoint semantics are then as follows: gt - round D up, and use > that value gte - round D down, and use >= that value lt - round D down, and use < that value lte - round D up, and use <= that value closes elastic#8424
long now = context == null ? System.currentTimeMillis() : context.nowInMillis(); | ||
DateMathParser dateParser = dateMathParser; | ||
if (forcedDateParser != null) { | ||
dateParser = forcedDateParser; | ||
} | ||
long time = includeUpper && roundCeil ? dateParser.parseRoundCeil(value, now, zone) : dateParser.parse(value, now, zone); | ||
return time; | ||
boolean roundUp = inclusive && roundCeil; // TODO: what is roundCeil?? |
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 is a hard override (via index.mapping.date.round_ceil setting, which default to true) to disallow rounding up. Not sure if this actuall set to false, seems undesired to me.
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 will open a separate issue to deal with this odd setting.
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.
+1
LGTM |
LGTM^2 |
Date math rounding currently works by rounding the date up or down based on the scope of the rounding. For example, if you have the date `2009-12-24||/d` it will round down to the inclusive lower end `2009-12-24T00:00:00.000` and round up to the non-inclusive date `2009-12-25T00:00:00.000`. The range endpoint semantics work as follows: * `gt` - round D down, and use > that value * `gte` - round D down, and use >= that value * `lt` - round D down, and use < * `lte` - round D up, and use <= There are 2 problems with these semantics: * `lte` ends up including the upper value, which should be non-inclusive * `gt` only excludes the beginning of the date, not the entire rounding scope This change makes the range endpoint semantics symmetrical. First, it changes the parser to round up and down using the first (same as before) and last (1 ms less than before) values of the rounding scope. This makes both rounded endpoints inclusive. The range endpoint semantics are then as follows: * `gt` - round D up, and use > that value * `gte` - round D down, and use >= that value * `lt` - round D down, and use < that value * `lte` - round D up, and use <= that value closes #8424 closes #8556
The setting `mapping.date.round_ceil` (and the undocumented setting `index.mapping.date.parse_upper_inclusive`) affect how date ranges using `lte` are parsed. In elastic#8556 the semantics of date rounding were solidified, eliminating the need to have different parsing functions whether the date is inclusive or exclusive. This change removes these legacy settings and improves the tests for the date math parser (now at 100% coverage!). It also removes the unnecessary function `DateMathParser.parseTimeZone` for which the existing `DateTimeZone.forID` handles all use cases. Any user previously using these settings can refer to the changed semantics and change their query accordingly. This is a breaking change because even dates without datemath previously used the different parsing functions depending on context. closes elastic#8598 closes elastic#8889
Date math rounding currently works by rounding the date up or down based
on the scope of the rounding. For example, if you have the date
2009-12-24||/d
it will round down to the inclusive lower end2009-12-24T00:00:00.000
and round up to the non-inclusive date2009-12-25T00:00:00.000
.The range endpoint semantics work as follows:
gt
- round D down, and use > that valuegte
- round D down, and use >= that valuelt
- round D down, and use <lte
- round D up, and use <=There are 2 problems with these semantics:
lte
ends up including the upper value, which should be non-inclusivegt
only excludes the beginning of the date, not the entire rounding scopeThis change makes the range endpoint semantics symmetrical. First, it
changes the parser to round up and down using the first (same as before)
and last (1 ms less than before) values of the rounding scope. This
makes both rounded endpoints inclusive. The range endpoint semantics
are then as follows:
gt
- round D up, and use > that valuegte
- round D down, and use >= that valuelt
- round D down, and use < that valuelte
- round D up, and use <= that valuecloses #8424