Skip to content

Commit 1728097

Browse files
kanoshiouivancea
authored andcommitted
ESQL: Align RENAME behavior with EVAL for sequential processing (elastic#122250)
1 parent 0def8d4 commit 1728097

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

docs/changelog/122250.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 122250
2+
summary: "ESQL: Align `RENAME` behavior with `EVAL` for sequential processing"
3+
area: ES|QL
4+
type: enhancement
5+
issues:
6+
- 121739

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,85 @@ x:keyword
213213
Facello
214214
Simmel
215215
;
216+
217+
swappingNames
218+
required_capability: rename_sequential_processing
219+
FROM employees
220+
| SORT emp_no ASC
221+
| KEEP first_name, last_name
222+
| RENAME first_name AS last_name, last_name AS first_name, first_name as name
223+
| LIMIT 2
224+
;
225+
226+
name:keyword
227+
Georgi
228+
Bezalel
229+
;
230+
231+
complexSwappingNames
232+
required_capability: rename_sequential_processing
233+
FROM employees
234+
| SORT emp_no ASC
235+
| KEEP first_name, last_name, emp_no
236+
| RENAME first_name AS last_name, last_name AS first_name, first_name as emp_no, emp_no AS first_name
237+
| LIMIT 2
238+
;
239+
240+
first_name:keyword
241+
Georgi
242+
Bezalel
243+
;
244+
245+
246+
reuseRenamedAlias
247+
required_capability: rename_sequential_processing
248+
FROM employees
249+
| SORT emp_no ASC
250+
| KEEP first_name, last_name
251+
| LIMIT 2
252+
| RENAME first_name AS x, x AS y, last_name as x
253+
;
254+
255+
y:keyword | x:keyword
256+
Georgi | Facello
257+
Bezalel | Simmel
258+
;
259+
260+
261+
multipleRenamesToSameAliasLastOnePrevails
262+
required_capability: rename_sequential_processing
263+
FROM employees
264+
| SORT emp_no ASC
265+
| KEEP first_name, last_name
266+
| LIMIT 2
267+
| RENAME first_name AS x, last_name as x
268+
;
269+
270+
x:keyword
271+
Facello
272+
Simmel
273+
;
274+
275+
276+
swapNames
277+
required_capability: rename_sequential_processing
278+
ROW a="keyword", b=5
279+
| RENAME a AS temp, b AS a, temp AS b
280+
;
281+
282+
b:keyword | a:integer
283+
keyword | 5
284+
;
285+
286+
287+
multipleRenames
288+
required_capability: rename_sequential_processing
289+
ROW a="keyword", b=5, c=null
290+
| RENAME a AS c, b AS a
291+
| RENAME c AS b
292+
| RENAME a AS b, b AS a
293+
;
294+
295+
a:integer
296+
5
297+
;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,12 @@ public enum Cap {
397397
*/
398398
UNION_TYPES_FIX_RENAME_RESOLUTION,
399399

400+
/**
401+
* Execute `RENAME` operations sequentially from left to right,
402+
* see <a href="https://github.com/elastic/elasticsearch/issues/122250"> ESQL: Align RENAME behavior with EVAL for sequential processing #122250 </a>
403+
*/
404+
RENAME_SEQUENTIAL_PROCESSING,
405+
400406
/**
401407
* Fix for union-types when some indexes are missing the required field. Done in #111932.
402408
*/

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ public static List<NamedExpression> projectionsForRename(Rename rename, List<Att
905905
if (alias.child() instanceof UnresolvedAttribute ua && alias.name().equals(ua.name()) == false) {
906906
// remove attributes overwritten by a renaming: `| keep a, b, c | rename a as b`
907907
projections.removeIf(x -> x.name().equals(alias.name()));
908+
childrenOutput.removeIf(x -> x.name().equals(alias.name()));
908909

909910
var resolved = maybeResolveAttribute(ua, childrenOutput, logger);
910911
if (resolved instanceof UnsupportedAttribute || resolved.resolved()) {

0 commit comments

Comments
 (0)