35
35
import stroom .query .language .functions .ExpressionContext ;
36
36
import stroom .query .language .functions .FieldIndex ;
37
37
import stroom .query .language .functions .Val ;
38
+ import stroom .query .language .functions .ValNull ;
38
39
import stroom .query .language .functions .ref .ErrorConsumer ;
39
40
import stroom .util .NullSafe ;
40
41
import stroom .util .concurrent .UncheckedInterruptedException ;
49
50
import java .util .Map ;
50
51
import java .util .Objects ;
51
52
import java .util .Optional ;
53
+ import java .util .function .Consumer ;
52
54
import java .util .function .Function ;
53
55
import java .util .function .Predicate ;
54
56
@@ -430,7 +432,42 @@ public DataStore map(final DataStore dataStore,
430
432
parent .getAggregateFilter (),
431
433
dataStore .getDateTimeSettings (),
432
434
expressionPredicateFactory );
433
- final Predicate <Val []> predicate = filter .orElse (vals -> true );
435
+ final Consumer <Item > consumer = filter .map (predicate -> (Consumer <Item >) item -> {
436
+ final List <Column > parentColumns = parent .getColumns ();
437
+ final Val [] parentValues = new Val [parentColumns .size ()];
438
+ for (int i = 0 ; i < parentValues .length ; i ++) {
439
+ // TODO : @66 Currently evaluating more values than will be needed as we don't know what is
440
+ // needed by the filter.
441
+ parentValues [i ] = item .getValue (i );
442
+ }
443
+
444
+ if (predicate .test (parentValues )) {
445
+ final Val [] values = new Val [parentFieldIndices .length ];
446
+ for (int i = 0 ; i < parentFieldIndices .length ; i ++) {
447
+ final int index = parentFieldIndices [i ];
448
+ if (index != -1 ) {
449
+ // TODO : @66 Currently evaluating more values than will be needed.
450
+ values [i ] = parentValues [index ];
451
+ } else {
452
+ values [i ] = ValNull .INSTANCE ;
453
+ }
454
+ }
455
+ childDataStore .accept (Val .of (values ));
456
+ }
457
+ }).orElseGet (() -> item -> {
458
+ final Val [] values = new Val [parentFieldIndices .length ];
459
+ for (int i = 0 ; i < parentFieldIndices .length ; i ++) {
460
+ final int index = parentFieldIndices [i ];
461
+ if (index != -1 ) {
462
+ // TODO : @66 Currently evaluating more values than will be needed.
463
+ final Val val = item .getValue (index );
464
+ values [i ] = val ;
465
+ } else {
466
+ values [i ] = ValNull .INSTANCE ;
467
+ }
468
+ }
469
+ childDataStore .accept (Val .of (values ));
470
+ });
434
471
435
472
// Get top level items.
436
473
// TODO : Add an option to get detail level items rather than root level items.
@@ -440,22 +477,7 @@ public DataStore map(final DataStore dataStore,
440
477
OpenGroups .NONE ,
441
478
timeFilter ,
442
479
IdentityItemMapper .INSTANCE ,
443
- item -> {
444
- final Val [] values = new Val [parentFieldIndices .length ];
445
- for (int i = 0 ; i < parentFieldIndices .length ; i ++) {
446
- final int index = parentFieldIndices [i ];
447
- if (index != -1 ) {
448
- // TODO : @66 Currently evaluating more values than will be needed.
449
- final Val val = item .getValue (index );
450
- values [i ] = val ;
451
- }
452
- }
453
-
454
- // Filter values.
455
- if (predicate .test (values )) {
456
- childDataStore .accept (Val .of (values ));
457
- }
458
- },
480
+ consumer ,
459
481
null );
460
482
461
483
return childDataStore ;
0 commit comments