Skip to content

Conversation

@yuancu
Copy link
Collaborator

@yuancu yuancu commented Nov 7, 2025

Description

timechart is semantically a subset of chart , where the row-split is always fixed to @timestamp. This PR merges their implementation for easier maintenance and resolves a few existing bugs of timechart.

Related Issues

Resolves #4581, resolves #4582, resolves #4632

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 added 10 commits November 7, 2025 16:53
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
- add 2 more indicies for test purpose

Signed-off-by: Yuanchun Shen <[email protected]>
Example 3: Calculate average number of packets by minute
================================================

This example calculates the average CPU usage for each minute without grouping by any field.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cpu_usage does not exist in the given index, therefore replaced

Example 5: Count events by hour and category
=====================================================================

This example counts events for each second and groups them by region, showing zero values for time-region combinations with no data.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

region does not exist in the given index, therefore replaced

Comment on lines +150 to +163
fetched rows / total rows = 8/8
+---------------------+---------+---------+
| @timestamp | host | count() |
|---------------------+---------+---------|
| 2023-01-01 10:00:00 | server1 | 1 |
| 2023-01-01 10:05:00 | server2 | 1 |
| 2023-01-01 10:10:00 | server1 | 1 |
| 2023-01-01 10:15:00 | server2 | 1 |
| 2023-01-01 10:20:00 | server1 | 1 |
| 2023-01-01 10:25:00 | server2 | 1 |
| 2023-01-01 10:30:00 | server1 | 1 |
| 2023-01-01 10:35:00 | server2 | 1 |
+---------------------+---------+---------+

Copy link
Member

Choose a reason for hiding this comment

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

Why the results before and after for the same ppl query are different? please confirm the current result is correct comparing to SPL.

Copy link
Collaborator Author

@yuancu yuancu Nov 12, 2025

Choose a reason for hiding this comment

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

The difference lies in whether we fill 0 for non-existing groups.

In SPL, timechart and chart will pivot the result table, explicitly filling 0 for count aggregation, leaving it empty for the rest aggregation functions. E.g. the result in SPL will be like:

@timestamp server1 server2
2023-01-01 10:00:00 1 0
2023-01-01 10:05:00 0 1
2023-01-01 10:10:00 1 0
2023-01-01 10:15:00 0 1
2023-01-01 10:20:00 1 0
2023-01-01 10:25:00 0 1
2023-01-01 10:30:00 1 0
2023-01-01 10:35:00 0 1

In this thread and offline discussions, we decided to not fill 0 for non-existing groups to simplify implementations and keep consistence with docs (see #4632), leaving the pivoting and zero-filling to frontend if necessary.

Comment on lines +310 to +311
"source=%s | chart usenull=false count() over gender by age "
+ " span=10 nullstr='not_shown'",
Copy link
Member

Choose a reason for hiding this comment

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

why the location of option nullstr changed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@penghuo commented that it would be better if the argument positions are more flexible in #4579 (comment)

Here, I altered the location of argument nullstr to exemplify this point


JSONObject result =
executeQuery("source=events_null | timechart span=1d limit=2 count() by host");
executeQuery("source=events_null | timechart count() by host span=1d limit=2");
Copy link
Member

Choose a reason for hiding this comment

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

ditto: cannot timechart span=1d limit=2 count() by host work now? can it work in spl?

Copy link
Collaborator Author

@yuancu yuancu Nov 12, 2025

Choose a reason for hiding this comment

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

It works. The locations of these arguments are scattered in different locations across the ITs.

@LantaoJin LantaoJin merged commit daf1795 into opensearch-project:main Nov 12, 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-4755-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 daf1795a0672c9f6ce1d1bd74fc58415963d099a
# Push it to GitHub
git push --set-upstream origin backport/backport-4755-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-4755-to-2.19-dev.

@yuancu yuancu deleted the issues/4581 branch November 12, 2025 12:45
yuancu added a commit to yuancu/sql-plugin that referenced this pull request Nov 13, 2025
…ct#4755)

* Remove visitTimechart

Signed-off-by: Yuanchun Shen <[email protected]>

* Migrate per functions to Chart

Signed-off-by: Yuanchun Shen <[email protected]>

* Update CalcitePPLTimechartTest

Signed-off-by: Yuanchun Shen <[email protected]>

* Migrate TimecharTest to use Chart

Signed-off-by: Yuanchun Shen <[email protected]>

* Fix AST relevant tests

Signed-off-by: Yuanchun Shen <[email protected]>

* Remove Timechart AST object in favor of Chart

Signed-off-by: Yuanchun Shen <[email protected]>

* Update expected plans for timechart

Signed-off-by: Yuanchun Shen <[email protected]>

* Update doctest for timechart
- add 2 more indicies for test purpose

Signed-off-by: Yuanchun Shen <[email protected]>

* Add yaml tests for 4581, 4582, and 4632

Signed-off-by: Yuanchun Shen <[email protected]>

* Allow flexible parameter positions for chart and timechart

Signed-off-by: Yuanchun Shen <[email protected]>

* Simplify CalciteTimechartCommandIT

Signed-off-by: Yuanchun Shen <[email protected]>

---------

Signed-off-by: Yuanchun Shen <[email protected]>
(cherry picked from commit daf1795)
@LantaoJin LantaoJin added the backport-manually Filed a PR to backport manually. label Nov 13, 2025
LantaoJin pushed a commit that referenced this pull request Nov 13, 2025
* Remove visitTimechart



* Migrate per functions to Chart



* Update CalcitePPLTimechartTest



* Migrate TimecharTest to use Chart



* Fix AST relevant tests



* Remove Timechart AST object in favor of Chart



* Update expected plans for timechart



* Update doctest for timechart
- add 2 more indicies for test purpose



* Add yaml tests for 4581, 4582, and 4632



* Allow flexible parameter positions for chart and timechart



* Simplify CalciteTimechartCommandIT



---------


(cherry picked from commit daf1795)

Signed-off-by: Yuanchun Shen <[email protected]>
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. bug Something isn't working enhancement New feature or request

Projects

None yet

3 participants