forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
package name -> filterrewrite move tree traversal logic to new class add documentation for important abstract methods add sub class for composite aggregation bridge Signed-off-by: bowenlan-amzn <[email protected]>
- Loading branch information
1 parent
3a60a81
commit 094c25b
Showing
14 changed files
with
402 additions
and
311 deletions.
There are no files selected for viewing
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
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
76 changes: 76 additions & 0 deletions
76
server/src/main/java/org/opensearch/search/optimization/filterrewrite/AggregatorBridge.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,76 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.search.optimization.filterrewrite; | ||
|
||
import org.apache.lucene.index.LeafReaderContext; | ||
import org.apache.lucene.index.PointValues; | ||
import org.opensearch.index.mapper.MappedFieldType; | ||
|
||
import java.io.IOException; | ||
import java.util.function.BiConsumer; | ||
|
||
/** | ||
* This interface provides a bridge between an aggregator and the optimization context, allowing | ||
* the aggregator to provide data and optimize the aggregation process. | ||
* | ||
* <p>The main purpose of this interface is to encapsulate the aggregator-specific optimization | ||
* logic and provide access to the data in Aggregator that is required for optimization, while keeping the optimization | ||
* business logic separate from the aggregator implementation. | ||
* | ||
* <p>To use this interface to optimize an aggregator, you should subclass this interface in this package | ||
* and put any specific optimization business logic in it. Then implement this subclass in the aggregator | ||
* to provide data that is needed for doing the optimization | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public abstract class AggregatorBridge { | ||
|
||
/** | ||
* The optimization context associated with this aggregator bridge. | ||
*/ | ||
OptimizationContext optimizationContext; | ||
|
||
/** | ||
* The field type associated with this aggregator bridge. | ||
*/ | ||
MappedFieldType fieldType; | ||
|
||
void setOptimizationContext(OptimizationContext context) { | ||
this.optimizationContext = context; | ||
} | ||
|
||
/** | ||
* Checks whether the aggregator can be optimized. | ||
* | ||
* @return {@code true} if the aggregator can be optimized, {@code false} otherwise. | ||
* The result will be saved in the optimization context. | ||
*/ | ||
public abstract boolean canOptimize(); | ||
|
||
/** | ||
* Prepares the optimization at shard level. | ||
* For example, figure out what are the ranges from the aggregation to do the optimization later | ||
*/ | ||
public abstract void prepare() throws IOException; | ||
|
||
/** | ||
* Prepares the optimization for a specific segment and ignore whatever built at shard level | ||
* | ||
* @param leaf the leaf reader context for the segment | ||
*/ | ||
public abstract void prepareFromSegment(LeafReaderContext leaf) throws IOException; | ||
|
||
/** | ||
* Attempts to build aggregation results for a segment | ||
* | ||
* @param values the point values (index structure for numeric values) for a segment | ||
* @param incrementDocCount a consumer to increment the document count for a range bucket. The First parameter is document count, the second is the key of the bucket | ||
*/ | ||
public abstract void tryOptimize(PointValues values, BiConsumer<Long, Long> incrementDocCount) throws IOException; | ||
} |
36 changes: 36 additions & 0 deletions
36
...main/java/org/opensearch/search/optimization/filterrewrite/CompositeAggregatorBridge.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,36 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.search.optimization.filterrewrite; | ||
|
||
import org.opensearch.index.mapper.DateFieldMapper; | ||
import org.opensearch.index.mapper.MappedFieldType; | ||
import org.opensearch.search.aggregations.bucket.composite.CompositeValuesSourceConfig; | ||
import org.opensearch.search.aggregations.bucket.composite.RoundingValuesSource; | ||
|
||
/** | ||
* For composite aggregation to do optimization when it only has a single date histogram source | ||
*/ | ||
public abstract class CompositeAggregatorBridge extends DateHistogramAggregatorBridge { | ||
protected boolean canOptimize(CompositeValuesSourceConfig[] sourceConfigs) { | ||
if (sourceConfigs.length != 1 || !(sourceConfigs[0].valuesSource() instanceof RoundingValuesSource)) return false; | ||
return canOptimize(sourceConfigs[0].missingBucket(), sourceConfigs[0].hasScript(), sourceConfigs[0].fieldType()); | ||
} | ||
|
||
private boolean canOptimize(boolean missing, boolean hasScript, MappedFieldType fieldType) { | ||
if (!missing && !hasScript) { | ||
if (fieldType instanceof DateFieldMapper.DateFieldType) { | ||
if (fieldType.isSearchable()) { | ||
this.fieldType = fieldType; | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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
Oops, something went wrong.