6
6
*/
7
7
package org .elasticsearch .xpack .esql .core .tree ;
8
8
9
- import org .elasticsearch .action .ActionListener ;
10
- import org .elasticsearch .action .support .CountDownActionListener ;
11
9
import org .elasticsearch .common .io .stream .NamedWriteable ;
12
10
import org .elasticsearch .xpack .esql .core .QlIllegalArgumentException ;
13
11
16
14
import java .util .Iterator ;
17
15
import java .util .List ;
18
16
import java .util .Objects ;
19
- import java .util .concurrent .atomic .AtomicReference ;
20
- import java .util .function .BiConsumer ;
21
17
import java .util .function .Consumer ;
22
18
import java .util .function .Function ;
23
19
import java .util .function .Predicate ;
@@ -191,45 +187,16 @@ public T transformDown(Function<? super T, ? extends T> rule) {
191
187
return node .transformChildren (child -> child .transformDown (rule ));
192
188
}
193
189
194
- @ SuppressWarnings ("unchecked" )
195
- public void transformDown (BiConsumer <T , ActionListener <T >> rule , ActionListener <T > listener ) {
196
- // First apply the rule to the current node (top-down)
197
- rule .accept ((T ) this , listener .delegateFailureAndWrap ((l , transformedNode ) -> {
198
- // Then recursively transform the children with the same rule
199
- transformedNode .transformChildren ((child , childListener ) -> child .transformDown (rule , childListener ), l );
200
- }));
201
- }
202
-
203
190
@ SuppressWarnings ("unchecked" )
204
191
public <E extends T > T transformDown (Class <E > typeToken , Function <E , ? extends T > rule ) {
205
192
return transformDown ((t ) -> (typeToken .isInstance (t ) ? rule .apply ((E ) t ) : t ));
206
193
}
207
194
208
- @ SuppressWarnings ("unchecked" )
209
- public <E extends T > void transformDown (Class <E > typeToken , BiConsumer <E , ActionListener <T >> rule , ActionListener <T > listener ) {
210
- transformDown (typeToken ::isInstance , rule , listener );
211
- }
212
-
213
195
@ SuppressWarnings ("unchecked" )
214
196
public <E extends T > T transformDown (Predicate <Node <?>> nodePredicate , Function <E , ? extends T > rule ) {
215
197
return transformDown ((t ) -> (nodePredicate .test (t ) ? rule .apply ((E ) t ) : t ));
216
198
}
217
199
218
- @ SuppressWarnings ("unchecked" )
219
- public <E extends T > void transformDown (
220
- Predicate <Node <?>> nodePredicate ,
221
- BiConsumer <E , ActionListener <T >> rule ,
222
- ActionListener <T > listener
223
- ) {
224
- transformDown ((T node , ActionListener <T > l ) -> {
225
- if (nodePredicate .test (node )) {
226
- rule .accept ((E ) node , l );
227
- } else {
228
- l .onResponse (node );
229
- }
230
- }, listener );
231
- }
232
-
233
200
@ SuppressWarnings ("unchecked" )
234
201
public T transformUp (Function <? super T , ? extends T > rule ) {
235
202
T transformed = transformChildren (child -> child .transformUp (rule ));
@@ -238,48 +205,15 @@ public T transformUp(Function<? super T, ? extends T> rule) {
238
205
}
239
206
240
207
@ SuppressWarnings ("unchecked" )
241
- public void transformUp (BiConsumer <T , ActionListener <T >> rule , ActionListener <T > listener ) {
242
- // First, recursively transform the children (depth-first, bottom-up) using the same async rule
243
- transformChildren (
244
- // traversal operation applied to each child
245
- (child , childListener ) -> child .transformUp (rule , childListener ),
246
- // After all children are transformed, apply the rule to the (possibly) new current node
247
- listener .delegateFailureAndWrap ((l , transformedChildrenNode ) -> {
248
- T node = transformedChildrenNode .equals (this ) ? (T ) this : transformedChildrenNode ;
249
- rule .accept (node , l );
250
- })
251
- );
252
- }
253
-
254
208
public <E extends T > T transformUp (Class <E > typeToken , Function <E , ? extends T > rule ) {
255
- return transformUp (typeToken ::isInstance , rule );
256
- }
257
-
258
- public <E extends T > void transformUp (Class <E > typeToken , BiConsumer <E , ActionListener <T >> rule , ActionListener <T > listener ) {
259
- transformUp (typeToken ::isInstance , rule , listener );
209
+ return transformUp ((t ) -> (typeToken .isInstance (t ) ? rule .apply ((E ) t ) : t ));
260
210
}
261
211
262
212
@ SuppressWarnings ("unchecked" )
263
213
public <E extends T > T transformUp (Predicate <Node <?>> nodePredicate , Function <E , ? extends T > rule ) {
264
214
return transformUp ((t ) -> (nodePredicate .test (t ) ? rule .apply ((E ) t ) : t ));
265
215
}
266
216
267
- @ SuppressWarnings ("unchecked" )
268
- public <E extends T > void transformUp (
269
- Predicate <Node <?>> nodePredicate ,
270
- BiConsumer <E , ActionListener <T >> rule ,
271
- ActionListener <T > listener
272
- ) {
273
- transformUp ((T node , ActionListener <T > l ) -> {
274
- if (nodePredicate .test (node )) {
275
- E typedNode = (E ) node ;
276
- rule .accept ((E ) node , l );
277
- } else {
278
- l .onResponse (node );
279
- }
280
- }, listener );
281
- }
282
-
283
217
@ SuppressWarnings ("unchecked" )
284
218
protected <R extends Function <? super T , ? extends T >> T transformChildren (Function <T , ? extends T > traversalOperation ) {
285
219
boolean childrenChanged = false ;
@@ -304,35 +238,6 @@ public <E extends T> void transformUp(
304
238
return (childrenChanged ? replaceChildrenSameSize (transformedChildren ) : (T ) this );
305
239
}
306
240
307
- @ SuppressWarnings ("unchecked" )
308
- protected void transformChildren (BiConsumer <? super T , ActionListener <T >> traversalOperation , ActionListener <T > listener ) {
309
- if (children .isEmpty ()) {
310
- listener .onResponse ((T ) this );
311
- return ;
312
- }
313
-
314
- final AtomicReference <List <T >> transformedChildren = new AtomicReference <>(null );
315
-
316
- CountDownActionListener countDownListener = new CountDownActionListener (
317
- children .size (),
318
- listener .delegateFailureIgnoreResponseAndWrap ((l ) -> {
319
- l .onResponse (transformedChildren .get () != null ? replaceChildren (transformedChildren .get ()) : (T ) this );
320
- })
321
- );
322
-
323
- for (int i = 0 , s = children .size (); i < s ; i ++) {
324
- T child = children .get (i );
325
- final int childId = i ;
326
- traversalOperation .accept (child , countDownListener .map (next -> {
327
- if (child .equals (next ) == false ) {
328
- transformedChildren .compareAndSet (null , new ArrayList <>(children ));
329
- transformedChildren .get ().set (childId , next );
330
- }
331
- return null ;
332
- }));
333
- }
334
- }
335
-
336
241
public final T replaceChildrenSameSize (List <T > newChildren ) {
337
242
if (newChildren .size () != children .size ()) {
338
243
throw new QlIllegalArgumentException (
@@ -352,38 +257,14 @@ public <E> T transformPropertiesOnly(Class<E> typeToken, Function<? super E, ? e
352
257
return transformNodeProps (typeToken , rule );
353
258
}
354
259
355
- public <E > void transformPropertiesOnly (
356
- Class <E > typeToken ,
357
- BiConsumer <? super E , ActionListener <? super E >> rule ,
358
- ActionListener <T > listener
359
- ) {
360
- transformNodeProps (typeToken , rule , listener );
361
- }
362
-
363
260
public <E > T transformPropertiesDown (Class <E > typeToken , Function <? super E , ? extends E > rule ) {
364
261
return transformDown (t -> t .transformNodeProps (typeToken , rule ));
365
262
}
366
263
367
- public <E > void transformPropertiesDown (
368
- Class <E > typeToken ,
369
- BiConsumer <? super E , ActionListener <? super E >> rule ,
370
- ActionListener <T > listener
371
- ) {
372
- transformDown ((t , l ) -> t .transformNodeProps (typeToken , rule , l ), listener );
373
- }
374
-
375
264
public <E > T transformPropertiesUp (Class <E > typeToken , Function <? super E , ? extends E > rule ) {
376
265
return transformUp (t -> t .transformNodeProps (typeToken , rule ));
377
266
}
378
267
379
- public <E > void transformPropertiesUp (
380
- Class <E > typeToken ,
381
- BiConsumer <? super E , ActionListener <? super E >> rule ,
382
- ActionListener <T > listener
383
- ) {
384
- transformUp ((t , l ) -> t .transformNodeProps (typeToken , rule , l ), listener );
385
- }
386
-
387
268
/**
388
269
* Transform this node's properties.
389
270
* <p>
@@ -396,14 +277,6 @@ protected final <E> T transformNodeProps(Class<E> typeToken, Function<? super E,
396
277
return info ().transform (rule , typeToken );
397
278
}
398
279
399
- protected final <E > void transformNodeProps (
400
- Class <E > typeToken ,
401
- BiConsumer <? super E , ActionListener <? super E >> rule ,
402
- ActionListener <T > listener
403
- ) {
404
- info ().transform (rule , typeToken , listener );
405
- }
406
-
407
280
/**
408
281
* Return the information about this node.
409
282
* <p>
0 commit comments