Skip to content

Conversation

@yuancu
Copy link
Collaborator

@yuancu yuancu commented Nov 12, 2025

Description

Allow users to specify a timestamp field instead of assuming there exists a @timestamp field when using timechart command.

For example, the following query is made possible:

source=events | timechart timefield=start_at span=1hour by category

Related Issues

Resolves #4576

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • 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.

@yuancu yuancu added the enhancement New feature or request label Nov 12, 2025
@yuancu yuancu changed the title Use param timefield to specify span field in timechart command Specify timestamp field for aggregation with param timefield in timechart command Nov 12, 2025
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
… visitor

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
@yuancu yuancu changed the title Specify timestamp field for aggregation with param timefield in timechart command Specify timestamp field with timefield in timechart command Nov 12, 2025
@yuancu yuancu marked this pull request as ready for review November 12, 2025 16:33
Optional.ofNullable(argMap.get("timefield"))
.map(l -> (String) l.getValue())
.orElse(OpenSearchConstants.IMPLICIT_FIELD_TIMESTAMP);
Field spanField = AstDSL.field(timeFieldName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you check if we need to use this specified time field in transformPerFunction for per functions as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think we need to use the specified timefield in per functions because otherwise they'll refer to the non-existing @timestamp field. I added an integration test for this case.

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
dai-chen
dai-chen previously approved these changes Nov 18, 2025
Copy link
Collaborator

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

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

Thanks for the changes!

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
@LantaoJin
Copy link
Member

non-blocking: @yuancu looks like this PR would impact the reverse enhancement #4775 more or less.

@yuancu
Copy link
Collaborator Author

yuancu commented Nov 26, 2025

non-blocking: @yuancu looks like this PR would impact the reverse enhancement #4775 more or less.

Yes it will. If this PR gets merged first, I'll help @ahkcs replace time field reference from hard-coded ones to the timefield variable.

@qianheng-aws qianheng-aws merged commit afc98dd into opensearch-project:main Nov 26, 2025
35 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.19-dev failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/sql/backport-2.19-dev 2.19-dev
# Navigate to the new working tree
pushd ../.worktrees/sql/backport-2.19-dev
# Create a new branch
git switch --create backport/backport-4784-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 afc98dd6757288b8b269b78d8e2e5f323f78cae6
# Push it to GitHub
git push --set-upstream origin backport/backport-4784-to-2.19-dev
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/sql/backport-2.19-dev

Then, create a pull request where the base branch is 2.19-dev and the compare/head branch is backport/backport-4784-to-2.19-dev.

@yuancu yuancu deleted the issues/4576 branch November 26, 2025 07:25
yuancu added a commit to yuancu/sql-plugin that referenced this pull request Nov 26, 2025
…arch-project#4784)

* Support param timefield to specify span field in timechart

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Update doc to introduce timefield parameter

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Update ASTBuilderTest for chart: default args are handled in rel node visitor

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Fix ast expression builder test

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Fix anomanyzer test

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Support using specified timefield in per functions

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Omit by-timestamp clause in timechart command

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Mask timefield argument in anonymizer

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Anonymize argument span

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

---------

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
(cherry picked from commit afc98dd)
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
@LantaoJin LantaoJin added the backport-manually Filed a PR to backport manually. label Nov 26, 2025
LantaoJin pushed a commit that referenced this pull request Nov 26, 2025
…#4863)

* Support param timefield to specify span field in timechart



* Update doc to introduce timefield parameter



* Update ASTBuilderTest for chart: default args are handled in rel node visitor



* Fix ast expression builder test



* Fix anomanyzer test



* Support using specified timefield in per functions



* Omit by-timestamp clause in timechart command



* Mask timefield argument in anonymizer



* Anonymize argument span



---------


(cherry picked from commit afc98dd)

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
asifabashar pushed a commit to asifabashar/sql that referenced this pull request Dec 10, 2025
…arch-project#4784)

* Support param timefield to specify span field in timechart

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Update doc to introduce timefield parameter

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Update ASTBuilderTest for chart: default args are handled in rel node visitor

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Fix ast expression builder test

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Fix anomanyzer test

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Support using specified timefield in per functions

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Omit by-timestamp clause in timechart command

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Mask timefield argument in anonymizer

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Anonymize argument span

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

---------

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.19-dev backport-failed backport-manually Filed a PR to backport manually. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] timechart with option to specify timestamp column, overriding the implicit @timestamp field

4 participants