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

Tests for agg missing values #51068

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -76,14 +76,23 @@ public void testNoDocs() throws IOException {
});
}

public void testFieldMissing() throws IOException {
public void testUnmapped() throws IOException {
testCase(new MatchAllDocsQuery(), "wrong_field", randomPrecision(), null, geoGrid -> {
assertEquals(0, geoGrid.getBuckets().size());
}, iw -> {
iw.addDocument(Collections.singleton(new LatLonDocValuesField(FIELD_NAME, 10D, 10D)));
});
}

public void testUnmappedMissing() throws IOException {
GeoGridAggregationBuilder builder = createBuilder("_name")
.field("wrong_field")
.missing("53.69437,6.475031");
testCase(new MatchAllDocsQuery(), randomPrecision(), null, geoGrid -> assertEquals(1, geoGrid.getBuckets().size()),
iw -> iw.addDocument(Collections.singleton(new LatLonDocValuesField(FIELD_NAME, 10D, 10D))), builder);

}

public void testWithSeveralDocs() throws IOException {
int precision = randomPrecision();
int numPoints = randomIntBetween(8, 128);
Expand Down Expand Up @@ -188,6 +197,13 @@ public void testBounds() throws IOException {
private void testCase(Query query, String field, int precision, GeoBoundingBox geoBoundingBox,
Consumer<InternalGeoGrid<T>> verify,
CheckedConsumer<RandomIndexWriter, IOException> buildIndex) throws IOException {
testCase(query, precision, geoBoundingBox, verify, buildIndex, createBuilder("_name").field(field));
}

private void testCase(Query query, int precision, GeoBoundingBox geoBoundingBox,
Consumer<InternalGeoGrid<T>> verify,
CheckedConsumer<RandomIndexWriter, IOException> buildIndex,
GeoGridAggregationBuilder aggregationBuilder) throws IOException {
Directory directory = newDirectory();
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
buildIndex.accept(indexWriter);
Expand All @@ -196,7 +212,6 @@ private void testCase(Query query, String field, int precision, GeoBoundingBox g
IndexReader indexReader = DirectoryReader.open(directory);
IndexSearcher indexSearcher = newSearcher(indexReader, true, true);

GeoGridAggregationBuilder aggregationBuilder = createBuilder("_name").field(field);
aggregationBuilder.precision(precision);
if (geoBoundingBox != null) {
aggregationBuilder.setGeoBoundingBox(geoBoundingBox);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ public void testAggregateWrongField() throws IOException {
);
}

public void testUnmappedMissing() throws IOException {
testBothCases(DEFAULT_QUERY, DATES_WITH_TIME,
aggregation -> aggregation.setNumBuckets(10).field("wrong_field").missing("2017-12-12"),
histogram -> {
assertEquals(1, histogram.getBuckets().size());
assertTrue(AggregationInspectionHelper.hasValue(histogram));
}
);
}


public void testIntervalYear() throws IOException {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ public void testUnmapped() throws Exception {
}
}

public void testUnmappedWithMissing() throws Exception {
try (Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir)) {
GeoCentroidAggregationBuilder aggBuilder = new GeoCentroidAggregationBuilder("my_agg")
.field("another_field")
.missing("53.69437,6.475031");

GeoPoint expectedCentroid = new GeoPoint(53.69437, 6.475031);
Document document = new Document();
document.add(new LatLonDocValuesField("field", 10, 10));
w.addDocument(document);
try (IndexReader reader = w.getReader()) {
IndexSearcher searcher = new IndexSearcher(reader);

MappedFieldType fieldType = new GeoPointFieldMapper.GeoPointFieldType();
fieldType.setHasDocValues(true);
fieldType.setName("another_field");
InternalGeoCentroid result = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
assertEquals(result.centroid(), expectedCentroid);
assertTrue(AggregationInspectionHelper.hasValue(result));
}
}
}

public void testSingleValuedField() throws Exception {
int numDocs = scaledRandomIntBetween(64, 256);
int numUniqueGeoPoints = randomIntBetween(1, numDocs);
Expand Down