Skip to content

top and head: allow limit keywords#4249

Merged
penghuo merged 16 commits into
opensearch-project:mainfrom
Swiddis:feature/headtop-limit
May 26, 2026
Merged

top and head: allow limit keywords#4249
penghuo merged 16 commits into
opensearch-project:mainfrom
Swiddis:feature/headtop-limit

Conversation

@Swiddis

@Swiddis Swiddis commented Sep 8, 2025

Copy link
Copy Markdown
Collaborator

Description

A small set of improvements:

  • Allows setting limit=N for head and top, similar to what timechart supports. Helps makes queries slightly more readable if storing them somewhere.
  • Adds limit to the available keyword field names (wasn't added by timechart).
  • Broke out AstPlanningTest to help split up AstBuilderTest, since that class is pretty large/unwieldy.

Related Issues

N/A

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: Simeon Widdis <sawiddis@amazon.com>
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

@RyanL1997 RyanL1997 left a comment

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.

Thanks for the change, in generally LGTM.

Comment thread ppl/src/test/java/org/opensearch/sql/ppl/AstPlanningTest.java Outdated
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
ykmr1224
ykmr1224 previously approved these changes Sep 9, 2025
Comment thread docs/user/ppl/cmd/head.rst Outdated
Comment thread docs/user/ppl/cmd/top.rst Outdated
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
ykmr1224
ykmr1224 previously approved these changes Sep 26, 2025
Signed-off-by: Simeon Widdis <sawiddis@gmail.com>
Signed-off-by: Simeon Widdis <sawiddis@gmail.com>
@opensearch-trigger-bot

Copy link
Copy Markdown
Contributor

This PR is stalled because it has been open for 2 weeks with no activity.

Signed-off-by: Simeon Widdis <sawiddis@gmail.com>
@opensearch-trigger-bot

Copy link
Copy Markdown
Contributor

This PR is stalled because it has been open for 2 weeks with no activity.

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
@opensearch-trigger-bot

Copy link
Copy Markdown
Contributor

This PR is stalled because it has been open for 2 weeks with no activity.

@Swiddis

Swiddis commented Dec 5, 2025

Copy link
Copy Markdown
Collaborator Author

Closing since this has stalled multiple times, repeatedly gets merge conflicts, & isn't urgent -- can reopen later if it comes up again

@Swiddis Swiddis closed this Dec 5, 2025
@Swiddis Swiddis reopened this May 26, 2026
@Swiddis

Swiddis commented May 26, 2026

Copy link
Copy Markdown
Collaborator Author

it came up again.

@github-actions

github-actions Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit 16ffe92)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 Multiple PR themes

Sub-PR theme: Refactor test base class extraction

Relevant files:

  • ppl/src/test/java/org/opensearch/sql/ppl/AstPlanningTestBase.java
  • ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java
  • ppl/src/test/java/org/opensearch/sql/ppl/parser/AstEquivalenceTest.java
  • ppl/src/test/java/org/opensearch/sql/ppl/rewrite/SpathRewriteTest.java

Sub-PR theme: Add limit keyword support to head and top commands

Relevant files:

  • ppl/src/main/antlr/OpenSearchPPLParser.g4
  • docs/user/ppl/cmd/head.md
  • docs/user/ppl/cmd/top.md

⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Enforce LIMIT requires EQUAL sign

The grammar allows LIMIT without EQUAL to be parsed, which could lead to ambiguous
parsing. Ensure that when LIMIT is present, EQUAL must follow to avoid parsing
conflicts with the optional integer literal.

ppl/src/main/antlr/OpenSearchPPLParser.g4 [345-347]

 headCommand
-   : HEAD ((LIMIT EQUAL)? number = integerLiteral)? (FROM from = integerLiteral)?
+   : HEAD ((LIMIT EQUAL number = integerLiteral) | number = integerLiteral)? (FROM from = integerLiteral)?
    ;
Suggestion importance[1-10]: 7

__

Why: The current grammar ((LIMIT EQUAL)? number = integerLiteral)? allows LIMIT without EQUAL, which could create ambiguity. The improved code enforces that when LIMIT is present, EQUAL must follow, making the grammar more explicit and preventing potential parsing conflicts.

Medium

@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 16ffe92

@penghuo penghuo merged commit e90692c into opensearch-project:main May 26, 2026
39 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request stalled

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants