Skip to content

Commit d28a656

Browse files
kanoshiouivancea
authored andcommitted
ESQL: Align RENAME behavior with EVAL for sequential processing (elastic#122250)
1 parent 2d90854 commit d28a656

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

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
@@ -268,6 +268,12 @@ public enum Cap {
268268
*/
269269
UNION_TYPES_FIX_RENAME_RESOLUTION,
270270

271+
/**
272+
* Execute `RENAME` operations sequentially from left to right,
273+
* see <a href="https://github.com/elastic/elasticsearch/issues/122250"> ESQL: Align RENAME behavior with EVAL for sequential processing #122250 </a>
274+
*/
275+
RENAME_SEQUENTIAL_PROCESSING,
276+
271277
/**
272278
* Fix for union-types when some indexes are missing the required field. Done in #111932.
273279
*/

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
@@ -856,6 +856,7 @@ public static List<NamedExpression> projectionsForRename(Rename rename, List<Att
856856
if (alias.child() instanceof UnresolvedAttribute ua && alias.name().equals(ua.name()) == false) {
857857
// remove attributes overwritten by a renaming: `| keep a, b, c | rename a as b`
858858
projections.removeIf(x -> x.name().equals(alias.name()));
859+
childrenOutput.removeIf(x -> x.name().equals(alias.name()));
859860

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

0 commit comments

Comments
 (0)