Skip to content

Fix bug that Streamstats command incorrectly treats null as a valid group#4777

Merged
LantaoJin merged 4 commits intoopensearch-project:mainfrom
ishaoxy:fix-streamstats-group-null-value
Nov 13, 2025
Merged

Fix bug that Streamstats command incorrectly treats null as a valid group#4777
LantaoJin merged 4 commits intoopensearch-project:mainfrom
ishaoxy:fix-streamstats-group-null-value

Conversation

@ishaoxy
Copy link
Copy Markdown
Contributor

@ishaoxy ishaoxy commented Nov 11, 2025

Description

  1. Added a groupNotNull predicate

  2. Wrapped each window expression in a conditional form:

CASE WHEN groupNotNull THEN raw_expr ELSE CAST(NULL AS expr_type) END

Related Issues

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.

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
@LantaoJin LantaoJin added bug Something isn't working bugFix and removed bug Something isn't working labels Nov 11, 2025
Copy link
Copy Markdown
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 @ishaoxy , thanks for taking this on. I just left some comments. In addition, for the testing, I saw we have covered most of the 'happy' cases, consider adding more negative cases (e.g. “What happens when GROUP BY col1, col2 and only one column is null?”).

.toList();
RexNode groupNotNull =
notNullList.isEmpty()
? context.relBuilder.literal(true)
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.

Just for my understanding: when notNullList.isEmpty(), returning literal(true) means all rows pass the null check. Is this the intended behavior when there are no grouping fields?

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.

This code now has been modified; sorry for this redundant logic. Because in this branch always hasGroup==true, notNullList will never be empty, and it will get result like [state IS NOT NULL, country IS NOT NULL] based on the group field.

@RyanL1997
Copy link
Copy Markdown
Collaborator

nit: I noticed that there were multiple empty space line deletion in the diff - consider revert these changes.

@ishaoxy
Copy link
Copy Markdown
Contributor Author

ishaoxy commented Nov 12, 2025

Hi @ishaoxy , thanks for taking this on. I just left some comments. In addition, for the testing, I saw we have covered most of the 'happy' cases, consider adding more negative cases (e.g. “What happens when GROUP BY col1, col2 and only one column is null?”).

Thank you for the suggestion! I have added such negative test.

yuancu
yuancu previously approved these changes Nov 12, 2025
Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
Copy link
Copy Markdown
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.

@ishaoxy LGTM thanks for the change.

@LantaoJin LantaoJin merged commit 66662ae into opensearch-project:main Nov 13, 2025
37 checks passed
@opensearch-trigger-bot
Copy link
Copy Markdown
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-4777-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 66662ae93e1f2521101fd8f85c732a4eda729d91
# Push it to GitHub
git push --set-upstream origin backport/backport-4777-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-4777-to-2.19-dev.

@LantaoJin LantaoJin added the backport-manually Filed a PR to backport manually. label Nov 13, 2025
asifabashar pushed a commit to asifabashar/sql that referenced this pull request Dec 10, 2025
… group (opensearch-project#4777)

* use null to cover the aggregate value when group value is null

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* fix test

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* fix some problems

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* add IT case

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

---------

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Streamstats command incorrectly treats null as a valid group

4 participants