Skip to content

Conversation

@dai-chen
Copy link
Collaborator

@dai-chen dai-chen commented Aug 21, 2025

Description

This PR introduces support for count(eval(condition)) function in PPL stats command which enables filtered counting capability. Pushdown optimization and additional support for distinct_count(eval) and eventstats command (low priority) will be worked on next. Please find more details in issue below: #3949 (comment).

Key implementation decisions:

  1. count(eval(...)) is rewritten as count(CASE WHEN ... THEN 1 ELSE NULL END).
  2. Only the count aggregation is supported (distinct_count is planned next). Support for other aggregation functions may be added in the future if the semantic is clear.

Related Issues

Resolves (partially) #3949

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.

@dai-chen dai-chen added enhancement New feature or request PPL Piped processing language labels Aug 21, 2025
penghuo
penghuo previously approved these changes Aug 22, 2025
Copy link
Collaborator

@penghuo penghuo left a comment

Choose a reason for hiding this comment

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

Current solution push down count(eval(p)) as script expression? we plan to agg-filter push down in future PR?

@dai-chen
Copy link
Collaborator Author

Current solution push down count(eval(p)) as script expression? we plan to agg-filter push down in future PR?

I think filtered aggregation pushdown is reverted in PR #4002. I'm working on a follow up PR to reenable it correctly.

Copy link
Collaborator

@RyanL1997 RyanL1997 left a comment

Choose a reason for hiding this comment

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

Hi @dai-chen , thanks for taking this on. LGTM and I just left a question.

@dai-chen dai-chen requested a review from penghuo August 28, 2025 20:38
* Fluent API for building count(eval) test cases. Provides a clean and readable way to define PPL
* queries and their expected outcomes.
*/
protected PPLQueryTestBuilder withPPLQuery(String ppl) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

@vamsimanohar vamsimanohar merged commit 29c8b72 into opensearch-project:main Aug 28, 2025
23 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-4103-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 29c8b72148ba9a46de4d16bd4383eca25c520ffd
# Push it to GitHub
git push --set-upstream origin backport/backport-4103-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-4103-to-2.19-dev.

opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 28, 2025
* Rewrite count(eval) expression to support filtered counting

Signed-off-by: Chen Dai <[email protected]>

* Refactor count eval UTs

Signed-off-by: Chen Dai <[email protected]>

* Add count eval ITs

Signed-off-by: Chen Dai <[email protected]>

* Add count eval doctest

Signed-off-by: Chen Dai <[email protected]>

* Fix doctest failure

Signed-off-by: Chen Dai <[email protected]>

* Add more UT for AST builder

Signed-off-by: Chen Dai <[email protected]>

* Resolve conflicts and more changes for shortcut c

Signed-off-by: Chen Dai <[email protected]>

---------

Signed-off-by: Chen Dai <[email protected]>
(cherry picked from commit 29c8b72)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.19-dev enhancement New feature or request PPL Piped processing language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants