Skip to content
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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

currantw
Copy link

@currantw currantw commented Jan 3, 2025

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

  • Updated documentation (docs/ppl-lang/README.md)
  • Implemented unit tests
  • Implemented tests for combination with other commands
  • New added source code should include a copyright header
  • Commits are signed per the DCO using --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.

Comment on lines 44 to 66
// 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));
Copy link
Author

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");

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.");

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.

Copy link
Member

@YANG-DB YANG-DB Jan 4, 2025

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 ...

testValid("@w6", "2000-01-01T00:00");
testValid("@w7", "2000-01-02T00:00");

testInvalid("@INVALID", "The relative date time unit 'INVALID' is not supported.");
Copy link
Member

@YANG-DB YANG-DB Jan 4, 2025

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 ...

Copy link
Member

@YANG-DB YANG-DB left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Support Relative Date-time Strings
3 participants