From 36b33c07ddcb6dd2942644699daf116d9ae2c584 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Mon, 27 Nov 2023 14:43:53 +0100 Subject: [PATCH 1/7] Misc dead code cleanup o.e.e.search (#102617) Misc obvious cleanup of unused methods and unused parameters. --- .../search/QueryPhaseResultConsumer.java | 3 +-- .../action/search/SearchRequest.java | 7 ------- .../DoubleValuesComparatorSource.java | 2 +- .../FloatValuesComparatorSource.java | 2 +- .../elasticsearch/search/MultiValueMode.java | 1 - .../range/GeoDistanceAggregationBuilder.java | 6 +----- .../bucket/range/InternalBinaryRange.java | 5 +---- .../bucket/range/InternalRange.java | 5 +---- .../bucket/range/ParsedRange.java | 2 +- .../bucket/terms/InternalMappedRareTerms.java | 1 - .../metrics/ExtendedStatsAggregator.java | 19 ++++--------------- .../aggregations/metrics/StatsAggregator.java | 3 +-- .../support/ValuesSourceConfig.java | 12 ++---------- .../support/ValuesSourceRegistry.java | 3 --- .../searchafter/SearchAfterBuilder.java | 16 ++-------------- .../search/sort/GeoDistanceSortBuilder.java | 9 +-------- .../search/MultiValueModeTests.java | 1 - .../rate/RateAggregationBuilder.java | 1 - .../xpack/spatial/SpatialPluginTests.java | 6 +++--- 19 files changed, 20 insertions(+), 84 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/search/QueryPhaseResultConsumer.java b/server/src/main/java/org/elasticsearch/action/search/QueryPhaseResultConsumer.java index fdd543fc8758f..b7b113601560b 100644 --- a/server/src/main/java/org/elasticsearch/action/search/QueryPhaseResultConsumer.java +++ b/server/src/main/java/org/elasticsearch/action/search/QueryPhaseResultConsumer.java @@ -300,11 +300,10 @@ void sortBuffer() { } } - synchronized long addWithoutBreaking(long size) { + synchronized void addWithoutBreaking(long size) { circuitBreaker.addWithoutBreaking(size); circuitBreakerBytes += size; maxAggsCurrentBufferSize = Math.max(maxAggsCurrentBufferSize, circuitBreakerBytes); - return circuitBreakerBytes; } synchronized long addEstimateAndMaybeBreak(long estimatedSize) { diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java b/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java index 65ed3e104fa98..372890778d960 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java @@ -541,13 +541,6 @@ public void setCcsMinimizeRoundtrips(boolean ccsMinimizeRoundtrips) { this.ccsMinimizeRoundtrips = ccsMinimizeRoundtrips; } - /** - * Returns the default value of {@link #ccsMinimizeRoundtrips} of a search request - */ - public static boolean defaultCcsMinimizeRoundtrips(SearchRequest request) { - return request.minCompatibleShardNode == null; - } - /** * A comma separated list of routing values to control the shards the search will be executed on. */ diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/DoubleValuesComparatorSource.java b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/DoubleValuesComparatorSource.java index 76463807942a2..dbc3aadde2e9f 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/DoubleValuesComparatorSource.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/DoubleValuesComparatorSource.java @@ -65,7 +65,7 @@ private NumericDoubleValues getNumericDocValues(LeafReaderContext context, doubl final BitSet rootDocs = nested.rootDocs(context); final DocIdSetIterator innerDocs = nested.innerDocs(context); final int maxChildren = nested.getNestedSort() != null ? nested.getNestedSort().getMaxChildren() : Integer.MAX_VALUE; - return sortMode.select(values, missingValue, rootDocs, innerDocs, context.reader().maxDoc(), maxChildren); + return sortMode.select(values, missingValue, rootDocs, innerDocs, maxChildren); } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/FloatValuesComparatorSource.java b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/FloatValuesComparatorSource.java index 4b8351f430e05..5dbcafcbdb5b8 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/FloatValuesComparatorSource.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/FloatValuesComparatorSource.java @@ -60,7 +60,7 @@ private NumericDoubleValues getNumericDocValues(LeafReaderContext context, float final BitSet rootDocs = nested.rootDocs(context); final DocIdSetIterator innerDocs = nested.innerDocs(context); final int maxChildren = nested.getNestedSort() != null ? nested.getNestedSort().getMaxChildren() : Integer.MAX_VALUE; - return sortMode.select(values, missingValue, rootDocs, innerDocs, context.reader().maxDoc(), maxChildren); + return sortMode.select(values, missingValue, rootDocs, innerDocs, maxChildren); } } diff --git a/server/src/main/java/org/elasticsearch/search/MultiValueMode.java b/server/src/main/java/org/elasticsearch/search/MultiValueMode.java index 2b5d9cb17b4f4..ad314a97a3a67 100644 --- a/server/src/main/java/org/elasticsearch/search/MultiValueMode.java +++ b/server/src/main/java/org/elasticsearch/search/MultiValueMode.java @@ -681,7 +681,6 @@ public NumericDoubleValues select( final double missingValue, final BitSet parentDocs, final DocIdSetIterator childDocs, - int maxDoc, int maxChildren ) throws IOException { if (parentDocs == null || childDocs == null) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceAggregationBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceAggregationBuilder.java index dc0b42f507d84..cdb2ae4517a22 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceAggregationBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceAggregationBuilder.java @@ -117,11 +117,7 @@ private static String key(String key, Double from, Double to) { if (key != null) { return key; } - StringBuilder sb = new StringBuilder(); - sb.append((from == null || from == 0) ? "*" : from); - sb.append("-"); - sb.append((to == null || Double.isInfinite(to)) ? "*" : to); - return sb.toString(); + return ((from == null || from == 0) ? "*" : from) + "-" + ((to == null || Double.isInfinite(to)) ? "*" : to); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRange.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRange.java index 23105bbe2d4f3..c8588136c1d33 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRange.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRange.java @@ -63,10 +63,7 @@ public Bucket( } private static String generateKey(BytesRef from, BytesRef to, DocValueFormat format) { - StringBuilder builder = new StringBuilder().append(from == null ? "*" : format.format(from)) - .append("-") - .append(to == null ? "*" : format.format(to)); - return builder.toString(); + return (from == null ? "*" : format.format(from)) + "-" + (to == null ? "*" : format.format(to)); } private static Bucket createFromStream(StreamInput in, DocValueFormat format, boolean keyed) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java index cb970fc87fd33..046d5efb97ece 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java @@ -144,10 +144,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } private static String generateKey(double from, double to, DocValueFormat format) { - StringBuilder builder = new StringBuilder().append(Double.isInfinite(from) ? "*" : format.format(from)) - .append("-") - .append(Double.isInfinite(to) ? "*" : format.format(to)); - return builder.toString(); + return (Double.isInfinite(from) ? "*" : format.format(from)) + "-" + (Double.isInfinite(to) ? "*" : format.format(to)); } @Override diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ParsedRange.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ParsedRange.java index 499b8c3e4f039..a12c126fb73d8 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ParsedRange.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ParsedRange.java @@ -41,7 +41,7 @@ protected static void declareParsedRangeFields( final CheckedFunction bucketParser, final CheckedFunction keyedBucketParser ) { - declareMultiBucketAggregationFields(objectParser, bucketParser::apply, keyedBucketParser::apply); + declareMultiBucketAggregationFields(objectParser, bucketParser, keyedBucketParser); } private static final ObjectParser PARSER = new ObjectParser<>( diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalMappedRareTerms.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalMappedRareTerms.java index aaa9857fc1562..b41e402c029f4 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalMappedRareTerms.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalMappedRareTerms.java @@ -34,7 +34,6 @@ public abstract class InternalMappedRareTerms, protected DocValueFormat format; protected List buckets; - protected Map bucketMap; final SetBackedScalingCuckooFilter filter; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregator.java index b469c24175715..cecd75941bcab 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregator.java @@ -140,20 +140,11 @@ public boolean hasMetric(String name) { public double metric(String name, long owningBucketOrd) { if (owningBucketOrd >= counts.size()) { return switch (InternalExtendedStats.Metrics.resolve(name)) { - case count -> 0; - case sum -> 0; + case count, sum_of_squares, sum -> 0; case min -> Double.POSITIVE_INFINITY; case max -> Double.NEGATIVE_INFINITY; - case avg -> Double.NaN; - case sum_of_squares -> 0; - case variance -> Double.NaN; - case variance_population -> Double.NaN; - case variance_sampling -> Double.NaN; - case std_deviation -> Double.NaN; - case std_deviation_population -> Double.NaN; - case std_deviation_sampling -> Double.NaN; - case std_upper -> Double.NaN; - case std_lower -> Double.NaN; + case avg, variance, variance_population, variance_sampling, std_deviation, std_deviation_population, std_deviation_sampling, + std_upper, std_lower -> Double.NaN; default -> throw new IllegalArgumentException("Unknown value [" + name + "] in common stats aggregation"); }; } @@ -167,9 +158,7 @@ public double metric(String name, long owningBucketOrd) { case variance -> variance(owningBucketOrd); case variance_population -> variancePopulation(owningBucketOrd); case variance_sampling -> varianceSampling(owningBucketOrd); - case std_deviation -> Math.sqrt(variance(owningBucketOrd)); - case std_deviation_population -> Math.sqrt(variance(owningBucketOrd)); - case std_deviation_sampling -> Math.sqrt(varianceSampling(owningBucketOrd)); + case std_deviation, std_deviation_population, std_deviation_sampling -> Math.sqrt(variance(owningBucketOrd)); case std_upper -> (sums.get(owningBucketOrd) / counts.get(owningBucketOrd)) + (Math.sqrt(variance(owningBucketOrd)) * this.sigma); case std_lower -> (sums.get(owningBucketOrd) / counts.get(owningBucketOrd)) - (Math.sqrt(variance(owningBucketOrd)) diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregator.java index 02a8325abe7b8..7a5861eb97fe2 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregator.java @@ -112,8 +112,7 @@ public boolean hasMetric(String name) { public double metric(String name, long owningBucketOrd) { if (owningBucketOrd >= counts.size()) { return switch (InternalStats.Metrics.resolve(name)) { - case count -> 0; - case sum -> 0; + case count, sum -> 0; case min -> Double.POSITIVE_INFINITY; case max -> Double.NEGATIVE_INFINITY; case avg -> Double.NaN; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java index 85788c1964b40..af75a8495afba 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java @@ -182,7 +182,6 @@ private static ValuesSourceConfig internalResolve( aggregationScript, scriptValueType, missing, - timeZone, docValueFormat, context::nowInMillis ); @@ -258,14 +257,14 @@ private static DocValueFormat resolveFormat( public static ValuesSourceConfig resolveFieldOnly(MappedFieldType fieldType, AggregationContext context) { FieldContext fieldContext = context.buildFieldContext(fieldType); ValuesSourceType vstype = fieldContext.indexFieldData().getValuesSourceType(); - return new ValuesSourceConfig(vstype, fieldContext, false, null, null, null, null, null, context::nowInMillis); + return new ValuesSourceConfig(vstype, fieldContext, false, null, null, null, null, context::nowInMillis); } /** * Convenience method for creating unmapped configs */ public static ValuesSourceConfig resolveUnmapped(ValuesSourceType valuesSourceType, AggregationContext context) { - return new ValuesSourceConfig(valuesSourceType, null, true, null, null, null, null, null, context::nowInMillis); + return new ValuesSourceConfig(valuesSourceType, null, true, null, null, null, null, context::nowInMillis); } private final ValuesSourceType valuesSourceType; @@ -275,7 +274,6 @@ public static ValuesSourceConfig resolveUnmapped(ValuesSourceType valuesSourceTy private final boolean unmapped; private final DocValueFormat format; private final Object missing; - private final ZoneId timeZone; private final ValuesSource valuesSource; @SuppressWarnings("this-escape") @@ -286,7 +284,6 @@ public ValuesSourceConfig( AggregationScript.LeafFactory script, ValueType scriptValueType, Object missing, - ZoneId timeZone, DocValueFormat format, LongSupplier nowInMillis ) { @@ -299,7 +296,6 @@ public ValuesSourceConfig( this.script = script; this.scriptValueType = scriptValueType; this.missing = missing; - this.timeZone = timeZone; this.format = format == null ? DocValueFormat.RAW : format; if (valid() == false) { @@ -383,10 +379,6 @@ public Object missing() { return this.missing; } - public ZoneId timezone() { - return this.timeZone; - } - public DocValueFormat format() { return format; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceRegistry.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceRegistry.java index 01541b03dad1d..44e66d98f0258 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceRegistry.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceRegistry.java @@ -53,9 +53,6 @@ public int hashCode() { } } - @SuppressWarnings("rawtypes") - public static final RegistryKey UNREGISTERED_KEY = new RegistryKey<>("unregistered", RegistryKey.class); - public static class Builder { private final AggregationUsageService.Builder usageServiceBuilder; private final Map, List>> aggregatorRegistry = new HashMap<>(); diff --git a/server/src/main/java/org/elasticsearch/search/searchafter/SearchAfterBuilder.java b/server/src/main/java/org/elasticsearch/search/searchafter/SearchAfterBuilder.java index 68ee36f5c0883..249f2c95ddc7f 100644 --- a/server/src/main/java/org/elasticsearch/search/searchafter/SearchAfterBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/searchafter/SearchAfterBuilder.java @@ -152,24 +152,18 @@ static Object convertValueFromSortField(Object value, SortField sortField, DocVa private static Object convertValueFromSortType(String fieldName, SortField.Type sortType, Object value, DocValueFormat format) { try { switch (sortType) { - case DOC: + case DOC, INT: if (value instanceof Number) { return ((Number) value).intValue(); } return Integer.parseInt(value.toString()); - case SCORE: + case SCORE, FLOAT: if (value instanceof Number) { return ((Number) value).floatValue(); } return Float.parseFloat(value.toString()); - case INT: - if (value instanceof Number) { - return ((Number) value).intValue(); - } - return Integer.parseInt(value.toString()); - case DOUBLE: if (value instanceof Number) { return ((Number) value).doubleValue(); @@ -187,12 +181,6 @@ private static Object convertValueFromSortType(String fieldName, SortField.Type () -> { throw new IllegalStateException("now() is not allowed in [search_after] key"); } ); - case FLOAT: - if (value instanceof Number) { - return ((Number) value).floatValue(); - } - return Float.parseFloat(value.toString()); - case STRING_VAL: case STRING: if (value instanceof BytesRef bytesRef) { diff --git a/server/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java b/server/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java index 2dceca2e9ad65..8b07a9e48a660 100644 --- a/server/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java @@ -651,14 +651,7 @@ private NumericDoubleValues getNumericDoubleValues(LeafReaderContext context) th final BitSet rootDocs = nested.rootDocs(context); final DocIdSetIterator innerDocs = nested.innerDocs(context); final int maxChildren = nested.getNestedSort() != null ? nested.getNestedSort().getMaxChildren() : Integer.MAX_VALUE; - return localSortMode.select( - distanceValues, - Double.POSITIVE_INFINITY, - rootDocs, - innerDocs, - context.reader().maxDoc(), - maxChildren - ); + return localSortMode.select(distanceValues, Double.POSITIVE_INFINITY, rootDocs, innerDocs, maxChildren); } } diff --git a/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java b/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java index 310ce21e0618a..488d79559f589 100644 --- a/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java +++ b/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java @@ -423,7 +423,6 @@ private void verifySortedNumericDouble( missingValue, rootDocs, new BitSetIterator(innerDocs, 0L), - maxDoc, maxChildren ); int prevRoot = -1; diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/rate/RateAggregationBuilder.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/rate/RateAggregationBuilder.java index 0b0becc1ae446..8bda1d59c5b57 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/rate/RateAggregationBuilder.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/rate/RateAggregationBuilder.java @@ -196,7 +196,6 @@ protected ValuesSourceConfig resolveConfig(AggregationContext context) { null, null, 1.0, - null, DocValueFormat.RAW, context::nowInMillis ); diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java index 2c5e9bf4917ee..38e79fa1dffb5 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java @@ -175,7 +175,7 @@ private void checkLicenseNotRequired( ValuesSourceRegistry registry = registryBuilder.build(); T aggregator = registry.getAggregator( registryKey, - new ValuesSourceConfig(sourceType, null, true, null, null, null, null, null, null) + new ValuesSourceConfig(sourceType, null, true, null, null, null, null, null) ); NullPointerException exception = expectThrows(NullPointerException.class, () -> builder.accept(aggregator)); assertThat( @@ -203,7 +203,7 @@ private void checkLicenseRequired( ValuesSourceRegistry registry = registryBuilder.build(); T aggregator = registry.getAggregator( registryKey, - new ValuesSourceConfig(sourceType, null, true, null, null, null, null, null, null) + new ValuesSourceConfig(sourceType, null, true, null, null, null, null, null) ); if (License.OperationMode.TRIAL != operationMode && License.OperationMode.compare(operationMode, License.OperationMode.GOLD) < 0) { @@ -229,7 +229,7 @@ private void checkLicenseRequired( private static class TestValuesSourceConfig extends ValuesSourceConfig { private TestValuesSourceConfig(ValuesSourceType sourceType) { - super(sourceType, null, true, null, null, null, null, null, null); + super(sourceType, null, true, null, null, null, null, null); } } } From 6df66d017584978616a46851b61959edc183c790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Mon, 27 Nov 2023 15:15:04 +0100 Subject: [PATCH 2/7] [Profiling] Rename request param custom_cost_factor into aws_cost_factor (#102643) --- .../xpack/profiling/CostCalculator.java | 14 ++++++----- .../profiling/GetStackTracesRequest.java | 24 +++++++++---------- .../TransportGetStackTracesAction.java | 10 ++++---- .../profiling/GetStackTracesRequestTests.java | 4 ++-- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/CostCalculator.java b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/CostCalculator.java index 3be0ec9201576..494b54d0bfcbe 100644 --- a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/CostCalculator.java +++ b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/CostCalculator.java @@ -14,22 +14,22 @@ final class CostCalculator { private static final double SECONDS_PER_HOUR = 60 * 60; private static final double SECONDS_PER_YEAR = SECONDS_PER_HOUR * 24 * 365.0d; // unit: seconds private static final double DEFAULT_COST_USD_PER_CORE_HOUR = 0.0425d; // unit: USD / (core * hour) - private static final double DEFAULT_CUSTOM_COST_FACTOR = 1.0d; + private static final double DEFAULT_AWS_COST_FACTOR = 1.0d; private final InstanceTypeService instanceTypeService; private final Map hostMetadata; private final double samplingDurationInSeconds; - private final double customCostFactor; + private final double awsCostFactor; CostCalculator( InstanceTypeService instanceTypeService, Map hostMetadata, double samplingDurationInSeconds, - Double customCostFactor + Double awsCostFactor ) { this.instanceTypeService = instanceTypeService; this.hostMetadata = hostMetadata; this.samplingDurationInSeconds = samplingDurationInSeconds > 0 ? samplingDurationInSeconds : 1.0d; // avoid division by zero - this.customCostFactor = customCostFactor == null ? DEFAULT_CUSTOM_COST_FACTOR : customCostFactor; + this.awsCostFactor = awsCostFactor == null ? DEFAULT_AWS_COST_FACTOR : awsCostFactor; } public double annualCostsUSD(String hostID, double samples) { @@ -40,12 +40,14 @@ public double annualCostsUSD(String hostID, double samples) { return annualCoreHours * DEFAULT_COST_USD_PER_CORE_HOUR; } + double providerCostFactor = host.instanceType.provider.equals("aws") ? awsCostFactor : 1.0d; + CostEntry costs = instanceTypeService.getCosts(host.instanceType); if (costs == null) { - return annualCoreHours * DEFAULT_COST_USD_PER_CORE_HOUR; + return annualCoreHours * DEFAULT_COST_USD_PER_CORE_HOUR * providerCostFactor; } - return annualCoreHours * costs.costFactor * customCostFactor; + return annualCoreHours * costs.costFactor * providerCostFactor; } public static double annualCoreHours(double duration, double samples, double samplingFrequency) { diff --git a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetStackTracesRequest.java b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetStackTracesRequest.java index a8ee825f5f87a..e1896e343f04b 100644 --- a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetStackTracesRequest.java +++ b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetStackTracesRequest.java @@ -38,7 +38,7 @@ public class GetStackTracesRequest extends ActionRequest implements IndicesReque public static final ParseField INDICES_FIELD = new ParseField("indices"); public static final ParseField STACKTRACE_IDS_FIELD = new ParseField("stacktrace_ids"); public static final ParseField REQUESTED_DURATION_FIELD = new ParseField("requested_duration"); - public static final ParseField CUSTOM_COST_FACTOR_FIELD = new ParseField("custom_cost_factor"); + public static final ParseField AWS_COST_FACTOR_FIELD = new ParseField("aws_cost_factor"); public static final ParseField CUSTOM_CO2_PER_KWH = new ParseField("co2_per_kwh"); public static final ParseField CUSTOM_DATACENTER_PUE = new ParseField("datacenter_pue"); public static final ParseField CUSTOM_PER_CORE_WATT = new ParseField("per_core_watt"); @@ -49,7 +49,7 @@ public class GetStackTracesRequest extends ActionRequest implements IndicesReque private String indices; private String stackTraceIds; private Double requestedDuration; - private Double customCostFactor; + private Double awsCostFactor; private Double customCO2PerKWH; private Double customDatacenterPUE; private Double customPerCoreWatt; @@ -66,7 +66,7 @@ public GetStackTracesRequest() { public GetStackTracesRequest( Integer sampleSize, Double requestedDuration, - Double customCostFactor, + Double awsCostFactor, QueryBuilder query, String indices, String stackTraceIds, @@ -76,7 +76,7 @@ public GetStackTracesRequest( ) { this.sampleSize = sampleSize; this.requestedDuration = requestedDuration; - this.customCostFactor = customCostFactor; + this.awsCostFactor = awsCostFactor; this.query = query; this.indices = indices; this.stackTraceIds = stackTraceIds; @@ -89,7 +89,7 @@ public GetStackTracesRequest(StreamInput in) throws IOException { this.query = in.readOptionalNamedWriteable(QueryBuilder.class); this.sampleSize = in.readOptionalInt(); this.requestedDuration = in.readOptionalDouble(); - this.customCostFactor = in.readOptionalDouble(); + this.awsCostFactor = in.readOptionalDouble(); this.adjustSampleCount = in.readOptionalBoolean(); this.indices = in.readOptionalString(); this.stackTraceIds = in.readOptionalString(); @@ -103,7 +103,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeOptionalNamedWriteable(query); out.writeOptionalInt(sampleSize); out.writeOptionalDouble(requestedDuration); - out.writeOptionalDouble(customCostFactor); + out.writeOptionalDouble(awsCostFactor); out.writeOptionalBoolean(adjustSampleCount); out.writeOptionalString(indices); out.writeOptionalString(stackTraceIds); @@ -120,8 +120,8 @@ public Double getRequestedDuration() { return requestedDuration; } - public Double getCustomCostFactor() { - return customCostFactor; + public Double getAwsCostFactor() { + return awsCostFactor; } public Double getCustomCO2PerKWH() { @@ -179,8 +179,8 @@ public void parseXContent(XContentParser parser) throws IOException { this.stackTraceIds = parser.text(); } else if (REQUESTED_DURATION_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { this.requestedDuration = parser.doubleValue(); - } else if (CUSTOM_COST_FACTOR_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - this.customCostFactor = parser.doubleValue(); + } else if (AWS_COST_FACTOR_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { + this.awsCostFactor = parser.doubleValue(); } else if (CUSTOM_CO2_PER_KWH.match(currentFieldName, parser.getDeprecationHandler())) { this.customCO2PerKWH = parser.doubleValue(); } else if (CUSTOM_DATACENTER_PUE.match(currentFieldName, parser.getDeprecationHandler())) { @@ -240,7 +240,7 @@ public ActionRequestValidationException validate() { validationException = requirePositive(SAMPLE_SIZE_FIELD, sampleSize, validationException); } validationException = requirePositive(REQUESTED_DURATION_FIELD, requestedDuration, validationException); - validationException = requirePositive(CUSTOM_COST_FACTOR_FIELD, customCostFactor, validationException); + validationException = requirePositive(AWS_COST_FACTOR_FIELD, awsCostFactor, validationException); validationException = requirePositive(CUSTOM_CO2_PER_KWH, customCO2PerKWH, validationException); validationException = requirePositive(CUSTOM_DATACENTER_PUE, customDatacenterPUE, validationException); validationException = requirePositive(CUSTOM_PER_CORE_WATT, customPerCoreWatt, validationException); @@ -267,7 +267,7 @@ public String getDescription() { appendField(sb, "stacktrace_ids", stackTraceIds); appendField(sb, "sample_size", sampleSize); appendField(sb, "requested_duration", requestedDuration); - appendField(sb, "custom_cost_factor", customCostFactor); + appendField(sb, "aws_cost_factor", awsCostFactor); appendField(sb, "co2_per_kwh", customCO2PerKWH); appendField(sb, "datacenter_pue", customDatacenterPUE); appendField(sb, "per_core_watt", customPerCoreWatt); diff --git a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetStackTracesAction.java b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetStackTracesAction.java index da04ecebbd359..e994863b75f49 100644 --- a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetStackTracesAction.java +++ b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetStackTracesAction.java @@ -149,7 +149,7 @@ protected void doExecute(Task submitTask, GetStackTracesRequest request, ActionL licenseChecker.requireSupportedLicense(); GetStackTracesResponseBuilder responseBuilder = new GetStackTracesResponseBuilder(); responseBuilder.setRequestedDuration(request.getRequestedDuration()); - responseBuilder.setCustomCostFactor(request.getCustomCostFactor()); + responseBuilder.setAwsCostFactor(request.getAwsCostFactor()); responseBuilder.setCustomCO2PerKWH(request.getCustomCO2PerKWH()); responseBuilder.setCustomDatacenterPUE(request.getCustomDatacenterPUE()); responseBuilder.setCustomPerCoreWatt(request.getCustomPerCoreWatt()); @@ -531,7 +531,7 @@ public void calculateCO2AndCosts() { instanceTypeService, hostsTable, responseBuilder.getRequestedDuration(), - responseBuilder.customCostFactor + responseBuilder.awsCostFactor ); Map events = responseBuilder.stackTraceEvents; List missingStackTraces = new ArrayList<>(); @@ -738,7 +738,7 @@ private static class GetStackTracesResponseBuilder { private double samplingRate; private long totalSamples; private Double requestedDuration; - private Double customCostFactor; + private Double awsCostFactor; private Double customCO2PerKWH; private Double customDatacenterPUE; private Double customPerCoreWatt; @@ -807,8 +807,8 @@ public double getRequestedDuration() { return end.getEpochSecond() - start.getEpochSecond(); } - public void setCustomCostFactor(Double customCostFactor) { - this.customCostFactor = customCostFactor; + public void setAwsCostFactor(Double awsCostFactor) { + this.awsCostFactor = awsCostFactor; } public void setCustomCO2PerKWH(Double customCO2PerKWH) { diff --git a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/GetStackTracesRequestTests.java b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/GetStackTracesRequestTests.java index 17e32e0b922a9..4fb8a3b571c55 100644 --- a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/GetStackTracesRequestTests.java +++ b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/GetStackTracesRequestTests.java @@ -31,13 +31,13 @@ public class GetStackTracesRequestTests extends ESTestCase { public void testSerialization() throws IOException { Integer sampleSize = randomIntBetween(1, Integer.MAX_VALUE); Double requestedDuration = randomBoolean() ? randomDoubleBetween(0.001d, Double.MAX_VALUE, true) : null; - Double customCostFactor = randomBoolean() ? randomDoubleBetween(0.1d, 5.0d, true) : null; + Double awsCostFactor = randomBoolean() ? randomDoubleBetween(0.1d, 5.0d, true) : null; QueryBuilder query = randomBoolean() ? new BoolQueryBuilder() : null; GetStackTracesRequest request = new GetStackTracesRequest( sampleSize, requestedDuration, - customCostFactor, + awsCostFactor, query, null, null, From 64f4d75d67fd6fb014da4b05d792790791ba4e7c Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Mon, 27 Nov 2023 15:19:20 +0100 Subject: [PATCH 3/7] Fix InternalEngineTests.testMergeThreadLogging (#102640) The test has to wait for all merge thread log messages (include Lucene ones) to be seen before reset the log level and stop the appender. Previous attempt wasn't enough: the test failure in #90071 (comment) shows that Lucene's merge scheduler thread can log after the Elasticsearch one, and if the appender has been closed in the meanwhile it can fail the test. This change ensure that the appender saw the Merge Scheduler end message before resetting the log level and close the engine. Closes #90071 --- .../index/engine/InternalEngineTests.java | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 60531851e16c9..ca3ee07de9192 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -2573,28 +2573,40 @@ public void testIndexWriterInfoStream() throws IllegalAccessException, IOExcepti } } - private static class MockMTAppender extends AbstractAppender { + private static class MockMergeThreadAppender extends AbstractAppender { + private final List messages = Collections.synchronizedList(new ArrayList<>()); + private final AtomicBoolean luceneMergeSchedulerEnded = new AtomicBoolean(); List messages() { return List.copyOf(messages); } - MockMTAppender(final String name) throws IllegalAccessException { + public boolean mergeCompleted() { + return luceneMergeSchedulerEnded.get(); + } + + MockMergeThreadAppender(final String name) throws IllegalAccessException { super(name, RegexFilter.createFilter(".*(\n.*)*", new String[0], false, null, null), null, false, Property.EMPTY_ARRAY); } @Override public void append(LogEvent event) { final String formattedMessage = event.getMessage().getFormattedMessage(); - if (event.getLevel() == Level.TRACE && formattedMessage.startsWith("merge thread")) { - messages.add(formattedMessage); + if (event.getLevel() == Level.TRACE && event.getMarker().getName().contains("[index][0]")) { + if (formattedMessage.startsWith("merge thread")) { + messages.add(formattedMessage); + } else if (event.getLoggerName().endsWith(".MS") + && formattedMessage.contains("MS: merge thread") + && formattedMessage.endsWith("end")) { + luceneMergeSchedulerEnded.set(true); + } } } } public void testMergeThreadLogging() throws Exception { - final MockMTAppender mockAppender = new MockMTAppender("testMergeThreadLogging"); + final MockMergeThreadAppender mockAppender = new MockMergeThreadAppender("testMergeThreadLogging"); mockAppender.start(); Logger rootLogger = LogManager.getRootLogger(); @@ -2613,26 +2625,29 @@ public void testMergeThreadLogging() throws Exception { engine.index(indexForDoc(testParsedDocument("3", null, testDocument(), B_1, null))); engine.index(indexForDoc(testParsedDocument("4", null, testDocument(), B_1, null))); engine.forceMerge(true, 1, false, UUIDs.randomBase64UUID()); - engine.flushAndClose(); assertBusy(() -> { assertThat(engine.getMergeStats().getTotal(), greaterThan(0L)); assertThat(engine.getMergeStats().getCurrent(), equalTo(0L)); }); - } - assertBusy(() -> { - List threadMsgs = mockAppender.messages().stream().filter(line -> line.startsWith("merge thread")).toList(); - assertThat("messages:" + threadMsgs, threadMsgs.size(), greaterThanOrEqualTo(3)); - assertThat( - threadMsgs, - containsInRelativeOrder( - matchesRegex("^merge thread .* start$"), - matchesRegex("^merge thread .* merge segment.*$"), - matchesRegex("^merge thread .* end$") - ) - ); - }); + assertBusy(() -> { + List threadMsgs = mockAppender.messages().stream().filter(line -> line.startsWith("merge thread")).toList(); + assertThat("messages:" + threadMsgs, threadMsgs.size(), greaterThanOrEqualTo(3)); + assertThat( + threadMsgs, + containsInRelativeOrder( + matchesRegex("^merge thread .* start$"), + matchesRegex("^merge thread .* merge segment.*$"), + matchesRegex("^merge thread .* end$") + ) + ); + assertThat(mockAppender.mergeCompleted(), is(true)); + }); + + Loggers.setLevel(rootLogger, savedLevel); + engine.close(); + } } finally { Loggers.setLevel(rootLogger, savedLevel); Loggers.removeAppender(rootLogger, mockAppender); From 319756ac98d22ec3f4fe32f26d8f6f0f5db2bf64 Mon Sep 17 00:00:00 2001 From: Panagiotis Bailis Date: Mon, 27 Nov 2023 16:27:23 +0200 Subject: [PATCH 4/7] [CI] Fix for mlt/25_docs_one_shard/Basic mlt query with docs - explicitly on same shard (#102506) --- .../resources/rest-api-spec/test/mlt/25_docs_one_shard.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/mlt/25_docs_one_shard.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/mlt/25_docs_one_shard.yml index 8490a262b96c9..a340de50bba0c 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/mlt/25_docs_one_shard.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/mlt/25_docs_one_shard.yml @@ -1,9 +1,5 @@ --- "Basic mlt query with docs - explicitly on same shard": - - skip: - version: "all" - reason: temporarily disabling for investigation - - do: indices.create: index: mlt_one_shard_test_index @@ -11,7 +7,7 @@ settings: index: number_of_shards: 1 - number_of_replicas: 0 + number_of_replicas: 1 - do: index: From 2626be33ca27986caa25c72eddc9936a32498481 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Mon, 27 Nov 2023 06:48:35 -0800 Subject: [PATCH 5/7] Track blocks when hashing single multi-valued field. (#102612) --- docs/changelog/102612.yaml | 5 ++ .../operator/MultivalueDedupeBytesRef.java | 4 +- .../operator/MultivalueDedupeDouble.java | 4 +- .../compute/operator/MultivalueDedupeInt.java | 4 +- .../operator/MultivalueDedupeLong.java | 4 +- .../blockhash/BooleanBlockHash.java | 2 +- .../blockhash/BytesRefBlockHash.java | 2 +- .../blockhash/DoubleBlockHash.java | 2 +- .../aggregation/blockhash/IntBlockHash.java | 2 +- .../aggregation/blockhash/LongBlockHash.java | 2 +- .../operator/MultivalueDedupeBoolean.java | 4 +- .../operator/X-MultivalueDedupe.java.st | 6 +-- .../operator/MultivalueDedupeTests.java | 49 +++++++++++-------- .../esql/planner/LocalExecutionPlanner.java | 3 +- 14 files changed, 53 insertions(+), 40 deletions(-) create mode 100644 docs/changelog/102612.yaml diff --git a/docs/changelog/102612.yaml b/docs/changelog/102612.yaml new file mode 100644 index 0000000000000..60808ae72801a --- /dev/null +++ b/docs/changelog/102612.yaml @@ -0,0 +1,5 @@ +pr: 102612 +summary: Track blocks when hashing single multi-valued field +area: ES|QL +type: enhancement +issues: [] diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeBytesRef.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeBytesRef.java index b7b2844b9be26..1fd4c1ea3562d 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeBytesRef.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeBytesRef.java @@ -150,8 +150,8 @@ public BytesRefBlock dedupeToBlockUsingCopyMissing(BlockFactory blockFactory) { * Dedupe values and build a {@link IntBlock} suitable for passing * as the grouping block to a {@link GroupingAggregatorFunction}. */ - public MultivalueDedupe.HashResult hash(BytesRefHash hash) { - try (IntBlock.Builder builder = IntBlock.newBlockBuilder(block.getPositionCount())) { + public MultivalueDedupe.HashResult hash(BlockFactory blockFactory, BytesRefHash hash) { + try (IntBlock.Builder builder = blockFactory.newIntBlockBuilder(block.getPositionCount())) { boolean sawNull = false; for (int p = 0; p < block.getPositionCount(); p++) { int count = block.getValueCount(p); diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeDouble.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeDouble.java index 74333fa6909d9..157b6670e95af 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeDouble.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeDouble.java @@ -147,8 +147,8 @@ public DoubleBlock dedupeToBlockUsingCopyMissing(BlockFactory blockFactory) { * Dedupe values and build a {@link IntBlock} suitable for passing * as the grouping block to a {@link GroupingAggregatorFunction}. */ - public MultivalueDedupe.HashResult hash(LongHash hash) { - try (IntBlock.Builder builder = IntBlock.newBlockBuilder(block.getPositionCount())) { + public MultivalueDedupe.HashResult hash(BlockFactory blockFactory, LongHash hash) { + try (IntBlock.Builder builder = blockFactory.newIntBlockBuilder(block.getPositionCount())) { boolean sawNull = false; for (int p = 0; p < block.getPositionCount(); p++) { int count = block.getValueCount(p); diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeInt.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeInt.java index 000e30c51d9aa..7bc9d77d3f877 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeInt.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeInt.java @@ -146,8 +146,8 @@ public IntBlock dedupeToBlockUsingCopyMissing(BlockFactory blockFactory) { * Dedupe values and build a {@link IntBlock} suitable for passing * as the grouping block to a {@link GroupingAggregatorFunction}. */ - public MultivalueDedupe.HashResult hash(LongHash hash) { - try (IntBlock.Builder builder = IntBlock.newBlockBuilder(block.getPositionCount())) { + public MultivalueDedupe.HashResult hash(BlockFactory blockFactory, LongHash hash) { + try (IntBlock.Builder builder = blockFactory.newIntBlockBuilder(block.getPositionCount())) { boolean sawNull = false; for (int p = 0; p < block.getPositionCount(); p++) { int count = block.getValueCount(p); diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeLong.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeLong.java index a981b397a123d..acbc9139a75c5 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeLong.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/operator/MultivalueDedupeLong.java @@ -148,8 +148,8 @@ public LongBlock dedupeToBlockUsingCopyMissing(BlockFactory blockFactory) { * Dedupe values and build a {@link IntBlock} suitable for passing * as the grouping block to a {@link GroupingAggregatorFunction}. */ - public MultivalueDedupe.HashResult hash(LongHash hash) { - try (IntBlock.Builder builder = IntBlock.newBlockBuilder(block.getPositionCount())) { + public MultivalueDedupe.HashResult hash(BlockFactory blockFactory, LongHash hash) { + try (IntBlock.Builder builder = blockFactory.newIntBlockBuilder(block.getPositionCount())) { boolean sawNull = false; for (int p = 0; p < block.getPositionCount(); p++) { int count = block.getValueCount(p); diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BooleanBlockHash.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BooleanBlockHash.java index caa16bc263005..684e6aec60b9e 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BooleanBlockHash.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BooleanBlockHash.java @@ -69,7 +69,7 @@ private IntVector add(BooleanVector vector) { } private IntBlock add(BooleanBlock block) { - return new MultivalueDedupeBoolean(block).hash(everSeen); + return new MultivalueDedupeBoolean(block).hash(blockFactory, everSeen); } @Override diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BytesRefBlockHash.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BytesRefBlockHash.java index 579b114ae2609..fb9b680c62d1d 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BytesRefBlockHash.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BytesRefBlockHash.java @@ -87,7 +87,7 @@ private IntVector add(BytesRefVector vector) { private IntBlock add(BytesRefBlock block) { // TODO: use block factory - MultivalueDedupe.HashResult result = new MultivalueDedupeBytesRef(block).hash(bytesRefHash); + MultivalueDedupe.HashResult result = new MultivalueDedupeBytesRef(block).hash(blockFactory, bytesRefHash); seenNull |= result.sawNull(); return result.ords(); } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/DoubleBlockHash.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/DoubleBlockHash.java index 468180430424c..c03ce2a0a4dce 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/DoubleBlockHash.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/DoubleBlockHash.java @@ -80,7 +80,7 @@ private IntVector add(DoubleVector vector) { } private IntBlock add(DoubleBlock block) { - MultivalueDedupe.HashResult result = new MultivalueDedupeDouble(block).hash(longHash); // TODO: block factory + MultivalueDedupe.HashResult result = new MultivalueDedupeDouble(block).hash(blockFactory, longHash); seenNull |= result.sawNull(); return result.ords(); } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/IntBlockHash.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/IntBlockHash.java index 41d6bf1db8681..bd5438da153e4 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/IntBlockHash.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/IntBlockHash.java @@ -77,7 +77,7 @@ private IntVector add(IntVector vector) { } private IntBlock add(IntBlock block) { - MultivalueDedupe.HashResult result = new MultivalueDedupeInt(block).hash(longHash); // TODO: block factory + MultivalueDedupe.HashResult result = new MultivalueDedupeInt(block).hash(blockFactory, longHash); seenNull |= result.sawNull(); return result.ords(); } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/LongBlockHash.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/LongBlockHash.java index 5ee273683d71c..d817edb9e059a 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/LongBlockHash.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/LongBlockHash.java @@ -80,7 +80,7 @@ private IntVector add(LongVector vector) { } private IntBlock add(LongBlock block) { - MultivalueDedupe.HashResult result = new MultivalueDedupeLong(block).hash(longHash); // TODO: block factory + MultivalueDedupe.HashResult result = new MultivalueDedupeLong(block).hash(blockFactory, longHash); seenNull |= result.sawNull(); return result.ords(); } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/MultivalueDedupeBoolean.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/MultivalueDedupeBoolean.java index 5c745640e4790..f3570bf7b853b 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/MultivalueDedupeBoolean.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/MultivalueDedupeBoolean.java @@ -68,8 +68,8 @@ public BooleanBlock dedupeToBlock(BlockFactory blockFactory) { * as the grouping block to a {@link GroupingAggregatorFunction}. * @param everSeen array tracking if the values {@code false} and {@code true} are ever seen */ - public IntBlock hash(boolean[] everSeen) { - try (IntBlock.Builder builder = IntBlock.newBlockBuilder(block.getPositionCount())) { + public IntBlock hash(BlockFactory blockFactory, boolean[] everSeen) { + try (IntBlock.Builder builder = blockFactory.newIntBlockBuilder(block.getPositionCount())) { for (int p = 0; p < block.getPositionCount(); p++) { int count = block.getValueCount(p); int first = block.getFirstValueIndex(p); diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/X-MultivalueDedupe.java.st b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/X-MultivalueDedupe.java.st index 04c3a47384537..169e7aa427717 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/X-MultivalueDedupe.java.st +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/X-MultivalueDedupe.java.st @@ -191,11 +191,11 @@ $endif$ * as the grouping block to a {@link GroupingAggregatorFunction}. */ $if(BytesRef)$ - public MultivalueDedupe.HashResult hash(BytesRefHash hash) { + public MultivalueDedupe.HashResult hash(BlockFactory blockFactory, BytesRefHash hash) { $else$ - public MultivalueDedupe.HashResult hash(LongHash hash) { + public MultivalueDedupe.HashResult hash(BlockFactory blockFactory, LongHash hash) { $endif$ - try (IntBlock.Builder builder = IntBlock.newBlockBuilder(block.getPositionCount())) { + try (IntBlock.Builder builder = blockFactory.newIntBlockBuilder(block.getPositionCount())) { boolean sawNull = false; for (int p = 0; p < block.getPositionCount(); p++) { int count = block.getValueCount(p); diff --git a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/MultivalueDedupeTests.java b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/MultivalueDedupeTests.java index c228ff9b77fb6..50b20a2ffdcff 100644 --- a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/MultivalueDedupeTests.java +++ b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/MultivalueDedupeTests.java @@ -270,47 +270,56 @@ private void assertBooleanHash(Set previousValues, BasicBlockTests.Rand if (previousValues.contains(true)) { everSeen[2] = true; } - IntBlock hashes = new MultivalueDedupeBoolean((BooleanBlock) b.block()).hash(everSeen); - List hashedValues = new ArrayList<>(); - if (everSeen[1]) { - hashedValues.add(false); - } - if (everSeen[2]) { - hashedValues.add(true); + try (IntBlock hashes = new MultivalueDedupeBoolean((BooleanBlock) b.block()).hash(blockFactory(), everSeen)) { + List hashedValues = new ArrayList<>(); + if (everSeen[1]) { + hashedValues.add(false); + } + if (everSeen[2]) { + hashedValues.add(true); + } + assertHash(b, hashes, hashedValues.size(), previousValues, i -> hashedValues.get((int) i)); } - assertHash(b, hashes, hashedValues.size(), previousValues, i -> hashedValues.get((int) i)); } private void assertBytesRefHash(Set previousValues, BasicBlockTests.RandomBlock b) { BytesRefHash hash = new BytesRefHash(1, BigArrays.NON_RECYCLING_INSTANCE); previousValues.stream().forEach(hash::add); - MultivalueDedupe.HashResult hashes = new MultivalueDedupeBytesRef((BytesRefBlock) b.block()).hash(hash); - assertThat(hashes.sawNull(), equalTo(b.values().stream().anyMatch(v -> v == null))); - assertHash(b, hashes.ords(), hash.size(), previousValues, i -> hash.get(i, new BytesRef())); + MultivalueDedupe.HashResult hashes = new MultivalueDedupeBytesRef((BytesRefBlock) b.block()).hash(blockFactory(), hash); + try (IntBlock ords = hashes.ords()) { + assertThat(hashes.sawNull(), equalTo(b.values().stream().anyMatch(v -> v == null))); + assertHash(b, ords, hash.size(), previousValues, i -> hash.get(i, new BytesRef())); + } } private void assertIntHash(Set previousValues, BasicBlockTests.RandomBlock b) { LongHash hash = new LongHash(1, BigArrays.NON_RECYCLING_INSTANCE); previousValues.stream().forEach(hash::add); - MultivalueDedupe.HashResult hashes = new MultivalueDedupeInt((IntBlock) b.block()).hash(hash); - assertThat(hashes.sawNull(), equalTo(b.values().stream().anyMatch(v -> v == null))); - assertHash(b, hashes.ords(), hash.size(), previousValues, i -> (int) hash.get(i)); + MultivalueDedupe.HashResult hashes = new MultivalueDedupeInt((IntBlock) b.block()).hash(blockFactory(), hash); + try (IntBlock ords = hashes.ords()) { + assertThat(hashes.sawNull(), equalTo(b.values().stream().anyMatch(v -> v == null))); + assertHash(b, ords, hash.size(), previousValues, i -> (int) hash.get(i)); + } } private void assertLongHash(Set previousValues, BasicBlockTests.RandomBlock b) { LongHash hash = new LongHash(1, BigArrays.NON_RECYCLING_INSTANCE); previousValues.stream().forEach(hash::add); - MultivalueDedupe.HashResult hashes = new MultivalueDedupeLong((LongBlock) b.block()).hash(hash); - assertThat(hashes.sawNull(), equalTo(b.values().stream().anyMatch(v -> v == null))); - assertHash(b, hashes.ords(), hash.size(), previousValues, i -> hash.get(i)); + MultivalueDedupe.HashResult hashes = new MultivalueDedupeLong((LongBlock) b.block()).hash(blockFactory(), hash); + try (IntBlock ords = hashes.ords()) { + assertThat(hashes.sawNull(), equalTo(b.values().stream().anyMatch(v -> v == null))); + assertHash(b, ords, hash.size(), previousValues, i -> hash.get(i)); + } } private void assertDoubleHash(Set previousValues, BasicBlockTests.RandomBlock b) { LongHash hash = new LongHash(1, BigArrays.NON_RECYCLING_INSTANCE); previousValues.stream().forEach(d -> hash.add(Double.doubleToLongBits(d))); - MultivalueDedupe.HashResult hashes = new MultivalueDedupeDouble((DoubleBlock) b.block()).hash(hash); - assertThat(hashes.sawNull(), equalTo(b.values().stream().anyMatch(v -> v == null))); - assertHash(b, hashes.ords(), hash.size(), previousValues, i -> Double.longBitsToDouble(hash.get(i))); + MultivalueDedupe.HashResult hashes = new MultivalueDedupeDouble((DoubleBlock) b.block()).hash(blockFactory(), hash); + try (IntBlock ords = hashes.ords()) { + assertThat(hashes.sawNull(), equalTo(b.values().stream().anyMatch(v -> v == null))); + assertHash(b, ords, hash.size(), previousValues, i -> Double.longBitsToDouble(hash.get(i))); + } } private void assertHash( diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java index 53f12d949469d..74cc4ab999808 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java @@ -13,7 +13,6 @@ import org.elasticsearch.compute.Describable; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; -import org.elasticsearch.compute.data.BooleanBlock; import org.elasticsearch.compute.data.ElementType; import org.elasticsearch.compute.data.Page; import org.elasticsearch.compute.lucene.LuceneCountOperator; @@ -366,7 +365,7 @@ private PhysicalOperation planExchangeSink(ExchangeSinkExec exchangeSink, LocalE for (int i = 0, s = output.size(); i < s; i++) { var out = output.get(i); if (out.dataType() == DataTypes.BOOLEAN) { - blocks.add(i, BooleanBlock.newConstantBlockWith(true, 1)); + blocks.add(i, BlockFactory.getNonBreakingInstance().newConstantBooleanBlockWith(true, 1)); } } } From 793d9d92a40b5ea62d7257ebb44153d0c5aeacb0 Mon Sep 17 00:00:00 2001 From: David Turner Date: Mon, 27 Nov 2023 06:49:58 -0800 Subject: [PATCH 6/7] Mark OwningChannelActionListener for removal (#102647) Make IntelliJ's warnings about using this workaround more strident. --- .../org/elasticsearch/compute/OwningChannelActionListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/OwningChannelActionListener.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/OwningChannelActionListener.java index 57256fa29d4a1..6512d80859163 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/OwningChannelActionListener.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/OwningChannelActionListener.java @@ -18,7 +18,7 @@ * * Deprecated: use {@link ChannelActionListener} instead and ensure responses sent to it are properly closed after. */ -@Deprecated +@Deprecated(forRemoval = true) public final class OwningChannelActionListener implements ActionListener { private final ChannelActionListener listener; From 651539d4fe63277577337fa745129893459c6dff Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Mon, 27 Nov 2023 15:55:43 +0100 Subject: [PATCH 7/7] Move terms parallel collection tests to TermsTests (#102648) They were before in AggregatorFactoriesTests, but TermsTests is a more appropriate place for them. --- .../AggregatorFactoriesTests.java | 74 ------------------- .../aggregations/bucket/TermsTests.java | 64 ++++++++++++++++ 2 files changed, 64 insertions(+), 74 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/AggregatorFactoriesTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/AggregatorFactoriesTests.java index c5763a46a6dd8..d5fb8f1b63e7e 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/AggregatorFactoriesTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/AggregatorFactoriesTests.java @@ -24,12 +24,9 @@ import org.elasticsearch.index.query.WrapperQueryBuilder; import org.elasticsearch.script.Script; import org.elasticsearch.search.SearchModule; -import org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregationBuilder; -import org.elasticsearch.search.aggregations.bucket.composite.TermsValuesSourceBuilder; import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.terms.SignificantTermsAggregationBuilder; -import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.CardinalityAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.BucketScriptPipelineAggregationBuilder; @@ -46,7 +43,6 @@ import java.io.IOException; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Random; @@ -342,13 +338,6 @@ public void testSupportsParallelCollection() { builder.addAggregator(new SignificantTermsAggregationBuilder("name")); assertFalse(builder.supportsParallelCollection(randomCardinality)); } - { - AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); - builder.addAggregator( - new CompositeAggregationBuilder("composite", Collections.singletonList(new TermsValuesSourceBuilder("name"))) - ); - assertTrue(builder.supportsParallelCollection(randomCardinality)); - } { AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); builder.addAggregator(new FilterAggregationBuilder("terms", new MatchAllQueryBuilder()) { @@ -361,69 +350,6 @@ public boolean isInSortOrderExecutionRequired() { } } - public void testSupportsParallelCollectionTermsAgg() { - { - AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); - TermsAggregationBuilder terms = new TermsAggregationBuilder("terms").executionHint("map"); - builder.addAggregator(terms); - assertFalse(builder.supportsParallelCollection(field -> randomIntBetween(-1, 100))); - } - { - AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); - TermsAggregationBuilder terms = new TermsAggregationBuilder("terms").executionHint("global_ordinals"); - builder.addAggregator(terms); - assertTrue(builder.supportsParallelCollection(field -> 0)); - } - { - AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); - TermsAggregationBuilder terms = new TermsAggregationBuilder("terms").order(BucketOrder.key(randomBoolean())); - if (randomBoolean()) { - terms.shardSize(randomIntBetween(1, 100)); - } - builder.addAggregator(terms); - assertTrue(builder.supportsParallelCollection(field -> randomIntBetween(0, 49))); - } - { - AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); - TermsAggregationBuilder terms = new TermsAggregationBuilder("terms").order(BucketOrder.key(randomBoolean())); - if (randomBoolean()) { - terms.shardSize(randomIntBetween(1, 100)); - } - builder.addAggregator(terms); - assertFalse(builder.supportsParallelCollection(field -> randomIntBetween(51, 100))); - } - { - AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); - builder.addAggregator(new TermsAggregationBuilder("terms")); - assertFalse(builder.supportsParallelCollection(field -> -1)); - } - { - AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); - builder.addAggregator(new TermsAggregationBuilder("terms")); - assertTrue(builder.supportsParallelCollection(field -> 0)); - } - { - AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); - TermsAggregationBuilder terms = new TermsAggregationBuilder("terms"); - terms.subAggregation(new TermsAggregationBuilder("name") { - @Override - public boolean supportsParallelCollection(ToLongFunction fieldCardinalityResolver) { - return false; - } - }); - builder.addAggregator(terms); - assertFalse(builder.supportsParallelCollection(field -> 0)); - } - { - AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); - TermsAggregationBuilder terms = new TermsAggregationBuilder("terms"); - terms.shardSize(10); - builder.addAggregator(terms); - assertTrue(builder.supportsParallelCollection(field -> randomIntBetween(1, 10))); - assertFalse(builder.supportsParallelCollection(field -> randomIntBetween(11, 100))); - } - } - @Override protected NamedXContentRegistry xContentRegistry() { return xContentRegistry; diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java index 66978b981e261..9af6ff227df8d 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java @@ -10,6 +10,7 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; +import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude; @@ -20,6 +21,7 @@ import java.util.List; import java.util.SortedSet; import java.util.TreeSet; +import java.util.function.ToLongFunction; public class TermsTests extends BaseAggregationTestCase { @@ -164,4 +166,66 @@ private List randomOrder() { return orders; } + public void testSupportsParallelCollection() { + { + AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); + TermsAggregationBuilder terms = new TermsAggregationBuilder("terms").executionHint("map"); + builder.addAggregator(terms); + assertFalse(builder.supportsParallelCollection(field -> randomIntBetween(-1, 100))); + } + { + AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); + TermsAggregationBuilder terms = new TermsAggregationBuilder("terms").executionHint("global_ordinals"); + builder.addAggregator(terms); + assertTrue(builder.supportsParallelCollection(field -> 0)); + } + { + AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); + TermsAggregationBuilder terms = new TermsAggregationBuilder("terms").order(BucketOrder.key(randomBoolean())); + if (randomBoolean()) { + terms.shardSize(randomIntBetween(1, 100)); + } + builder.addAggregator(terms); + assertTrue(builder.supportsParallelCollection(field -> randomIntBetween(0, 49))); + } + { + AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); + TermsAggregationBuilder terms = new TermsAggregationBuilder("terms").order(BucketOrder.key(randomBoolean())); + if (randomBoolean()) { + terms.shardSize(randomIntBetween(1, 100)); + } + builder.addAggregator(terms); + assertFalse(builder.supportsParallelCollection(field -> randomIntBetween(51, 100))); + } + { + AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); + builder.addAggregator(new TermsAggregationBuilder("terms")); + assertFalse(builder.supportsParallelCollection(field -> -1)); + } + { + AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); + builder.addAggregator(new TermsAggregationBuilder("terms")); + assertTrue(builder.supportsParallelCollection(field -> 0)); + } + { + AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); + TermsAggregationBuilder terms = new TermsAggregationBuilder("terms"); + terms.subAggregation(new TermsAggregationBuilder("name") { + @Override + public boolean supportsParallelCollection(ToLongFunction fieldCardinalityResolver) { + return false; + } + }); + builder.addAggregator(terms); + assertFalse(builder.supportsParallelCollection(field -> 0)); + } + { + AggregatorFactories.Builder builder = new AggregatorFactories.Builder(); + TermsAggregationBuilder terms = new TermsAggregationBuilder("terms"); + terms.shardSize(10); + builder.addAggregator(terms); + assertTrue(builder.supportsParallelCollection(field -> randomIntBetween(1, 10))); + assertFalse(builder.supportsParallelCollection(field -> randomIntBetween(11, 100))); + } + } }