|
@@ -10,16 +10,20 @@ package org.elasticsearch.xpack.transform.transforms.pivot;
|
|
|
import org.elasticsearch.common.geo.GeoPoint;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
import org.elasticsearch.script.Script;
|
|
|
+import org.elasticsearch.search.DocValueFormat;
|
|
|
import org.elasticsearch.search.aggregations.Aggregation;
|
|
|
import org.elasticsearch.search.aggregations.AggregationBuilder;
|
|
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
|
|
import org.elasticsearch.search.aggregations.AggregationReduceContext;
|
|
|
import org.elasticsearch.search.aggregations.InternalAggregation;
|
|
|
+import org.elasticsearch.search.aggregations.InternalAggregations;
|
|
|
import org.elasticsearch.search.aggregations.PipelineAggregationBuilder;
|
|
|
import org.elasticsearch.search.aggregations.PipelineAggregatorBuilders;
|
|
|
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregation;
|
|
|
import org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregation;
|
|
|
import org.elasticsearch.search.aggregations.bucket.composite.ParsedComposite;
|
|
|
+import org.elasticsearch.search.aggregations.bucket.range.InternalRange;
|
|
|
+import org.elasticsearch.search.aggregations.bucket.range.Range;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.DoubleTerms;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.LongTerms;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.ParsedDoubleTerms;
|
|
@@ -72,7 +76,6 @@ import org.elasticsearch.xpack.core.transform.transforms.pivot.GroupConfig;
|
|
|
import org.elasticsearch.xpack.transform.transforms.pivot.AggregationResultUtils.BucketKeyExtractor;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
@@ -873,7 +876,7 @@ public class AggregationResultUtilsTests extends ESTestCase {
|
|
|
expectedObject.put("type", type);
|
|
|
double lat = randomDoubleBetween(-90.0, 90.0, false);
|
|
|
double lon = randomDoubleBetween(-180.0, 180.0, false);
|
|
|
- expectedObject.put("coordinates", Arrays.asList(lon, lat));
|
|
|
+ expectedObject.put("coordinates", asList(lon, lat));
|
|
|
agg = createGeoBounds(new GeoPoint(lat, lon), new GeoPoint(lat, lon));
|
|
|
assertThat(AggregationResultUtils.getExtractor(agg).value(agg, Collections.emptyMap(), ""), equalTo(expectedObject));
|
|
|
}
|
|
@@ -920,12 +923,12 @@ public class AggregationResultUtilsTests extends ESTestCase {
|
|
|
List<List<Double[]>> coordinates = (List<List<Double[]>>) geoJson.get("coordinates");
|
|
|
assertThat(coordinates.size(), equalTo(1));
|
|
|
assertThat(coordinates.get(0).size(), equalTo(5));
|
|
|
- List<List<Double>> expected = Arrays.asList(
|
|
|
- Arrays.asList(lon, lat),
|
|
|
- Arrays.asList(lon2, lat),
|
|
|
- Arrays.asList(lon2, lat2),
|
|
|
- Arrays.asList(lon, lat2),
|
|
|
- Arrays.asList(lon, lat)
|
|
|
+ List<List<Double>> expected = asList(
|
|
|
+ asList(lon, lat),
|
|
|
+ asList(lon2, lat),
|
|
|
+ asList(lon2, lat2),
|
|
|
+ asList(lon, lat2),
|
|
|
+ asList(lon, lat)
|
|
|
);
|
|
|
for (int j = 0; j < 5; j++) {
|
|
|
Double[] coordinate = coordinates.get(0).get(j);
|
|
@@ -947,7 +950,7 @@ public class AggregationResultUtilsTests extends ESTestCase {
|
|
|
public void testPercentilesAggExtractor() {
|
|
|
Aggregation agg = createPercentilesAgg(
|
|
|
"p_agg",
|
|
|
- Arrays.asList(new Percentile(1, 0), new Percentile(50, 22.2), new Percentile(99, 43.3), new Percentile(99.5, 100.3))
|
|
|
+ asList(new Percentile(1, 0), new Percentile(50, 22.2), new Percentile(99, 43.3), new Percentile(99.5, 100.3))
|
|
|
);
|
|
|
assertThat(
|
|
|
AggregationResultUtils.getExtractor(agg).value(agg, Collections.emptyMap(), ""),
|
|
@@ -956,17 +959,64 @@ public class AggregationResultUtilsTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
public void testPercentilesAggExtractorNaN() {
|
|
|
- Aggregation agg = createPercentilesAgg("p_agg", Arrays.asList(new Percentile(1, Double.NaN), new Percentile(50, Double.NaN)));
|
|
|
+ Aggregation agg = createPercentilesAgg("p_agg", asList(new Percentile(1, Double.NaN), new Percentile(50, Double.NaN)));
|
|
|
assertThat(AggregationResultUtils.getExtractor(agg).value(agg, Collections.emptyMap(), ""), equalTo(asMap("1", null, "50", null)));
|
|
|
}
|
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public static Range createRangeAgg(String name, List<InternalRange.Bucket> buckets) {
|
|
|
+ Range agg = mock(Range.class);
|
|
|
+ when(agg.getName()).thenReturn(name);
|
|
|
+ when(agg.getBuckets()).thenReturn((List) buckets);
|
|
|
+ return agg;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testRangeAggExtractor() {
|
|
|
+ Aggregation agg = createRangeAgg(
|
|
|
+ "p_agg",
|
|
|
+ asList(
|
|
|
+ new InternalRange.Bucket(null, Double.NEGATIVE_INFINITY, 10.5, 10, InternalAggregations.EMPTY, false, DocValueFormat.RAW),
|
|
|
+ new InternalRange.Bucket(null, 10.5, 19.5, 30, InternalAggregations.EMPTY, false, DocValueFormat.RAW),
|
|
|
+ new InternalRange.Bucket(null, 19.5, 200, 30, InternalAggregations.EMPTY, false, DocValueFormat.RAW),
|
|
|
+ new InternalRange.Bucket(null, 20, Double.POSITIVE_INFINITY, 0, InternalAggregations.EMPTY, false, DocValueFormat.RAW),
|
|
|
+ new InternalRange.Bucket(null, -10, -5, 0, InternalAggregations.EMPTY, false, DocValueFormat.RAW),
|
|
|
+ new InternalRange.Bucket(null, -11.0, -6.0, 0, InternalAggregations.EMPTY, false, DocValueFormat.RAW),
|
|
|
+ new InternalRange.Bucket(null, -11.0, 0, 0, InternalAggregations.EMPTY, false, DocValueFormat.RAW),
|
|
|
+ new InternalRange.Bucket("custom-0", 0, 10, 777, InternalAggregations.EMPTY, false, DocValueFormat.RAW)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ assertThat(
|
|
|
+ AggregationResultUtils.getExtractor(agg).value(agg, Collections.emptyMap(), ""),
|
|
|
+ equalTo(
|
|
|
+ asMap(
|
|
|
+ "*-10_5",
|
|
|
+ 10L,
|
|
|
+ "10_5-19_5",
|
|
|
+ 30L,
|
|
|
+ "19_5-200",
|
|
|
+ 30L,
|
|
|
+ "20-*",
|
|
|
+ 0L,
|
|
|
+ "-10--5",
|
|
|
+ 0L,
|
|
|
+ "-11--6",
|
|
|
+ 0L,
|
|
|
+ "-11-0",
|
|
|
+ 0L,
|
|
|
+ "custom-0",
|
|
|
+ 777L
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
public static SingleBucketAggregation createSingleBucketAgg(String name, long docCount, Aggregation... subAggregations) {
|
|
|
SingleBucketAggregation agg = mock(SingleBucketAggregation.class);
|
|
|
when(agg.getDocCount()).thenReturn(docCount);
|
|
|
when(agg.getName()).thenReturn(name);
|
|
|
if (subAggregations != null) {
|
|
|
org.elasticsearch.search.aggregations.Aggregations subAggs = new org.elasticsearch.search.aggregations.Aggregations(
|
|
|
- Arrays.asList(subAggregations)
|
|
|
+ asList(subAggregations)
|
|
|
);
|
|
|
when(agg.getAggregations()).thenReturn(subAggs);
|
|
|
} else {
|