-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Fix inconsistent roundup behavior for date ranges using Temporal object as terms #127739
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eb6f5e2
Fix inconsistent roundup behavior for date ranges using Temporal obje…
mosche 087aa52
Update docs/changelog/127739.yaml
mosche 9bafb50
Merge branch 'main' into ktlo/date_range_fix
mosche 4e23cd0
PR feedback
mosche e758653
Merge branch 'main' into ktlo/date_range_fix
mosche 67dc9d9
Merge branch 'main' into ktlo/date_range_fix
mosche 1441972
Merge branch 'main' into ktlo/date_range_fix
mosche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pr: 127739 | ||
summary: Fix inconsistent roundup behavior for date ranges using Temporal object as | ||
terms | ||
area: Infra/Core | ||
type: bug | ||
issues: | ||
- 86284 |
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,10 +86,43 @@ public void testRangeQuery() throws Exception { | |
); | ||
} | ||
|
||
public void testDateRangeQueryDoesNotRoundupTemporals() { | ||
type = RangeType.DATE; | ||
SearchExecutionContext context = createContext(); | ||
RangeFieldType ft = createDefaultFieldType(); | ||
ShapeRelation relation = randomFrom(ShapeRelation.values()); | ||
|
||
// explicitly not using nextFrom here to provide a concrete, visual example. | ||
// see the behavioral difference compared to testRangeQueryIntersectsAdjacentDates | ||
ZonedDateTime from = ZonedDateTime.parse("2025-05-01T14:10:00.000Z"); | ||
ZonedDateTime to = ZonedDateTime.parse("2025-05-01T14:11:00.000Z"); | ||
|
||
// usage of roundUp parsers is wrong if terms are Temporal objects, otherwise it would arbitrarily change the bounds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by "Temporal object" don't you mean all dates? |
||
// depending on the string representation | ||
assertEquals( | ||
getExpectedRangeQuery(relation, from, to, false, true), | ||
ft.rangeQuery(from, to, false, true, relation, null, null, context) | ||
); | ||
} | ||
|
||
public void testRangeQueryIntersectsAdjacentDates() { | ||
type = RangeType.DATE; | ||
SearchExecutionContext context = createContext(); | ||
ShapeRelation relation = randomFrom(ShapeRelation.values()); | ||
RangeFieldType ft = createDefaultFieldType(); | ||
|
||
// explicitly not using nextFrom here to provide a concrete, visual example of the roundUp behavior | ||
String from = "2025-05-01T14:10Z"; // transformed to 2025-05-01T14:10:59.999999999Z by roundUp parser | ||
String to = "2025-05-01T14:11Z"; | ||
|
||
Query rangeQuery = ft.rangeQuery(from, to, false, false, relation, null, null, context); | ||
assertThat(rangeQuery, instanceOf(IndexOrDocValuesQuery.class)); | ||
assertThat(((IndexOrDocValuesQuery) rangeQuery).getIndexQuery(), instanceOf(MatchNoDocsQuery.class)); | ||
} | ||
|
||
/** | ||
* test the queries are correct if from/to are adjacent and the range is exclusive of those values | ||
*/ | ||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/86284") | ||
public void testRangeQueryIntersectsAdjacentValues() throws Exception { | ||
SearchExecutionContext context = createContext(); | ||
ShapeRelation relation = randomFrom(ShapeRelation.values()); | ||
|
@@ -143,7 +176,6 @@ public void testRangeQueryIntersectsAdjacentValues() throws Exception { | |
/** | ||
* check that we catch cases where the user specifies larger "from" than "to" value, not counting the include upper/lower settings | ||
*/ | ||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/86284") | ||
public void testFromLargerToErrors() throws Exception { | ||
SearchExecutionContext context = createContext(); | ||
RangeFieldType ft = createDefaultFieldType(); | ||
|
Oops, something went wrong.
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.
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 little deceptive, the parser used in rangeQuery will call toString on this. I think it would be slightly clearer if the test used Strings instead, which matches what would come from a real query, not a ZonedDateTime object.
I wonder if that is the issue with the original test failures: they're passing in ZonedDateTime objects and subject to their toString behavior, but in production this wouldn't happen, we get strings directly from the request.
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.
If we don't care about ZonedDateTime objects, there's no problem here and the failing tests have simply tested for the wrong thing... the problem is really only the difference between Joda vs Java time behaving differently for the
toString
(pls read the PR description for the details)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.
Yeah I don't think ZonedDateTime is possible outside tests, see where eg
from
is set inRangeQueryBuilder
, it basically comes down to parsing xcontent, where we only have strings and numbers. The entire point of the date math parser is to turn a string into a ZonedDateTime, so it doesn't make sense that we would try to take an already realized ZonedDateTime, turn it back into a string, and then get a ZonedDateTime.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.
yes, as described in the PR description, that's the cause of the issue
closing this in favor of fixing the test: #127899