1515import org .elasticsearch .compute .operator .DriverContext ;
1616
1717import java .util .List ;
18- import java .util .concurrent .atomic .AtomicBoolean ;
1918
2019public class PresentAggregatorFunction implements AggregatorFunction {
2120 public static AggregatorFunctionSupplier supplier () {
@@ -55,14 +54,15 @@ public static List<IntermediateStateDesc> intermediateStateDesc() {
5554 return INTERMEDIATE_STATE_DESC ;
5655 }
5756
58- private final AtomicBoolean state ;
5957 private final List <Integer > channels ;
6058
59+ private boolean state ;
60+
6161 public static PresentAggregatorFunction create (List <Integer > inputChannels ) {
62- return new PresentAggregatorFunction (inputChannels , new AtomicBoolean ( false ) );
62+ return new PresentAggregatorFunction (inputChannels , false );
6363 }
6464
65- private PresentAggregatorFunction (List <Integer > channels , AtomicBoolean state ) {
65+ private PresentAggregatorFunction (List <Integer > channels , boolean state ) {
6666 this .channels = channels ;
6767 this .state = state ;
6868 }
@@ -78,17 +78,10 @@ private int blockIndex() {
7878
7979 @ Override
8080 public void addRawInput (Page page , BooleanVector mask ) {
81+ if (mask .isConstant () && mask .getBoolean (0 ) == false ) return ;
82+
8183 Block block = page .getBlock (blockIndex ());
82- boolean present ;
83- if (mask .isConstant ()) {
84- if (mask .getBoolean (0 ) == false ) {
85- return ;
86- }
87- present = block .getTotalValueCount () > 0 ;
88- } else {
89- present = presentMasked (block , mask );
90- }
91- this .state .set (present );
84+ this .state = mask .isConstant () ? block .getTotalValueCount () > 0 : presentMasked (block , mask );
9285 }
9386
9487 private boolean presentMasked (Block block , BooleanVector mask ) {
@@ -112,7 +105,7 @@ public void addIntermediateInput(Page page) {
112105 BooleanVector present = page .<BooleanBlock >getBlock (channels .get (0 )).asVector ();
113106 assert present .getPositionCount () == 1 ;
114107 if (present .getBoolean (0 )) {
115- state . set ( true ) ;
108+ this . state = true ;
116109 }
117110 }
118111
@@ -123,7 +116,7 @@ public void evaluateIntermediate(Block[] blocks, int offset, DriverContext drive
123116
124117 @ Override
125118 public void evaluateFinal (Block [] blocks , int offset , DriverContext driverContext ) {
126- blocks [offset ] = driverContext .blockFactory ().newConstantBooleanBlockWith (state . get () , 1 );
119+ blocks [offset ] = driverContext .blockFactory ().newConstantBooleanBlockWith (state , 1 );
127120 }
128121
129122 @ Override
0 commit comments