From 3435815e140d110bdbdfebbee4e105c13c938ce9 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Mon, 24 Feb 2020 18:01:34 -0500 Subject: [PATCH 1/2] Unmute testSupportedFieldTypes, fix Percentiles/Ranks/Terms tests Also fixes Percentiles which was incorrectly specified to only accept numeric, but in fact also accepts Boolean and Date (because those are numeric on master - thanks `testSupportedFieldTypes` for catching it!) --- .../metrics/PercentilesAggregatorFactory.java | 2 +- .../bucket/terms/TermsAggregatorTests.java | 5 ++++- .../HDRPercentileRanksAggregatorTests.java | 4 +++- .../HDRPercentilesAggregatorTests.java | 5 ++++- ...TDigestPercentileRanksAggregatorTests.java | 4 +++- .../TDigestPercentilesAggregatorTests.java | 5 ++++- .../aggregations/AggregatorTestCase.java | 19 ++++++++----------- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java index 07c1b7f4f9ec1..f8ed217c6d2ba 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java @@ -50,7 +50,7 @@ class PercentilesAggregatorFactory extends ValuesSourceAggregatorFactory { static void registerAggregators(ValuesSourceRegistry valuesSourceRegistry) { valuesSourceRegistry.register(PercentilesAggregationBuilder.NAME, - List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.HISTOGRAM), + List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.HISTOGRAM, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN), new PercentilesAggregatorSupplier() { @Override public Aggregator build(String name, ValuesSource valuesSource, SearchContext context, Aggregator parent, diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java index 0a915de65815f..62b49c1186ad8 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorTests.java @@ -132,7 +132,10 @@ protected AggregationBuilder createAggBuilderForTypeTest(MappedFieldType fieldTy @Override protected List getSupportedValuesSourceTypes() { return List.of(CoreValuesSourceType.NUMERIC, - CoreValuesSourceType.BYTES); + CoreValuesSourceType.BYTES, + CoreValuesSourceType.IP, + CoreValuesSourceType.DATE, + CoreValuesSourceType.BOOLEAN); } public void testGlobalOrdinalsExecutionHint() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksAggregatorTests.java index 7ed434f3a202d..6c34ba7430a38 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksAggregatorTests.java @@ -53,7 +53,9 @@ protected AggregationBuilder createAggBuilderForTypeTest(MappedFieldType fieldTy @Override protected List getSupportedValuesSourceTypes() { - return List.of(CoreValuesSourceType.NUMERIC); + return List.of(CoreValuesSourceType.NUMERIC, + CoreValuesSourceType.DATE, + CoreValuesSourceType.BOOLEAN); } public void testEmpty() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java index 75596a9755351..c982cd1c6cc15 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java @@ -66,7 +66,10 @@ protected AggregationBuilder createAggBuilderForTypeTest(MappedFieldType fieldTy @Override protected List getSupportedValuesSourceTypes() { - return List.of(CoreValuesSourceType.NUMERIC); + return List.of(CoreValuesSourceType.NUMERIC, + CoreValuesSourceType.DATE, + CoreValuesSourceType.BOOLEAN, + CoreValuesSourceType.HISTOGRAM); } public void testNoDocs() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentileRanksAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentileRanksAggregatorTests.java index 420c9b8cecbcf..043554bcc4dc3 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentileRanksAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentileRanksAggregatorTests.java @@ -53,7 +53,9 @@ protected AggregationBuilder createAggBuilderForTypeTest(MappedFieldType fieldTy @Override protected List getSupportedValuesSourceTypes() { - return List.of(CoreValuesSourceType.NUMERIC); + return List.of(CoreValuesSourceType.NUMERIC, + CoreValuesSourceType.DATE, + CoreValuesSourceType.BOOLEAN); } public void testEmpty() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesAggregatorTests.java index ea2aca16aa8a2..766407e86de43 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesAggregatorTests.java @@ -59,7 +59,10 @@ protected AggregationBuilder createAggBuilderForTypeTest(MappedFieldType fieldTy @Override protected List getSupportedValuesSourceTypes() { - return List.of(CoreValuesSourceType.NUMERIC); + return List.of(CoreValuesSourceType.NUMERIC, + CoreValuesSourceType.DATE, + CoreValuesSourceType.BOOLEAN, + CoreValuesSourceType.HISTOGRAM); } public void testNoDocs() throws IOException { diff --git a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java index 94d60ef7008c8..ba75cc5be7a5a 100644 --- a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java @@ -617,7 +617,6 @@ protected AggregationBuilder createAggBuilderForTypeTest(MappedFieldType fieldTy * * Exception types/messages are not currently checked, just presence/absence of an exception. */ - @AwaitsFix(bugUrl = "Muted until we can tweak Date/IP/Boolean") public final void testSupportedFieldTypes() throws IOException { MapperRegistry mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry(); Settings settings = Settings.builder().put("index.version.created", Version.CURRENT.id).build(); @@ -689,12 +688,7 @@ private void writeTestDoc(MappedFieldType fieldType, String fieldName, RandomInd ValuesSourceType vst = fieldType.getValuesSourceType(); if (vst.equals(CoreValuesSourceType.NUMERIC)) { - // TODO note: once VS refactor adds DATE/BOOLEAN, this conditional will go away - if (typeName.equals(DateFieldMapper.CONTENT_TYPE) || typeName.equals(DateFieldMapper.DATE_NANOS_CONTENT_TYPE)) { - iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, randomNonNegativeLong()))); - } else if (typeName.equals(BooleanFieldMapper.CONTENT_TYPE)) { - iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, randomBoolean() ? 0 : 1))); - } else if (typeName.equals(NumberFieldMapper.NumberType.DOUBLE.typeName())) { + if (typeName.equals(NumberFieldMapper.NumberType.DOUBLE.typeName())) { long encoded = NumericUtils.doubleToSortableLong(Math.abs(randomDouble())); iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, encoded))); } else if (typeName.equals(NumberFieldMapper.NumberType.FLOAT.typeName())) { @@ -709,13 +703,16 @@ private void writeTestDoc(MappedFieldType fieldType, String fieldName, RandomInd } else if (vst.equals(CoreValuesSourceType.BYTES)) { if (typeName.equals(BinaryFieldMapper.CONTENT_TYPE)) { iw.addDocument(singleton(new BinaryFieldMapper.CustomBinaryDocValuesField(fieldName, new BytesRef("a").bytes))); - } else if (typeName.equals(IpFieldMapper.CONTENT_TYPE)) { - // TODO note: once VS refactor adds IP, this conditional will go away - boolean v4 = randomBoolean(); - iw.addDocument(singleton(new SortedSetDocValuesField(fieldName, new BytesRef(InetAddressPoint.encode(randomIp(v4)))))); } else { iw.addDocument(singleton(new SortedSetDocValuesField(fieldName, new BytesRef("a")))); } + } else if (vst.equals(CoreValuesSourceType.DATE)) { + iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, randomNonNegativeLong()))); + } else if (vst.equals(CoreValuesSourceType.BOOLEAN)) { + iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, randomBoolean() ? 0 : 1))); + } else if (vst.equals(CoreValuesSourceType.IP)) { + boolean v4 = randomBoolean(); + iw.addDocument(singleton(new SortedSetDocValuesField(fieldName, new BytesRef(InetAddressPoint.encode(randomIp(v4)))))); } else if (vst.equals(CoreValuesSourceType.RANGE)) { Object start; Object end; From 2a7686dad8f98183146174de0e486c7d9bf718db Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Tue, 25 Feb 2020 09:32:38 -0500 Subject: [PATCH 2/2] Checkstyle! --- .../elasticsearch/search/aggregations/AggregatorTestCase.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java index ba75cc5be7a5a..9050efe4042f3 100644 --- a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java @@ -63,15 +63,12 @@ import org.elasticsearch.index.fielddata.IndexFieldDataCache; import org.elasticsearch.index.fielddata.IndexFieldDataService; import org.elasticsearch.index.mapper.BinaryFieldMapper; -import org.elasticsearch.index.mapper.BooleanFieldMapper; import org.elasticsearch.index.mapper.CompletionFieldMapper; import org.elasticsearch.index.mapper.ContentPath; -import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.FieldAliasMapper; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.GeoShapeFieldMapper; -import org.elasticsearch.index.mapper.IpFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.Mapper; import org.elasticsearch.index.mapper.Mapper.BuilderContext;