-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-5133 Refactor extracting AggregationFunctionCollector
- Loading branch information
Showing
12 changed files
with
145 additions
and
177 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...ernate/search/backend/lucene/lowlevel/aggregation/collector/impl/AggregationFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.search.backend.lucene.lowlevel.aggregation.collector.impl; | ||
|
||
public interface AggregationFunction<R extends AggregationFunction<?>> { | ||
|
||
void apply(long value); | ||
|
||
void merge(AggregationFunction<R> sibling); | ||
|
||
long result(); | ||
|
||
R implementation(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ckend/lucene/lowlevel/aggregation/collector/impl/AggregationFunctionCollectorManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.search.backend.lucene.lowlevel.aggregation.collector.impl; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
import java.util.function.Supplier; | ||
|
||
import org.hibernate.search.backend.lucene.lowlevel.docvalues.impl.JoiningLongMultiValuesSource; | ||
|
||
import org.apache.lucene.search.CollectorManager; | ||
|
||
public class AggregationFunctionCollectorManager<T extends AggregationFunction<?>> | ||
implements CollectorManager<AggregationFunctionCollector<T>, Long> { | ||
|
||
private final JoiningLongMultiValuesSource source; | ||
private final Supplier<AggregationFunction<T>> functionSupplier; | ||
|
||
public AggregationFunctionCollectorManager(JoiningLongMultiValuesSource source, | ||
Supplier<AggregationFunction<T>> functionSupplier) { | ||
this.source = source; | ||
this.functionSupplier = functionSupplier; | ||
} | ||
|
||
@Override | ||
public AggregationFunctionCollector<T> newCollector() { | ||
return new AggregationFunctionCollector<>( source, functionSupplier.get() ); | ||
} | ||
|
||
@Override | ||
public Long reduce(Collection<AggregationFunctionCollector<T>> collectors) throws IOException { | ||
if ( collectors.isEmpty() ) { | ||
return null; | ||
} | ||
|
||
LinkedList<AggregationFunctionCollector<T>> distinctCollectors = new LinkedList<>( collectors ); | ||
AggregationFunctionCollector<T> collector = distinctCollectors.removeLast(); | ||
for ( AggregationFunctionCollector<T> other : distinctCollectors ) { | ||
collector.merge( other ); | ||
} | ||
return collector.result(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
...rch/backend/lucene/lowlevel/aggregation/collector/impl/CountDistinctCollectorManager.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
...ain/java/org/hibernate/search/backend/lucene/lowlevel/aggregation/collector/impl/Sum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.search.backend.lucene.lowlevel.aggregation.collector.impl; | ||
|
||
public class Sum implements AggregationFunction<Sum> { | ||
|
||
private long sum = 0L; | ||
|
||
@Override | ||
public void apply(long value) { | ||
sum += value; | ||
} | ||
|
||
@Override | ||
public void merge(AggregationFunction<Sum> sibling) { | ||
apply( sibling.result() ); | ||
} | ||
|
||
@Override | ||
public long result() { | ||
return sum; | ||
} | ||
|
||
@Override | ||
public Sum implementation() { | ||
return this; | ||
} | ||
} |
63 changes: 0 additions & 63 deletions
63
...org/hibernate/search/backend/lucene/lowlevel/aggregation/collector/impl/SumCollector.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
...ernate/search/backend/lucene/lowlevel/aggregation/collector/impl/SumCollectorManager.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.