Repository navigation
parser: add the rename command - #4
Merged
Merged
Conversation
Splunk rename takes one or more `from AS to` pairs and applies them in a single pass. The whole command lowers to one RenameStage so the pairs stay together, matching both Splunk and the ES|QL RENAME command that receives them. Field spellings follow Splunk: a name may be quoted, and a wildcard may touch or lead the name (EU*, properties.*, *foo). Wildcards parse because they are valid SPL; the ES|QL emitter refuses them at the offending field with rename-wildcard, since RENAME has no wildcard form and expanding one would need the field list. ES|QL applies every pair of a RENAME to the same input columns, so a pair whose target is another pair's source has no order-independent meaning. That form, and renaming one field twice, are refused with rename-conflict and rename-duplicate. `rename a as a` is a no-op and emits nothing. The target name is emitted as written rather than through the field mapping: it is the name the query chooses, not an ECS field. The source is an existing column, so it is mapped. PromQL refuses the stage with promql-unsupported-stage. Tests: parser stage and position tables plus syntax-error positions, compiler goldens and refusal positions, and ten conformance cases. The corpus baselines are re-recorded and the README report table regenerated. make check and go test -race ./... pass.
be-thomas
commented
Oct 26, 2026
be-thomas
commented
Oct 26, 2026
be-thomas
commented
Oct 26, 2026
be-thomas
commented
Oct 26, 2026
be-thomas
commented
Oct 26, 2026
Review of the rename support found that the ES|QL emitter did not track the columns a rename creates or removes. A later stage that referenced a renamed field resolved it through the field mapping, so `rename dest as host | stats count by host` emitted `BY `host.name`` for a column that now exists as `host`, and `rename host as dest | stats count by host` emitted a column RENAME had just dropped. The emitter now records the target as a column of its own name and the source as no longer available. A reference to a name that was renamed away is refused at the reference with rename-source-dropped instead of emitting a column that does not exist, and a later rename that restores the name clears it. Two pairs that would interact are now refused consistently. Two pairs cannot share a target: Splunk rejects it, and ES|QL keeps only the rightmost column, so `rename a as b, c as b` silently lost one. No-op pairs no longer count as renames, so `rename a as b, a as a` and `rename a as b, b as b` emit the real pair instead of reporting a duplicate. The conflict message no longer claims ES|QL's order is unspecified: Elastic documents a multi-pair RENAME as the equivalent sequence of single renames. Identifiers that spell an ES|QL keyword are now backtick-quoted, so `rename where as search` emits `RENAME `where` AS search` rather than a bare keyword. Tests cover the resolved name, a two-stage chain, restoring a renamed name, both no-op shapes, both refusal positions, keyword quoting, and three new conformance cases.
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.
What changes
Adds the classic SPL
renamecommand:rename <field> AS <field>[, ...].ast.RenameStageholds all pairs of one command, because Splunkapplies them as one command and the ES|QL
RENAMEthat receives themcarries them together. Each
ast.Renamecarries the positions of both fieldtokens.
CmdRenamewithrenamePairandrenameField. A quoted namekeeps its decoded text; a wildcard may lead or trail the name (
*foo,properties.*,EU*). The leading-wildcard alternative starts onSTAR_TIGHT, so SLL prediction never has to pick between alternatives thatshare a first token.
renamemoves from the known-but-unimplemented table to theimplemented one, and the token is accepted by the public
Lexadapter andby the tight-token classifier.
RENAME a AS b, c AS d. ES|QL defines a multi-pairRENAMEas the equivalent sequence of single renames, so the pipeline tracks which
columns exist: a renamed field resolves to its new name downstream, and a
reference to a name that was renamed away is refused. Refusals:
rename-wildcardat the wildcarded field —RENAMEhas no wildcard form;rename-duplicatewhen one field is renamed twice;rename-conflictwhen a pair's target is another pair's source, or whentwo pairs share one target (ES|QL would keep only the rightmost column);
rename-source-droppedat a later reference to a name that was renamedaway.
rename a as ais a no-op and emits nothing, and no-op pairs are ignoredwhen checking the other pairs.
promql-unsupported-stage, as with the other row-shaping stages.column); the target is emitted as written, because it is the name the query
chooses, not an ECS field.
quoted, so keyword field names survive emission in every command.
Docs updated: README (supported table and regenerated conformance report),
COMPATIBILITY, CONFORMANCE, CHANGELOG, ROADMAP, ARCHITECTURE.
Tests
pkg/parser/spl1/parser_test.go:TestRename(8 cases asserting exact ASTand
ast.Posincluding offsets) andTestRenameErrors(7 cases assertingthe
syntaxcode and exact position).pkg/compiler/compiler_test.go: 12 rename ES|QL goldens (single pair,unmapped target, downstream resolution, two-stage chain, name restored by a
later rename, both no-op shapes, multiple pairs, quoted source, keyword
quoting, no-op command) plus one golden for keyword quoting in
table, andTestRenameRefusals(10 refusal cases, each asserting one diagnostic withcode, line, column and empty output).
conformance/cases/rename/: 12 cases — exact ES|QL for simple, multiple,quoted, no-op, downstream (
statsover the new name) and mapped target;refusals for wildcard source, bare wildcard target, duplicate, target
overlap, target reuse and a dropped-source reference, each with its PromQL
refusal.
make corpus-update; the README reporttable was regenerated with
make corpus-reportand matches byte for byte.Verification:
make check,go test -race ./...,make generate-check(nodrift),
go test ./conformance -count=1.Effect on the corpus: parse-to-IR 84 → 95 of 2,812, ES|QL compile 65 → 72.
renameblocked 117 detection queries; the remainder still fail for reasonsoutside this command (see below).
Review
An independent review posted five inline findings, all addressed in
515188cand each thread replied to and resolved:renamecreates and removes, so a later reference to a renamed field resolved
through the ECS mapping and a reference to a renamed-away field named a
dropped column. Fixed by recording both directions and refusing the latter.
pairs "to the same input columns"; Elastic documents the equivalent of
sequential renames. The wording now reflects that, and the refusal for
interacting pairs is stated as the conservative policy it is (Splunk's
behaviour for those pairs is unverified).
rename a as b, c as bwas accepted though ES|QLkeeps only the rightmost and Splunk rejects it; now
rename-conflict.rename a as a, a as bandrename a as b, b as bwerewrongly reported as duplicates/conflicts; no-op pairs no longer count.
quoteIdentdid not quote ES|QL keywords, sorename where as searchemitted a bare keyword (pre-existing forKEEPtoo). Fixed for every command, with two goldens.
Open questions
name a
{}JSON path (rename data{} as x) and 1 uses a hyphenated name(
x-amz-copy-source). Both are general identifier-lexing gaps that affectevery command, not just
rename. They look like the next feature.rename a as *fooparses on the source sidebut not after
AS, because the tight-token pass classifies a star after anoperand as
STAR_OP. Splunk's documented wildcard rename is symmetrictrailing (
EU* AS EMEA*), which works. Should a leading-wildcard target besupported, or is the syntax error acceptable?
renamewildcard expansion. The refusal is deliberate, but a futureemitter could expand wildcards when it knows the schema. That needs a
mapping-level field list, which does not exist yet.
rename a as b, b as cpair by pair like ES|QL, the refusal could belifted and the two emitted as one command.
No push to
main; merging waits for maintainer review.