@@ -309,94 +309,94 @@ public final String toString() {
309
309
public final void close () {
310
310
Releasables .closeExpectNoException (() -> Releasables .close (evaluators ));
311
311
}
312
- }
313
312
314
- /**
315
- * Evaluates {@code COALESCE} eagerly per position if entire-block evaluation fails.
316
- * First we evaluate all remaining evaluators, and then we pluck the first non-null
317
- * value from each one. This is <strong>much</strong> faster than
318
- * {@link CoalesceLazyEvaluator} but will include spurious warnings if any of the
319
- * evaluators make them so we only use it for evaluators that are
320
- * {@link ExpressionEvaluator.Factory#eagerEvalSafeInLazy safe} to evaluate eagerly
321
- * in a lazy environment.
322
- */
323
- private static final class CoalesceEagerEvaluator extends AbstractCoalesceEvaluator {
324
- CoalesceEagerEvaluator (DriverContext driverContext , ElementType resultType , List <ExpressionEvaluator > evaluators ) {
325
- super (driverContext , resultType , evaluators );
326
- }
313
+ /**
314
+ * Evaluates {@code COALESCE} eagerly per position if entire-block evaluation fails.
315
+ * First we evaluate all remaining evaluators, and then we pluck the first non-null
316
+ * value from each one. This is <strong>much</strong> faster than
317
+ * {@link CoalesceLazyEvaluator} but will include spurious warnings if any of the
318
+ * evaluators make them so we only use it for evaluators that are
319
+ * {@link ExpressionEvaluator.Factory#eagerEvalSafeInLazy safe} to evaluate eagerly
320
+ * in a lazy environment.
321
+ */
322
+ private static final class CoalesceEagerEvaluator extends AbstractCoalesceEvaluator {
323
+ CoalesceEagerEvaluator (DriverContext driverContext , ElementType resultType , List <ExpressionEvaluator > evaluators ) {
324
+ super (driverContext , resultType , evaluators );
325
+ }
327
326
328
- @ Override
329
- protected Block perPosition (Page page , Block lastFullBlock , int firstToEvaluate ) {
330
- int positionCount = page .getPositionCount ();
331
- Block [] flatten = new Block [evaluators .size () - firstToEvaluate + 1 ];
332
- try {
333
- flatten [0 ] = lastFullBlock ;
334
- for (int f = 1 ; f < flatten .length ; f ++) {
335
- flatten [f ] = evaluators .get (firstToEvaluate + f - 1 ).eval (page );
336
- }
337
- try (Block .Builder result = resultType .newBlockBuilder (positionCount , driverContext .blockFactory ())) {
338
- position : for (int p = 0 ; p < positionCount ; p ++) {
339
- for (Block f : flatten ) {
340
- if (false == f .isNull (p )) {
341
- result .copyFrom (f , p , p + 1 );
342
- continue position ;
327
+ @ Override
328
+ protected Block perPosition (Page page , Block lastFullBlock , int firstToEvaluate ) {
329
+ int positionCount = page .getPositionCount ();
330
+ Block [] flatten = new Block [evaluators .size () - firstToEvaluate + 1 ];
331
+ try {
332
+ flatten [0 ] = lastFullBlock ;
333
+ for (int f = 1 ; f < flatten .length ; f ++) {
334
+ flatten [f ] = evaluators .get (firstToEvaluate + f - 1 ).eval (page );
335
+ }
336
+ try (Block .Builder result = resultType .newBlockBuilder (positionCount , driverContext .blockFactory ())) {
337
+ position : for (int p = 0 ; p < positionCount ; p ++) {
338
+ for (Block f : flatten ) {
339
+ if (false == f .isNull (p )) {
340
+ result .copyFrom (f , p , p + 1 );
341
+ continue position ;
342
+ }
343
343
}
344
+ result .appendNull ();
344
345
}
345
- result .appendNull ();
346
+ return result .build ();
346
347
}
347
- return result .build ();
348
+ } finally {
349
+ Releasables .close (flatten );
348
350
}
349
- } finally {
350
- Releasables .close (flatten );
351
351
}
352
352
}
353
- }
354
353
355
- /**
356
- * Evaluates {@code COALESCE} lazily per position if entire-block evaluation fails.
357
- * For each position we either:
358
- * <ul>
359
- * <li>Take the non-null values from the {@code lastFullBlock}</li>
360
- * <li>
361
- * Evaluator the remaining evaluators one at a time, keeping
362
- * the first non-null value.
363
- * </li>
364
- * </ul>
365
- */
366
- private static final class CoalesceLazyEvaluator extends AbstractCoalesceEvaluator {
367
- CoalesceLazyEvaluator (DriverContext driverContext , ElementType resultType , List <ExpressionEvaluator > evaluators ) {
368
- super (driverContext , resultType , evaluators );
369
- }
354
+ /**
355
+ * Evaluates {@code COALESCE} lazily per position if entire-block evaluation fails.
356
+ * For each position we either:
357
+ * <ul>
358
+ * <li>Take the non-null values from the {@code lastFullBlock}</li>
359
+ * <li>
360
+ * Evaluator the remaining evaluators one at a time, keeping
361
+ * the first non-null value.
362
+ * </li>
363
+ * </ul>
364
+ */
365
+ private static final class CoalesceLazyEvaluator extends AbstractCoalesceEvaluator {
366
+ CoalesceLazyEvaluator (DriverContext driverContext , ElementType resultType , List <ExpressionEvaluator > evaluators ) {
367
+ super (driverContext , resultType , evaluators );
368
+ }
370
369
371
- @ Override
372
- protected Block perPosition (Page page , Block lastFullBlock , int firstToEvaluate ) {
373
- int positionCount = page .getPositionCount ();
374
- try (Block .Builder result = resultType .newBlockBuilder (positionCount , driverContext .blockFactory ())) {
375
- position : for (int p = 0 ; p < positionCount ; p ++) {
376
- if (lastFullBlock .isNull (p ) == false ) {
377
- result .copyFrom (lastFullBlock , p , p + 1 );
378
- continue ;
379
- }
380
- int [] positions = new int [] { p };
381
- Page limited = new Page (
382
- 1 ,
383
- IntStream .range (0 , page .getBlockCount ()).mapToObj (b -> page .getBlock (b ).filter (positions )).toArray (Block []::new )
384
- );
385
- try (Releasable ignored = limited ::releaseBlocks ) {
386
- for (int e = firstToEvaluate ; e < evaluators .size (); e ++) {
387
- try (Block block = evaluators .get (e ).eval (limited )) {
388
- if (false == block .isNull (0 )) {
389
- result .copyFrom (block , 0 , 1 );
390
- continue position ;
370
+ @ Override
371
+ protected Block perPosition (Page page , Block lastFullBlock , int firstToEvaluate ) {
372
+ int positionCount = page .getPositionCount ();
373
+ try (Block .Builder result = resultType .newBlockBuilder (positionCount , driverContext .blockFactory ())) {
374
+ position : for (int p = 0 ; p < positionCount ; p ++) {
375
+ if (lastFullBlock .isNull (p ) == false ) {
376
+ result .copyFrom (lastFullBlock , p , p + 1 );
377
+ continue ;
378
+ }
379
+ int [] positions = new int [] { p };
380
+ Page limited = new Page (
381
+ 1 ,
382
+ IntStream .range (0 , page .getBlockCount ()).mapToObj (b -> page .getBlock (b ).filter (positions )).toArray (Block []::new )
383
+ );
384
+ try (Releasable ignored = limited ::releaseBlocks ) {
385
+ for (int e = firstToEvaluate ; e < evaluators .size (); e ++) {
386
+ try (Block block = evaluators .get (e ).eval (limited )) {
387
+ if (false == block .isNull (0 )) {
388
+ result .copyFrom (block , 0 , 1 );
389
+ continue position ;
390
+ }
391
391
}
392
392
}
393
+ result .appendNull ();
393
394
}
394
- result .appendNull ();
395
395
}
396
+ return result .build ();
397
+ } finally {
398
+ lastFullBlock .close ();
396
399
}
397
- return result .build ();
398
- } finally {
399
- lastFullBlock .close ();
400
400
}
401
401
}
402
402
}
0 commit comments