Skip to content

Improve error message for unsupported window functions in eventstats/streamstats#5600

Open
gingeekrishna wants to merge 2 commits into
opensearch-project:mainfrom
gingeekrishna:fix/5168-improve-unsupported-window-function-error
Open

Improve error message for unsupported window functions in eventstats/streamstats#5600
gingeekrishna wants to merge 2 commits into
opensearch-project:mainfrom
gingeekrishna:fix/5168-improve-unsupported-window-function-error

Conversation

@gingeekrishna

Copy link
Copy Markdown
Contributor

Description

Fixes #5168

eventstats/streamstats reject window functions outside WINDOW_FUNC_MAPPING (e.g. rank(), dense_rank(), nth_value()) with a bare "Unexpected window function: X" error.

As confirmed in the issue discussion by @songkant-aws, this is expected behavior, not a bug — rank/dense_rank/nth_value require ORDER BY semantics, but eventstats/streamstats only support partition by. The issue was relabeled error-experience: the fix is to make the error message clearer, not to add support for these functions.

Changes

  • CalciteRexNodeVisitor#visitWindowFunction: replaced the generic "Unexpected window function: X" message with one that names the rejected function and lists the functions eventstats/streamstats do support (sourced from WINDOW_FUNC_MAPPING), so users get actionable guidance instead of a bare error.
  • Updated the existing unit test (UnifiedQueryPlannerTest) and integration tests (CalcitePPLEventstatsIT, CalciteStreamstatsCommandIT) to assert against the new message.
  • Added new integration tests covering rank/dense_rank specifically, since the issue's repro queries used those functions.

Note: this PR builds on top of #5587 (already merged), which fixed the same throw site to return a 4xx instead of a 500. This PR only changes the message text, not the exception type or HTTP status.

Test plan

  • Unit test UnifiedQueryPlannerTest#unsupportedWindowFunctionIsRethrownAsSemanticCheckException passes
  • Integration tests added/updated for eventstats and streamstats (require a live cluster to run in CI)

…streamstats

Window functions outside WINDOW_FUNC_MAPPING (e.g. rank, dense_rank,
nth_value) throw a generic "Unexpected window function: X" from
CalciteRexNodeVisitor#visitWindowFunction. These functions require
ORDER BY semantics that eventstats/streamstats don't have (they only
support partition-by), so they are intentionally unsupported, not a
bug -- but the error message gave users no indication of what to use
instead.

Replace the message with one that names the function and lists the
functions eventstats/streamstats do support, so users get actionable
guidance instead of a bare "unexpected" error.

Fixes opensearch-project#5168

Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit 99c53f5)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Hardcoded list

The error message hardcodes the list of supported functions as a string literal. If WINDOW_FUNC_MAPPING is updated to add or remove functions, this message will become stale and misleading. The list should be generated dynamically from WINDOW_FUNC_MAPPING.keySet() to stay in sync.

() ->
    new CalciteUnsupportedException(
        "Window function '"
            + funcName
            + "' is not supported in eventstats/streamstats."
            + " Supported functions: avg, count, dc, distinct_count, earliest,"
            + " latest, max, min, row_number, stddev_pop, stddev_samp, sum,"
            + " var_pop, var_samp."));

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Latest suggestions up to 99c53f5
Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Use String.format for error message

The error message concatenates multiple strings which can impact readability and
maintainability. Consider using String.format() or a text block for better
formatting and easier future modifications of the supported functions list.

core/src/main/java/org/opensearch/sql/calcite/CalciteRexNodeVisitor.java [709-715]

 new CalciteUnsupportedException(
-    "Window function '"
-        + funcName
-        + "' is not supported in eventstats/streamstats."
-        + " Supported functions: avg, count, dc, distinct_count, earliest,"
-        + " latest, max, min, row_number, stddev_pop, stddev_samp, sum,"
-        + " var_pop, var_samp."));
+    String.format(
+        "Window function '%s' is not supported in eventstats/streamstats."
+            + " Supported functions: avg, count, dc, distinct_count, earliest,"
+            + " latest, max, min, row_number, stddev_pop, stddev_samp, sum,"
+            + " var_pop, var_samp.",
+        funcName));
Suggestion importance[1-10]: 4

__

Why: While using String.format() can improve readability, the current string concatenation approach is perfectly valid and readable. This is a minor style improvement that doesn't significantly impact code quality or functionality.

Low

Previous suggestions

Suggestions up to commit c16fc0c
CategorySuggestion                                                                                                                                    Impact
General
Dynamically generate supported functions list

The hardcoded list of supported functions in the error message may become outdated
if new functions are added to WINDOW_FUNC_MAPPING. Consider dynamically generating
this list from the mapping keys to ensure accuracy and maintainability.

core/src/main/java/org/opensearch/sql/calcite/CalciteRexNodeVisitor.java [709-715]

 new CalciteUnsupportedException(
     "Window function '"
         + funcName
         + "' is not supported in eventstats/streamstats."
-        + " Supported functions: avg, count, dc, distinct_count, earliest,"
-        + " latest, max, min, row_number, stddev_pop, stddev_samp, sum,"
-        + " var_pop, var_samp."));
+        + " Supported functions: "
+        + String.join(", ", WINDOW_FUNC_MAPPING.keySet())
+        + "."));
Suggestion importance[1-10]: 7

__

Why: This suggestion improves maintainability by dynamically generating the list of supported functions from WINDOW_FUNC_MAPPING.keySet() instead of hardcoding them. This ensures the error message stays accurate when new functions are added, reducing maintenance burden and preventing outdated documentation.

Medium

Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 99c53f5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] eventstats/streamstats reject window functions that grammar accepts

2 participants