-
Notifications
You must be signed in to change notification settings - Fork 33
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
#991 Support Relative Date Times #1006
base: main
Are you sure you want to change the base?
#991 Support Relative Date Times #1006
Conversation
Signed-off-by: currantw <[email protected]>
Signed-off-by: currantw <[email protected]>
Signed-off-by: currantw <[email protected]>
// Map from time unit constants to the corresponding duration. | ||
private static final Duration secondDuration = Duration.ofSeconds(1); | ||
private static final Duration minuteDuration = Duration.ofMinutes(1); | ||
private static final Duration hourDuration = Duration.ofHours(1); | ||
|
||
private static final Map<String, Duration> durationForTimeUnit = Map.ofEntries( | ||
Map.entry("s", secondDuration), | ||
Map.entry("sec", secondDuration), | ||
Map.entry("secs", secondDuration), | ||
Map.entry("second", secondDuration), | ||
Map.entry("seconds", secondDuration), | ||
|
||
Map.entry("m", minuteDuration), | ||
Map.entry("min", minuteDuration), | ||
Map.entry("mins", minuteDuration), | ||
Map.entry("minute", minuteDuration), | ||
Map.entry("minutes", minuteDuration), | ||
|
||
Map.entry("h", hourDuration), | ||
Map.entry("hr", hourDuration), | ||
Map.entry("hrs", hourDuration), | ||
Map.entry("hour", hourDuration), | ||
Map.entry("hours", hourDuration)); |
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.
Is there are more convenient/easier to maintain way to populate this in Java. More specifically, is there a way to create entries for each of the values in SECOND_UNITS_SET
that map to Duration.ofSeconds(1)
, without needing to repeat all these values?
public class TimeUtilsTest { | ||
|
||
// Monday, Jan 03, 2000 @ 01:01:01.100 | ||
private final LocalDateTime dateTime = LocalDateTime.parse("2000-01-03T01:01:01.100"); |
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.
use capitals (MOCK_DATETIME
) to show that its a constant.
testValid("@w6", "2000-01-01T00:00"); | ||
testValid("@w7", "2000-01-02T00:00"); | ||
|
||
testInvalid("@INVALID", "The relative date time unit 'INVALID' is not supported."); |
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.
you will need to test a lot more invalid cases (such as "@W8") to satisfy implementation.
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 would also like to see more complicated use cases such as
source=table | WHERE earliest=-5d@w1 AND latest=@w6 | ...
I remembered we will not be supporting this functionality in the first iteration - can you please add this test and mark it as ignore
until we add this capability ...
…unit tests. Signed-off-by: currantw <[email protected]>
Signed-off-by: currantw <[email protected]>
Signed-off-by: currantw <[email protected]>
testValid("@w6", "2000-01-01T00:00"); | ||
testValid("@w7", "2000-01-02T00:00"); | ||
|
||
testInvalid("@INVALID", "The relative date time unit 'INVALID' is not supported."); |
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 would also like to see more complicated use cases such as
source=table | WHERE earliest=-5d@w1 AND latest=@w6 | ...
I remembered we will not be supporting this functionality in the first iteration - can you please add this test and mark it as ignore
until we add this capability ...
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.
please also add such time based relative dates queries in the example commands doc
Add a new relative time query filter example to the ppl where clause documentation
Signed-off-by: currantw [email protected]
Description
Adds support for relative date times via the new user-defined method
relative_datetime
.Related Issues
Resolves #991.
Check List
--signoff
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.