-
Notifications
You must be signed in to change notification settings - Fork 181
Fix span on negative timestamp #4017
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
Changes from all commits
aa716f9
a24ba2e
b7d23d4
5bba43a
e978249
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| import java.time.format.DateTimeFormatter; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.opensearch.sql.planner.physical.collector.Rounding.DateTimeUnit; | ||
|
|
||
| public class DateTimeUtilsTest { | ||
|
Collaborator
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. np: this is actually UT for
Collaborator
Author
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. No, It's actually testing the |
||
| @Test | ||
|
|
@@ -105,4 +106,76 @@ void testRelativeZonedDateTimeWithWrongInput() { | |
| IllegalArgumentException.class, () -> getRelativeZonedDateTime("1d+1y", zonedDateTime)); | ||
| assertEquals(e.getMessage(), "Unexpected character '1' at position 0 in input: 1d+1y"); | ||
| } | ||
|
|
||
| @Test | ||
| void testRoundOnTimestampBeforeEpoch() { | ||
| long actual = | ||
| LocalDateTime.parse("1961-05-12T23:40:05") | ||
| .atZone(ZoneOffset.UTC) | ||
| .toInstant() | ||
| .toEpochMilli(); | ||
| long rounded = DateTimeUnit.MINUTE.round(actual, 1); | ||
| assertEquals( | ||
| LocalDateTime.parse("1961-05-12T23:40:00") | ||
| .atZone(ZoneOffset.UTC) | ||
| .toInstant() | ||
| .toEpochMilli(), | ||
| Instant.ofEpochMilli(rounded).toEpochMilli()); | ||
|
|
||
| rounded = DateTimeUnit.HOUR.round(actual, 1); | ||
| assertEquals( | ||
| LocalDateTime.parse("1961-05-12T23:00:00") | ||
| .atZone(ZoneOffset.UTC) | ||
| .toInstant() | ||
| .toEpochMilli(), | ||
| Instant.ofEpochMilli(rounded).toEpochMilli()); | ||
|
|
||
| rounded = DateTimeUnit.DAY.round(actual, 1); | ||
| assertEquals( | ||
| LocalDateTime.parse("1961-05-12T00:00:00") | ||
| .atZone(ZoneOffset.UTC) | ||
| .toInstant() | ||
| .toEpochMilli(), | ||
| Instant.ofEpochMilli(rounded).toEpochMilli()); | ||
|
|
||
| rounded = DateTimeUnit.DAY.round(actual, 3); | ||
| assertEquals( | ||
| LocalDateTime.parse("1961-05-12T00:00:00") | ||
| .atZone(ZoneOffset.UTC) | ||
| .toInstant() | ||
| .toEpochMilli(), | ||
| Instant.ofEpochMilli(rounded).toEpochMilli()); | ||
|
|
||
| rounded = DateTimeUnit.WEEK.round(actual, 1); | ||
| assertEquals( | ||
| LocalDateTime.parse("1961-05-08T00:00:00") | ||
| .atZone(ZoneOffset.UTC) | ||
| .toInstant() | ||
| .toEpochMilli(), | ||
| Instant.ofEpochMilli(rounded).toEpochMilli()); | ||
|
|
||
| rounded = DateTimeUnit.MONTH.round(actual, 1); | ||
| assertEquals( | ||
| LocalDateTime.parse("1961-05-01T00:00:00") | ||
| .atZone(ZoneOffset.UTC) | ||
| .toInstant() | ||
| .toEpochMilli(), | ||
| Instant.ofEpochMilli(rounded).toEpochMilli()); | ||
|
|
||
| rounded = DateTimeUnit.QUARTER.round(actual, 1); | ||
| assertEquals( | ||
| LocalDateTime.parse("1961-04-01T00:00:00") | ||
| .atZone(ZoneOffset.UTC) | ||
| .toInstant() | ||
| .toEpochMilli(), | ||
| Instant.ofEpochMilli(rounded).toEpochMilli()); | ||
|
|
||
| rounded = DateTimeUnit.YEAR.round(actual, 2); | ||
| assertEquals( | ||
| LocalDateTime.parse("1960-01-01T00:00:00") | ||
| .atZone(ZoneOffset.UTC) | ||
| .toInstant() | ||
| .toEpochMilli(), | ||
| Instant.ofEpochMilli(rounded).toEpochMilli()); | ||
| } | ||
| } | ||
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.
Not sure if I understand correct: this can be abstract as
Uh oh!
There was an error while loading. Please reload this page.
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.
Agree, seems that could be abstracted. This focus on bugfix and just keep the exist implementation without too much refinement. Maybe that refinement could be done next time if we need further related change.