Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the parent join aggregator test case #60991

Merged
merged 1 commit into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,19 @@
import org.apache.lucene.search.TermInSetQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.ContentPath;
import org.elasticsearch.index.mapper.MappingLookup;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.IdFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.MappingLookup;
import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.shard.ShardId;
Expand Down Expand Up @@ -75,7 +74,6 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/60980")
public class ChildrenToParentAggregatorTests extends AggregatorTestCase {

private static final String CHILD_TYPE = "child_type";
Expand Down Expand Up @@ -121,9 +119,11 @@ public void testParentChild() throws IOException {
expectedTotalParents++;
expectedMinValue = Math.min(expectedMinValue, expectedValues.v2());
}
assertEquals("Having " + parent.getDocCount() + " docs and aggregation results: " +
parent.getAggregations().asMap(),
expectedTotalParents, parent.getDocCount());
assertEquals(
"Having " + parent.getDocCount() + " docs and aggregation results: " + parent,
expectedTotalParents,
parent.getDocCount()
);
assertEquals(expectedMinValue, ((InternalMin) parent.getAggregations().get("in_parent")).getValue(), Double.MIN_VALUE);
assertTrue(JoinAggregationInspectionHelper.hasValue(parent));
});
Expand Down Expand Up @@ -235,21 +235,19 @@ private static Map<String, Tuple<Integer, Integer>> setupIndex(RandomIndexWriter
Map<String, Tuple<Integer, Integer>> expectedValues = new HashMap<>();
int numParents = randomIntBetween(1, 10);
for (int i = 0; i < numParents; i++) {
List<List<Field>> documents = new ArrayList<>();
String parent = "parent" + i;
int randomValue = randomIntBetween(0, 100);
List<Field> parentDocument = createParentDocument(parent, randomValue);
/*long parentDocId =*/ iw.addDocument(parentDocument);
//System.out.println("Parent: " + parent + ": " + randomValue + ", id: " + parentDocId);
documents.add(createParentDocument(parent, randomValue));
int numChildren = randomIntBetween(1, 10);
int minValue = Integer.MAX_VALUE;
for (int c = 0; c < numChildren; c++) {
minValue = Math.min(minValue, randomValue);
int randomSubValue = randomIntBetween(0, 100);
List<Field> childDocument = createChildDocument("child" + c + "_" + parent, parent, randomSubValue);
/*long childDocId =*/ iw.addDocument(childDocument);
//System.out.println("Child: " + "child" + c + "_" + parent + ": " + randomSubValue + ", id: " + childDocId);
documents.add(createChildDocument("child" + c + "_" + parent, parent, randomSubValue));
}
expectedValues.put(parent, new Tuple<>(numChildren, minValue));
iw.addDocuments(documents);
}
return expectedValues;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,12 @@ protected <A extends InternalAggregation, C extends Aggregator> A searchAndReduc
}

/**
* Divides the provided {@link IndexSearcher} in sub-searcher, one for each segment,
* builds an aggregator for each sub-searcher filtered by the provided {@link Query} and
* Collects all documents that match the provided query {@link Query} and
* returns the reduced {@link InternalAggregation}.
* <p>
* Half the time it aggregates each leaf individually and reduces all
* results together. The other half the time it aggregates across the entire
* index at once and runs a final reduction on the single resulting agg.
*/
protected <A extends InternalAggregation, C extends Aggregator> A searchAndReduce(IndexSettings indexSettings,
IndexSearcher searcher,
Expand Down