From 096d7fa26ff37650d1c497fb8579938c61c56a6c Mon Sep 17 00:00:00 2001 From: bowenlan-amzn Date: Thu, 8 Feb 2024 21:25:04 -0800 Subject: [PATCH] clean up Signed-off-by: bowenlan-amzn --- .../aggregations/bucket/FilterRewriteIT.java | 25 ++++------------- .../aggregations/bucket/MinDocCountIT.java | 27 +------------------ .../bucket/FastFilterRewriteHelper.java | 19 +------------ 3 files changed, 7 insertions(+), 64 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/FilterRewriteIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/FilterRewriteIT.java index ee1ced60e68e4..35e024603f0f2 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/FilterRewriteIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/FilterRewriteIT.java @@ -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; @@ -59,9 +60,6 @@ public static Collection parameters() { protected void setupSuiteScopeCluster() throws Exception { assertAcked(client().admin().indices().prepareCreate("idx").get()); - // one segment has some docs - // the other segment has some other docs - // check the results are correct final int segmentCount = randomIntBetween(2, 10); final Set longTerms = new HashSet(); @@ -69,7 +67,6 @@ protected void setupSuiteScopeCluster() throws Exception { for (int i = 0; i < segmentCount; i++) { final List indexRequests = new ArrayList<>(); - long longTerm; do { longTerm = randomInt(segmentCount * 2); @@ -81,21 +78,14 @@ 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); } - logger.info("expected results dateTerms={}", dateTerms); - ensureSearchable(); } @@ -103,17 +93,12 @@ 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 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 entry : expected.entrySet()) { assertEquals(entry.getValue(), results.get(entry.getKey())); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/MinDocCountIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/MinDocCountIT.java index c6f82270b67f4..781d2acc5e2be 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/MinDocCountIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/MinDocCountIT.java @@ -34,19 +34,11 @@ 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; import org.opensearch.common.settings.Settings; import org.opensearch.common.time.DateFormatter; -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; @@ -135,7 +127,6 @@ public void setupSuiteScopeCluster() throws Exception { final List indexRequests = new ArrayList<>(); final Set stringTerms = new HashSet<>(); final Set longTerms = new HashSet(); - final HashMap dateTerms = new HashMap<>(); for (int i = 0; i < cardinality; ++i) { String stringTerm; do { @@ -151,7 +142,6 @@ public void setupSuiteScopeCluster() throws Exception { String dateTerm = DateFormatter.forPattern("yyyy-MM-dd").format(time); final int frequency = randomBoolean() ? 1 : randomIntBetween(2, 20); for (int j = 0; j < frequency; ++j) { - final boolean match = randomBoolean(); indexRequests.add( client().prepareIndex("idx") .setSource( @@ -160,18 +150,14 @@ public void setupSuiteScopeCluster() throws Exception { .field("l", longTerm) .field("d", doubleTerm) .field("date", dateTerm) - .field("match", match) + .field("match", randomBoolean()) .endObject() ) ); - if (match) { - dateTerms.put(dateTerm, dateTerms.getOrDefault(dateTerm, 0) + 1); - } } } cardinality = stringTerms.size(); - logger.info("date terms {}", dateTerms); indexRandom(true, indexRequests); ensureSearchable(); } @@ -441,14 +427,6 @@ private void testMinDocCountOnHistogram(BucketOrder order) throws Exception { } private void testMinDocCountOnDateHistogram(BucketOrder order) throws Exception { - - IndicesSegmentsRequest segmentReq = new IndicesSegmentsRequest("idx"); - IndicesSegmentResponse segmentRes = client().admin().indices().segments(segmentReq).get(); - XContentBuilder builder = XContentFactory.jsonBuilder(); - segmentRes.toXContent(builder, ToXContent.EMPTY_PARAMS); - String jsonString = builder.toString(); - logger.info("segmentRes={}", jsonString); - final SearchResponse allResponse = client().prepareSearch("idx") .setSize(0) .setQuery(QUERY) @@ -458,7 +436,6 @@ private void testMinDocCountOnDateHistogram(BucketOrder order) throws Exception .get(); final Histogram allHisto = allResponse.getAggregations().get("histo"); - logger.info("allHisto={}", allHisto); for (long minDocCount = 0; minDocCount < 50; ++minDocCount) { final SearchResponse response = client().prepareSearch("idx") @@ -471,8 +448,6 @@ private void testMinDocCountOnDateHistogram(BucketOrder order) throws Exception .minDocCount(minDocCount) ) .get(); - final Histogram minDocHisto = response.getAggregations().get("histo"); - logger.info("minDocCount={},minDocHisto={}", minDocCount, minDocHisto); assertSubset(allHisto, response.getAggregations().get("histo"), minDocCount); } } diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/FastFilterRewriteHelper.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/FastFilterRewriteHelper.java index bf2804174037f..363498f4b7326 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/FastFilterRewriteHelper.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/FastFilterRewriteHelper.java @@ -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; } @@ -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) { @@ -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", @@ -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 level if (filtersBuiltAtSegmentLevel) { fastFilterContext.filters = null; } @@ -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(); } }