Skip to content

Commit 4b3adc5

Browse files
bpinteamridula-s109
authored andcommitted
ESQL: Extend RENAME syntax to allow a new = old syntax (elastic#129212)
This extends RENAME's grammar to allow a new syntax: `| RENAME new_name = old_name` This is supported along the existing `... old_name AS new_name` syntax. Closes elastic#129208
1 parent 044d810 commit 4b3adc5

File tree

7 files changed

+806
-720
lines changed

7 files changed

+806
-720
lines changed

docs/reference/query-languages/esql/_snippets/commands/layout/rename.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ The `RENAME` processing command renames one or more columns.
88
RENAME old_name1 AS new_name1[, ..., old_nameN AS new_nameN]
99
```
1010

11+
The following syntax is also supported {applies_to}`stack: ga 9.1`:
12+
13+
```esql
14+
RENAME new_name1 = old_name1[, ..., new_nameN = old_nameN]
15+
```
16+
17+
::::{tip}
18+
Both syntax options can be used interchangeably but we recommend sticking to one for consistency and readability.
19+
::::
20+
1121
**Parameters**
1222

1323
`old_nameX`

x-pack/plugin/esql/qa/testFixtures/src/main/resources/rename.csv-spec

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,50 @@ ROW a="keyword", b=5, c=null
296296
a:integer
297297
5
298298
;
299+
300+
useAssignmentOnly
301+
required_capability: rename_allow_assignment
302+
303+
ROW a = 1, b = "two"
304+
| RENAME aa = a, bb = b
305+
;
306+
307+
aa:integer | bb:keyword
308+
1 | two
309+
;
310+
311+
useAssignmentAndASKeyword
312+
required_capability: rename_allow_assignment
313+
314+
ROW a = 1, b = "two", c = null
315+
| RENAME aa = a, b AS bb, cc = c
316+
;
317+
318+
aa:integer | bb:keyword | cc:null
319+
1 | two | null
320+
;
321+
322+
shadowWithAssignment
323+
required_capability: rename_allow_assignment
324+
325+
ROW a = 1, b = "two"
326+
| RENAME a = b
327+
;
328+
329+
a:keyword
330+
two
331+
;
332+
333+
multipleRenamesWithAssignment
334+
required_capability: rename_sequential_processing
335+
required_capability: rename_allow_assignment
336+
337+
ROW a="keyword", b=5, c=null
338+
| RENAME c = a, a = b
339+
| RENAME b = c
340+
| RENAME b = a, a = b
341+
;
342+
343+
a:integer
344+
5
345+
;

x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ renameCommand
212212

213213
renameClause:
214214
oldName=qualifiedNamePattern AS newName=qualifiedNamePattern
215+
| newName=qualifiedNamePattern ASSIGN oldName=qualifiedNamePattern
215216
;
216217

217218
dissectCommand

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ public enum Cap {
439439
*/
440440
RENAME_SEQUENTIAL_PROCESSING,
441441

442+
/**
443+
* Support for assignment in RENAME, besides the use of `AS` keyword.
444+
*/
445+
RENAME_ALLOW_ASSIGNMENT,
446+
442447
/**
443448
* Support for removing empty attribute in merging output.
444449
* See <a href="https://github.com/elastic/elasticsearch/issues/126392"> ESQL: EVAL after STATS produces an empty column #126392 </a>

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser.interp

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)