Search in sources :

Example 1 with GeoPoints

use of org.opensearch.index.fielddata.ScriptDocValues.GeoPoints in project OpenSearch by opensearch-project.

the class ScriptDocValuesGeoPointsTests method testMissingValues.

public void testMissingValues() throws IOException {
    GeoPoint[][] points = new GeoPoint[between(3, 10)][];
    for (int d = 0; d < points.length; d++) {
        points[d] = new GeoPoint[randomBoolean() ? 0 : between(1, 10)];
        for (int i = 0; i < points[d].length; i++) {
            points[d][i] = new GeoPoint(randomLat(), randomLon());
        }
    }
    final ScriptDocValues.GeoPoints geoPoints = new GeoPoints(wrap(points));
    for (int d = 0; d < points.length; d++) {
        geoPoints.setNextDocId(d);
        if (points[d].length > 0) {
            assertEquals(points[d][0], geoPoints.getValue());
        } else {
            Exception e = expectThrows(IllegalStateException.class, () -> geoPoints.getValue());
            assertEquals("A document doesn't have a value for a field! " + "Use doc[<field>].size()==0 to check if a document is missing a field!", e.getMessage());
            e = expectThrows(IllegalStateException.class, () -> geoPoints.get(0));
            assertEquals("A document doesn't have a value for a field! " + "Use doc[<field>].size()==0 to check if a document is missing a field!", e.getMessage());
        }
        assertEquals(points[d].length, geoPoints.size());
        for (int i = 0; i < points[d].length; i++) {
            assertEquals(points[d][i], geoPoints.get(i));
        }
    }
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) GeoPoints(org.opensearch.index.fielddata.ScriptDocValues.GeoPoints) GeoPoints(org.opensearch.index.fielddata.ScriptDocValues.GeoPoints) GeoPoint(org.opensearch.common.geo.GeoPoint) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 GeoPoint (org.opensearch.common.geo.GeoPoint)1 GeoPoints (org.opensearch.index.fielddata.ScriptDocValues.GeoPoints)1