[Feature] Add grammar bundle generation API for PPL language features - #5162
Merged
mengweieric merged 22 commits intoMar 20, 2026
Merged
Conversation
Contributor
📝 WalkthroughWalkthroughAdds a new GET endpoint /_plugins/_ppl/_grammar that serves a cached, serialized ANTLR grammar bundle; introduces GrammarBundle and PPLGrammarBundleBuilder, a RestPPLGrammarAction handler with tests, unit tests for the builder, and updates ANTLR third‑party metadata to 4.13.2. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Handler as RestPPLGrammarAction
participant Cache
participant Builder as PPLGrammarBundleBuilder
participant Serializer as XContentBuilder
Client->>Handler: GET /_plugins/_ppl/_grammar
Handler->>Cache: check cached bundle
alt cache hit
Cache-->>Handler: return Bundle
else cache miss
Handler->>Builder: buildBundle()
Builder->>Builder: inspect lexer/parser, serialize ATNs, compute hash
Builder-->>Handler: Bundle
Handler->>Cache: store Bundle
end
Handler->>Serializer: serialize Bundle to JSON
Serializer-->>Handler: JSON payload
Handler-->>Client: HTTP 200 + JSON
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
mengweieric
force-pushed
the
feature/grammar-bundle
branch
from
February 20, 2026 23:00
d288392 to
eabe8ec
Compare
mengweieric
force-pushed
the
feature/grammar-bundle
branch
3 times, most recently
from
February 23, 2026 06:49
3f36846 to
c838750
Compare
mengweieric
marked this pull request as ready for review
February 23, 2026 07:02
mengweieric
requested review from
GumpacG,
LantaoJin,
MaxKsyunz,
Swiddis,
YANG-DB,
Yury-Fridlyand,
acarbonetto,
anirudha,
dai-chen,
derek-ho,
forestmvey,
joshuali925,
kavithacm,
penghuo,
ps48,
seankao-az,
vamsimanohar and
ykmr1224
as code owners
February 23, 2026 07:02
Contributor
|
Persistent review updated to latest commit 7758a18 |
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
…y, and tests - Hash full 32-bit ints in grammarHash to avoid collisions with ANTLR 4.13.2 ATN serialization - Use RuntimeMetaData.getRuntimeVersion() instead of unreliable JAR manifest lookup - Make GrammarBundle immutable with @value instead of @DaTa - Update THIRD-PARTY to reflect ANTLR 4.13.2 - Harden tests with JSON parsing and add antlrVersion assertion Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
- Assert ATN serialization version 4 for both lexer and parser to enforce antlr4ng compatibility contract - Resolve startRuleIndex by looking up "root" rule name instead of hardcoding 0 - Fix MockRestChannel.bytesOutput() to return real BytesStreamOutput - Document nullable elements in literalNames/symbolicNames Javadoc - Rename test methods to follow testXxx() convention per ppl/plugin modules Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Consistent with buildBundle() which is also @VisibleForTesting protected. Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
mengweieric
force-pushed
the
feature/grammar-bundle
branch
from
March 20, 2026 19:55
7758a18 to
97de071
Compare
Contributor
|
Persistent review updated to latest commit 97de071 |
Swiddis
approved these changes
Mar 20, 2026
ahkcs
approved these changes
Mar 20, 2026
asifabashar
pushed a commit
to asifabashar/sql
that referenced
this pull request
Jul 21, 2026
…opensearch-project#5162) * initial commit for grammar API Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * remove unused etag Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * cleanup on unused code Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * cleanup on comments and debug logging Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * modify tests Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * a few mode cleanup Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * Read ANTLR version from runtime Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * add antlr version Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * spotless fix Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * Address PR review: fix hash truncation, antlrVersion API, immutability, and tests - Hash full 32-bit ints in grammarHash to avoid collisions with ANTLR 4.13.2 ATN serialization - Use RuntimeMetaData.getRuntimeVersion() instead of unreliable JAR manifest lookup - Make GrammarBundle immutable with @value instead of @DaTa - Update THIRD-PARTY to reflect ANTLR 4.13.2 - Harden tests with JSON parsing and add antlrVersion assertion Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * Mark grammar API as experimental Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * Address review: ATN v4 guard, startRuleIndex by name, test hardening - Assert ATN serialization version 4 for both lexer and parser to enforce antlr4ng compatibility contract - Resolve startRuleIndex by looking up "root" rule name instead of hardcoding 0 - Fix MockRestChannel.bytesOutput() to return real BytesStreamOutput - Document nullable elements in literalNames/symbolicNames Javadoc - Rename test methods to follow testXxx() convention per ppl/plugin modules Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * Reduce invalidateCache() visibility from public to protected Consistent with buildBundle() which is also @VisibleForTesting protected. Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * add more necessary fields Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * adjusting ignore token set to be lexical/internal only Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * addressed fix-now comments Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * fix test duplication Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * Polish grammar bundle builder and stabilize grammar endpoint doctest Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * address issue: transport action wrapper Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * Refactor PPL grammar bundle loading to static holder singleton Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * Revert grammar endpoint doc example to clean JSON format Signed-off-by: Eric Wei <mengwei.eric@gmail.com> * Fix typo renameClasue in grammar bundle builder Signed-off-by: Eric Wei <mengwei.eric@gmail.com> --------- Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements the backend grammar metadata API for PPL autocomplete support.
This endpoint serves a versioned grammar bundle containing ANTLR metadata required for downstream consumers (for example OpenSearch Dashboards) to reconstruct a functional PPL lexer/parser at runtime using antlr4ng interpreter APIs. This enables full client-side parsing/autocomplete with zero per-keystroke server calls, while keeping backend grammar as the source of truth.
What the bundle contains:
ATNSerializer.serialize().toArray(), compatible with antlr4ngATNDeserializer.deserialize()tokenDictionary,ignoredTokens, andrulesToVisitfor autocomplete behaviorgrammarHash(ATNs + lexer/parser rule names + literal/symbolic vocabulary + ANTLR version) for client-side change detectionbundleVersionandantlrVersionfor compatibility validationBackend behavior:
@ExperimentalApiAlso included:
ppl.grammar+ YAML REST response-shape testTHIRD-PARTYupdated to reflect ANTLR 4.13.2Related Issues
Resolves #5218
Check List
--signoffor-s.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.