Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Feb 9, 2024
1 parent 70b9aad commit 2bfd0b2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.search.aggregations.bucket;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.common.settings.Settings;
Expand Down Expand Up @@ -69,7 +70,6 @@ protected void setupSuiteScopeCluster() throws Exception {
for (int i = 0; i < segmentCount; i++) {
final List<IndexRequestBuilder> indexRequests = new ArrayList<>();


long longTerm;
do {
longTerm = randomInt(segmentCount * 2);
Expand All @@ -81,15 +81,10 @@ protected void setupSuiteScopeCluster() throws Exception {
for (int j = 0; j < frequency; j++) {
indexRequests.add(
client().prepareIndex("idx")
.setSource(
jsonBuilder().startObject()
.field("date", dateTerm)
.field("match", true)
.endObject()
)
.setSource(jsonBuilder().startObject().field("date", dateTerm).field("match", true).endObject())
);
}
expected.put(dateTerm+"T00:00:00.000Z", (long) frequency);
expected.put(dateTerm + "T00:00:00.000Z", (long) frequency);

indexRandom(true, false, indexRequests);
}
Expand All @@ -103,17 +98,13 @@ public void testMinDocCountOnDateHistogram() throws Exception {
final SearchResponse allResponse = client().prepareSearch("idx")
.setSize(0)
.setQuery(QUERY)
.addAggregation(
dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0)
)
.addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0))
.get();

final Histogram allHisto = allResponse.getAggregations().get("histo");
logger.info("allHisto={}", allHisto);
Map<String, Long> results = new HashMap<>();
allHisto.getBuckets().forEach(bucket ->
results.put(bucket.getKeyAsString(), bucket.getDocCount())
);
allHisto.getBuckets().forEach(bucket -> results.put(bucket.getKeyAsString(), bucket.getDocCount()));

for (Map.Entry<String, Long> entry : expected.entrySet()) {
assertEquals(entry.getValue(), results.get(entry.getKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@

import com.carrotsearch.randomizedtesting.generators.RandomStrings;

import org.opensearch.action.admin.indices.segments.IndexShardSegments;
import org.opensearch.action.admin.indices.segments.IndicesSegmentResponse;
import org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest;
import org.opensearch.action.admin.indices.segments.ShardSegments;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchResponse;
Expand All @@ -46,7 +44,6 @@
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.engine.Segment;
import org.opensearch.index.fielddata.ScriptDocValues;
import org.opensearch.index.query.QueryBuilder;
import org.opensearch.index.query.QueryBuilders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ public Weight[] buildFastFilter(LeafReaderContext leaf, SearchContext context) t

private Weight[] buildFastFilter(SearchContext context, long[] bounds) throws IOException {
bounds = processHardBounds(bounds);
logger.debug("Bounds are {} for shard {} with hard bound", bounds, context.indexShard().shardId());
if (bounds == null) {
return null;
}
Expand Down Expand Up @@ -424,11 +423,6 @@ public static boolean tryFastFilterAggregation(
if (!fastFilterContext.rewriteable) {
return false;
}
logger.debug(
"try fast filter on Shard {} segment {}",
fastFilterContext.context.indexShard().shardId(),
ctx.ord
);

NumericDocValues docCountValues = DocValues.getNumeric(ctx.reader(), DocCountFieldMapper.NAME);
if (docCountValues.nextDoc() != NO_MORE_DOCS) {
Expand All @@ -447,11 +441,6 @@ public static boolean tryFastFilterAggregation(
}
Weight[] filters = fastFilterContext.filters;
boolean filtersBuiltAtSegmentLevel = false;
logger.debug(
"Shard {} segment {} functionally match all documents",
fastFilterContext.context.indexShard().shardId(),
ctx.ord
);
if (filters == null) {
logger.debug(
"Shard {} segment {} functionally match all documents. Build the fast filter",
Expand Down Expand Up @@ -498,7 +487,7 @@ public static boolean tryFastFilterAggregation(
}
}

// each segment computes its own filters, so reset
// each segment computes its own filters, so reset the filters built at segment
if (filtersBuiltAtSegmentLevel) {
fastFilterContext.filters = null;
}
Expand All @@ -509,12 +498,6 @@ public static boolean tryFastFilterAggregation(

private static boolean segmentMatchAll(SearchContext ctx, LeafReaderContext leafCtx) throws IOException {
Weight weight = ctx.searcher().createWeight(ctx.query(), ScoreMode.COMPLETE_NO_SCORES, 1f);
if (weight == null) {
return false;
}
int count = weight.count(leafCtx);
int numDocs = leafCtx.reader().numDocs();
logger.debug("Shard {} segment {} has {} count and {} num docs", ctx.indexShard().shardId(), leafCtx.ord, count, numDocs);
return weight != null && weight.count(leafCtx) == leafCtx.reader().numDocs();
}
}

0 comments on commit 2bfd0b2

Please sign in to comment.