Skip to content

[FEATURE] PPL earliest/latest aggregation function support #3639

Closed

Description

@xinyual

Is your feature request related to a problem?
We need to support earliest/latest as aggregate function, it calcite the earliest/latest time for a time related column. Also, it should be supported in eventstat as well

Activity

  1. added
    enhancement
    on May 20, 2025
  2. added
    PPL
    and removed
    enhancement
    on May 20, 2025
  3. added
    calcite
    on May 22, 2025
  4. moved this from Not Started to Done in PPL Trackeron Jun 16, 2025
  5. dai-chen commented on Aug 13, 2025

    @dai-chen
    Collaborator

    @LantaoJin @xinyual I'm doing gap analysis for this and have questions below. As I understand, PR #3640 adds earliest and latest function as scalar conditional function.

    1. This issue is not resolved right? Shall we reopen it?
    2. Could you share the SPL doc that earliest and latest as conditional function?
  6. 3 remaining items

  7. moved this from Done to Not Started in PPL Trackeron Aug 15, 2025
  8. dai-chen commented on Aug 15, 2025

    @dai-chen
    Collaborator

    Implementation Options

    1. stats command
      • Rewrite earliest(field)/latest(field) => min_by(field, _time)/max_by(field, _time)
      • Pushdown optimization: map to Top Hits aggregation with size=1 and sorted by _time field
    2. eventstats command
      • [TBD] Rewrite to first value window function, e.g., FIRST_VALUE(x) OVER (PARTITION BY ... ORDER BY _time ASC ...)

    Prerequisite: We need to define implicit internal field _time first, similarly as _raw field.

  9. xinyual commented on Aug 18, 2025

    @xinyual
    ContributorAuthor

    Prerequisite: We need to define implicit internal field _time first, similarly as _raw field.

    For similar cases like timechart, we use @timestamp #3965 (comment) Can we reuse similar implementation here?
    Do you have time to finish this? If not, I can take this.

  10. dai-chen commented on Aug 18, 2025

    @dai-chen
    Collaborator

    @xinyual Thanks for the context. I wasn't aware of that.

    We reviewed this today and decide to add an optional argument to let users specify a time field other than @timestamp (e.g., source=accounts | stats earliest(age, time)). cc: @ykmr1224

  11. xinyual commented on Aug 19, 2025

    @xinyual
    ContributorAuthor

    We reviewed this today and decide to add an optional argument to let users specify a time field other than @timestamp (e.g., source=accounts | stats earliest(age, time)). cc: @ykmr1224

    Is this the decision for all time modifier cases, e.g. timechart? We will set a default field @timestamp and also allow user to input time field. If so, we should also change the implementation of conditional function earliest/latest. Currently it asks customer to input a time field.

  12. dai-chen commented on Aug 19, 2025

    @dai-chen
    Collaborator

    We reviewed this today and decide to add an optional argument to let users specify a time field other than @timestamp (e.g., source=accounts | stats earliest(age, time)). cc: @ykmr1224

    Is this the decision for all time modifier cases, e.g. timechart? We will set a default field @timestamp and also allow user to input time field. If so, we should also change the implementation of conditional function earliest/latest. Currently it asks customer to input a time field.

    @ykmr1224 Could you follow up with this? As I understand, the current approach is: for any function implicitly relies on _time field, users can do the same without specifying @timestamp. Meanwhile we provide optional argument additionally in case the time field name is different.

    We also discussed a bit about _raw field support which we want to provide a setting. Probably that's also an option for any internal/default fields like _time? cc: @penghuo

  13. ykmr1224 commented on Aug 29, 2025

    @ykmr1224
    Collaborator

    I will work on another PR for earliest/latest with eventstats(#4047).

  14. ykmr1224 commented on Sep 16, 2025

    @ykmr1224
    Collaborator

    earliest/latest is now supported in eventstats: #4212

  15. moved this from Not Started to Done in PPL Trackeron Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PPLcalcitefeaturev3.3.0

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions