Skip to content

Commit 30cb238

Browse files
authored
[8.19] ESQL: Extend RENAME syntax to allow a new = old syntax (elastic#129212) (elastic#129254)
* 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 (cherry picked from commit 6c7730d) * Fix merging
1 parent bac3e16 commit 30cb238

File tree

7 files changed

+466
-382
lines changed

7 files changed

+466
-382
lines changed

docs/reference/esql/processing-commands/rename.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ The `RENAME` processing command renames one or more columns.
1111
RENAME old_name1 AS new_name1[, ..., old_nameN AS new_nameN]
1212
----
1313

14+
The following syntax is also supported:
15+
16+
[source,esql]
17+
----
18+
RENAME new_name1 = old_name1[, ..., new_nameN = old_nameN]
19+
----
20+
21+
TIP: Both syntax options can be used interchangeably but we recommend sticking to one for consistency and readability.
22+
1423
*Parameters*
1524

1625
`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
@@ -269,6 +269,7 @@ renameCommand
269269

270270
renameClause:
271271
oldName=qualifiedNamePattern AS newName=qualifiedNamePattern
272+
| newName=qualifiedNamePattern ASSIGN oldName=qualifiedNamePattern
272273
;
273274

274275
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
@@ -307,6 +307,11 @@ public enum Cap {
307307
*/
308308
RENAME_SEQUENTIAL_PROCESSING,
309309

310+
/**
311+
* Support for assignment in RENAME, besides the use of `AS` keyword.
312+
*/
313+
RENAME_ALLOW_ASSIGNMENT,
314+
310315
/**
311316
* Support for removing empty attribute in merging output.
312317
* See <a href="https://github.com/elastic/elasticsearch/issues/126392"> 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)