Repository navigation
Description
Is your feature request related to a problem?
Adding new PPL commands or functions requires extensive boilerplate code across multiple layers of the codebase, making it error-prone and time-consuming. Developers must manually:
- Update ANTLR grammar files (lexer and parser)
- Create AST node classes and implement AST/RelNode visitor pattern methods
- Register functions in multiple locations (PPLBuiltinOperators, PPLFuncImpTable, BuiltinFunctionName)
- Create unit tests that validate the translation pipeline and Spark SQL generated
- Create multiple integration test classes (IT, Yaml IT, ExplainIT, AnonymousIT, CrossClusterIT)
- Remember engine-specific setup (e.g.,
enableCalcite()for V3-only functions) - Update documentation following the latest doc structure
This repetitive process leads to:
- Human errors: Easy to miss required steps or files - some are subtle even if reference similar PRs.
- Inconsistency: Different developers may structure code differently.
- Slow onboarding: New contributors face a steep learning curve.
- Maintenance burden: Changes to architecture require updating many files.
What solution would you like?
Below are several ideas that address the problem from different levels (tooling, specs, and architecture):
-
Interactive scaffolding tool: Add a Gradle task that generates the required files and code insertions from a few prompts, with a strict “expected files changed” checklist to prevent missed steps (human or AI) and copy-paste drift.
-
Spec-driven code generation: Define a YAML/Markdown spec as the single source of truth for commands/functions (metadata, signatures, engine support, tests/docs) and generate the repetitive glue at build time—AI-friendly by design.
-
Better abstractions: Introduce a small DSL for AST → RelNode translation and shared test base classes/mixins to standardize setup. This reduces long-term maintenance and makes both scaffolding and codegen simpler and safer.
What alternatives have you considered?
- Better documentation only: Document the process better, but doesn't prevent human errors
- Copy-paste from examples: Current approach, leads to inconsistencies and forgotten steps
- Code review checklists: Helpful but reactive - catches errors after they're made
Do you have any additional context?
- This issue was motivated by where backport PR failure below due to missing
enableCalcite(). However, more broadly, it highlights a recurring friction point in PPL development: adding new PPL features requires too much scattered, easy-to-miss boilerplate, and we should improve the end-to-end developer workflow to make contributions safer and more consistent. - Success metrics may include:
- Time to add new PPL command/function reduced by X%+
- New contributors can onboard and ship first PR within X days
- Consistent code structure across all commands/functions
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNot Started
Activity
Swiddis commentedon Dec 15, 2025
I've been thinking about this too. A lot of the boilerplate in parsing seems avoidable.
Ideally, we should be defining the grammar independently of individual commands, and have a shared system for registering new command syntaxes that bundles all of the core validation. This simplifies the AST parsing logic lets us centralize all of our syntax validation, and we can then focus on just the actual logic of the commands. Most languages don't register every standard library function directly in their lexer, they leave this to a separate resolution/binding step.
For example, even if you remember to update all the right places, many commands define grammars with fixed field order (such as the current
topCommand). Other commands (e.g.spathCommand) accept in arbitrary order. It's also error-prone because we keep reserving keywords and then breakingkeywordsCanBeIdInstead, consider the scenario where the grammar is just:
We write a parser wrapper that can fetch arbitrary specific parameters. Then registering all of the commands can be done with a system resembling:
I think we can do this approach fairly easily for most commands. There's probably a couple with very weird grammar, we can handle those individually as they come up.
At a command level, this isn't much longer than specifying the syntax in the grammar. But then we can frontload all of the parsing/validation/anonymization to this layer, and commands then only need to write the implementation. This would at least work for the commands with the typical "parameters, arguments, maybe custom extra stuff (like
by)" syntax.From the description, this type of approach can theoretically cover points 1, 2, 3, 4, most of 5, and 6. I don't think 7 can reasonably be automated since each command has its own functionality. It also covers a few unmentioned points:
Swiddis commentedon Dec 15, 2025
I did a quick scan through the existing commands and broke them up by how easy it'd be to write a generic parser for them. Tier 1 being "just collect the arguments in a
Map" and tier 4 being impractical to handle without special-case grammar.Tier 1: Perfect Fit (10 commands)
Commands that already match
commandName namedArgs* fields?:REVERSEHEAD number? (FROM from)?EXPAND field (AS alias)?FLATTEN field (AS aliases)?DEDUP number? fields (KEEPEMPTY=bool)? (CONSECUTIVE=bool)?KMEANS (CENTROIDS=n)? (ITERATIONS=n)? (DISTANCE_TYPE=s)?AD (param=value)*ML (param=value)*ADDTOTALS fields? options*Tier 2: Good Fit with Extensions (15 commands)
Commands that need special clause support (BY, OVER, AS, SORT):
TOP number? options* fields (BY group)?.byClause()supportSTATS args* aggTerms* (BY group | span)?EVENTSTATS args* aggTerms* (BY group)?STREAMSTATS args* aggTerms* (BY group)?SORT count? sortFieldsFIELDS (+|-)? fieldListRENAME field AS field (COMMA field AS field)*REPLACE pattern WITH replacement IN fieldsBIN field (SPAN=x)? options* (AS alias)?GROK sourceField patternPARSE sourceField patternSPATH (INPUT=f)? (OUTPUT=f)? (PATH=p)?REGEX field EQUAL patternREX FIELD=f options* pattern options*TRENDLINE (SORT field)? clauses*Overall doable. We need to extend the registration API with:
.byClause()/.statsByClause().aggregationTerms().sortClause().pairList().pattern()Tier 3: Complex but Manageable (10 commands)
Commands with complex nested structures but could be abstracted:
CHART options* agg (OVER row)? (BY col)? options*TIMECHART params* agg (BY field)? params*EVAL field = expression (COMMA field = expression)*PATTERNS field (BY group)? options* params*LOOKUP table mappings ((APPEND|REPLACE) outputs)?ADDCOLTOTALS fields? options*APPENDCOL (OVERRIDE=bool)? [subpipeline]APPEND [subpipeline]APPENDPIPE [subpipeline]WHERE logicalExpressionWould need:
Tier 4: Major Outliers (5 commands)
Commands with highly specialized syntax that don't fit the pattern of other commands:
• Field comparisons with operators
• Nested expressions with AND/OR/NOT
• IN lists
• Time modifiers
• Can appear before FROM clause
• Complex search term types
• Side aliases (LEFT=l, RIGHT=r)
• Join hints with dot notation (left.hint=value)
• Join criteria with ON/WHERE
• Options (OVERWRITE, TYPE, MAX)
• Complex syntax variations
• Each subsearch is a full search + pipeline
• Syntax:
MULTISEARCH ([search | cmds]+)• Different execution path
• Different execution path
These commands are fundamentally different:
dai-chen commentedon Dec 15, 2025
Hi @Swiddis The generic parser looks interesting! In your top command example, could you give more details what's behind it? Do we represent the new command logic in current AST->RelNode pipeline or by SQL directly? Or just give executable code in your
TopCommand:evaluate?Swiddis commentedon Dec 17, 2025
The idea is that
evaluatewill receive some sort of data structure that contains all of its parameters, pre-parsed & validated, and it'll get assembled in planning. So Top might be working on something like{"showcount": true, "countfield": "count", "number": 5}and need to convert that to RelNode. The parsing boilerplate is all abstracted away, and the map structure more accurately maps how devs (or at least I) actually want to implement commands ("just add this parameter & let me write the relnode logic").In a perfect world this would be a
TopParameters-style class that's reflected/determined by the parser, but I'm not sure how feasible that is. It might need to be some sort ofMap. Ideally there's a single source of truth that combines "what data the RelNode generator works with" and "what data the parser is fetching."krisfreedain commentedon Jan 5, 2026
Catch All Triage - 1 2