Skip to content

Add earliest and latest in condition function - #3640

Merged
qianheng-aws merged 31 commits into
opensearch-project:mainfrom
xinyual:addEarliest
Jun 10, 2025
Merged

qianheng-aws merged 31 commits into
opensearch-project:mainfrom
xinyual:addEarliest

Conversation

@xinyual

@xinyual xinyual commented May 20, 2025 •

Copy link
Copy Markdown
Contributor

Description

This pr add latest/earliest as two condition function, it will calculate the relative time according to relative string and current time.

Related Issues

Resolves #[Issue number to be closed when this PR is merged]
#3639

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

xinyual added 4 commits May 20, 2025 13:39
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
@penghuo

penghuo commented May 20, 2025

Copy link
Copy Markdown
Collaborator
  • update docs please.
  • what is expectation of earliest and latest? Do we support it in where command?

@dai-chen dai-chen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In SPL doc, these functions are applied to _raw field, but in our impl it's just an alias of min/max?

@LantaoJin LantaoJin added the calcite calcite migration releated label May 22, 2025
Signed-off-by: xinyual <[email protected]>
@xinyual

xinyual commented May 22, 2025

Copy link
Copy Markdown
Contributor Author
  • update docs please.
  • what is expectation of earliest and latest? Do we support it in where command?

Add the doc.
This PR only add them as the aggregation. Will raise another PR as the boolean function.

xinyual added 4 commits May 29, 2025 17:44
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
Comment on lines +639 to +640
"1970-01-18 20:22:32",
"2018-08-19 00:00:00"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid the current implementation may be wrong, the current implementation treat the earliest and latest as window function with default window frame. IMO, the behavior is odd. Please check again if they require to use other window frame instead default.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xinyual does spark-ppl support eventstats earliest(birthdate), latest(birthdate), if not, can we decide later, and only support it as condition function?
From user perspective, It is alias of min/max function, not impact usability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spark-ppl only supports it as condition function. Currently I forbid them as window/aggregation in the latest code.


Usage: earliest(relative_string, field) returns true if the field is after transferring the relative_string.

relative_string:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Does relative_string follow RELATIVE_TIMESTAMP or OpenSearch date math?

  2. relative_string should include a clear definition of the supported time modifiers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread docs/user/ppl/functions/condition.rst Resolved
Comment on lines +58 to +62
ZonedDateTime candidateDatetime = ZonedDateTime.ofInstant(candidate, clock.getZone());
ZonedDateTime latest =
getRelativeZonedDateTime(
expression, ZonedDateTime.ofInstant(clock.instant(), clock.getZone()));
return latest.isAfter(candidateDatetime);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case all timestamp use same timezone, this PR actually does not have similar issue as #3725?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

xinyual added 8 commits June 5, 2025 17:13
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
LantaoJin
LantaoJin previously approved these changes Jun 7, 2025

@LantaoJin LantaoJin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once doc comment addressed.

public static final UDFOperandMetadata DATE_OR_TIMESTAMP_OR_STRING =
UDFOperandMetadata.wrap(
(CompositeOperandTypeChecker) OperandTypes.DATE_OR_TIMESTAMP.or(OperandTypes.STRING));
public static final UDFOperandMetadata STRING_DATE_OR_TIMESTAMP =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: change to STRING_OR_TIMESTAMP

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already rename to STRING_TIMESTMAP, which means accept (STRING, TIMESTAMP)


Usage: earliest(relative_string, field) returns true if the field is after transferring the relative_string.

relative_string:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xinyual added 2 commits June 9, 2025 11:32
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
LantaoJin
LantaoJin previously approved these changes Jun 9, 2025
xinyual added 2 commits June 10, 2025 11:00
Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
@xinyual xinyual changed the title Add earliest and latest in aggregation and window function Add earliest and latest in condition function Jun 10, 2025
@qianheng-aws
qianheng-aws merged commit 246138c into opensearch-project:main Jun 10, 2025
penghuo pushed a commit that referenced this pull request Jun 16, 2025
* add earliest and latest

Signed-off-by: xinyual <[email protected]>

* add more ITs

Signed-off-by: xinyual <[email protected]>

* reuse max/min

Signed-off-by: xinyual <[email protected]>

* revert useless change

Signed-off-by: xinyual <[email protected]>

* add doc

Signed-off-by: xinyual <[email protected]>

* fix do

Signed-off-by: xinyual <[email protected]>

* fix doctest

Signed-off-by: xinyual <[email protected]>

* add earliest and latest as two condition function

Signed-off-by: xinyual <[email protected]>

* fix relative string

Signed-off-by: xinyual <[email protected]>

* add more IT

Signed-off-by: xinyual <[email protected]>

* change doc

Signed-off-by: xinyual <[email protected]>

* update doc

Signed-off-by: xinyual <[email protected]>

* update doc

Signed-off-by: xinyual <[email protected]>

* update doc

Signed-off-by: xinyual <[email protected]>

* add more doc

Signed-off-by: xinyual <[email protected]>

* update to utc_timestamp

Signed-off-by: xinyual <[email protected]>

* remove useless change

Signed-off-by: xinyual <[email protected]>

* update the doc

Signed-off-by: xinyual <[email protected]>

* forbidden the earliest/latest in aggregation/window function

Signed-off-by: xinyual <[email protected]>

* forbid IT

Signed-off-by: xinyual <[email protected]>

* revert doc

Signed-off-by: xinyual <[email protected]>

* add type checker

Signed-off-by: xinyual <[email protected]>

* revert useless change

Signed-off-by: xinyual <[email protected]>

* add doc

Signed-off-by: xinyual <[email protected]>

* add link

Signed-off-by: xinyual <[email protected]>

* apply spotless

Signed-off-by: xinyual <[email protected]>

---------

Signed-off-by: xinyual <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

calcite calcite migration releated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants