Skip to content

Commit 04e0148

Browse files
authored
Merge branch 'main' into random-sampling-support-data-streams
2 parents d0d2d58 + 12df171 commit 04e0148

File tree

66 files changed

+3030
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3030
-228
lines changed

docs/changelog/137025.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 137025
2+
summary: Fix `ReplaceAliasingEvalWithProject` in case of shadowing
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 137019

docs/changelog/137219.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 137219
2+
summary: Perform query field validation for rerank task type
3+
area: Machine Learning
4+
type: bug
5+
issues: []

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/ExponentialHistogramXContent.java

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@
2121

2222
package org.elasticsearch.exponentialhistogram;
2323

24+
import org.elasticsearch.core.Nullable;
25+
import org.elasticsearch.core.Types;
2426
import org.elasticsearch.xcontent.XContentBuilder;
27+
import org.elasticsearch.xcontent.XContentParser;
2528

2629
import java.io.IOException;
30+
import java.util.Collections;
31+
import java.util.List;
32+
import java.util.Map;
33+
import java.util.function.BiConsumer;
2734

2835
/**
2936
* Handles the serialization of an {@link ExponentialHistogram} to XContent.
@@ -48,7 +55,11 @@ public class ExponentialHistogramXContent {
4855
* @param histogram the ExponentialHistogram to serialize
4956
* @throws IOException if the XContentBuilder throws an IOException
5057
*/
51-
public static void serialize(XContentBuilder builder, ExponentialHistogram histogram) throws IOException {
58+
public static void serialize(XContentBuilder builder, @Nullable ExponentialHistogram histogram) throws IOException {
59+
if (histogram == null) {
60+
builder.nullValue();
61+
return;
62+
}
5263
builder.startObject();
5364

5465
builder.field(SCALE_FIELD, histogram.scale());
@@ -101,4 +112,63 @@ private static void writeBuckets(XContentBuilder b, String fieldName, Exponentia
101112
b.endObject();
102113
}
103114

115+
/**
116+
* Parses an {@link ExponentialHistogram} from the provided {@link XContentParser}.
117+
* This method is neither optimized, nor does it do any validation of the parsed content.
118+
* No estimation for missing sum/min/max is done.
119+
* Therefore only intended for testing!
120+
*
121+
* @param xContent the serialized histogram to read
122+
* @return the deserialized histogram
123+
* @throws IOException if the XContentParser throws an IOException
124+
*/
125+
public static ExponentialHistogram parseForTesting(XContentParser xContent) throws IOException {
126+
if (xContent.currentToken() == null) {
127+
xContent.nextToken();
128+
}
129+
if (xContent.currentToken() == XContentParser.Token.VALUE_NULL) {
130+
return null;
131+
}
132+
return parseForTesting(xContent.map());
133+
}
134+
135+
/**
136+
* Parses an {@link ExponentialHistogram} from a {@link Map}.
137+
* This method is neither optimized, nor does it do any validation of the parsed content.
138+
* No estimation for missing sum/min/max is done.
139+
* Therefore only intended for testing!
140+
*
141+
* @param xContent the serialized histogram as a map
142+
* @return the deserialized histogram
143+
*/
144+
public static ExponentialHistogram parseForTesting(@Nullable Map<String, Object> xContent) {
145+
if (xContent == null) {
146+
return null;
147+
}
148+
int scale = ((Number) xContent.get(SCALE_FIELD)).intValue();
149+
ExponentialHistogramBuilder builder = ExponentialHistogram.builder(scale, ExponentialHistogramCircuitBreaker.noop());
150+
151+
Map<String, Number> zero = Types.forciblyCast(xContent.getOrDefault(ZERO_FIELD, Collections.emptyMap()));
152+
double zeroThreshold = zero.getOrDefault(ZERO_THRESHOLD_FIELD, 0).doubleValue();
153+
long zeroCount = zero.getOrDefault(ZERO_COUNT_FIELD, 0).longValue();
154+
builder.zeroBucket(ZeroBucket.create(zeroThreshold, zeroCount));
155+
156+
builder.sum(((Number) xContent.getOrDefault(SUM_FIELD, 0)).doubleValue());
157+
builder.min(((Number) xContent.getOrDefault(MIN_FIELD, Double.NaN)).doubleValue());
158+
builder.max(((Number) xContent.getOrDefault(MAX_FIELD, Double.NaN)).doubleValue());
159+
160+
parseBuckets(Types.forciblyCast(xContent.getOrDefault(NEGATIVE_FIELD, Collections.emptyMap())), builder::setNegativeBucket);
161+
parseBuckets(Types.forciblyCast(xContent.getOrDefault(POSITIVE_FIELD, Collections.emptyMap())), builder::setPositiveBucket);
162+
163+
return builder.build();
164+
}
165+
166+
private static void parseBuckets(Map<String, List<Number>> serializedBuckets, BiConsumer<Long, Long> bucketSetter) {
167+
List<Number> indices = serializedBuckets.getOrDefault(BUCKET_INDICES_FIELD, Collections.emptyList());
168+
List<Number> counts = serializedBuckets.getOrDefault(BUCKET_COUNTS_FIELD, Collections.emptyList());
169+
assert indices.size() == counts.size();
170+
for (int i = 0; i < indices.size(); i++) {
171+
bucketSetter.accept(indices.get(i).longValue(), counts.get(i).longValue());
172+
}
173+
}
104174
}

libs/exponential-histogram/src/test/java/org/elasticsearch/exponentialhistogram/ExponentialHistogramXContentTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import org.elasticsearch.common.Strings;
2525
import org.elasticsearch.xcontent.XContentBuilder;
26+
import org.elasticsearch.xcontent.XContentParser;
27+
import org.elasticsearch.xcontent.XContentParserConfiguration;
2628
import org.elasticsearch.xcontent.json.JsonXContent;
2729

2830
import java.io.IOException;
@@ -31,6 +33,11 @@
3133

3234
public class ExponentialHistogramXContentTests extends ExponentialHistogramTestCase {
3335

36+
public void testNullHistogram() {
37+
assertThat(toJson(null), equalTo("null"));
38+
checkRoundTrip(null);
39+
}
40+
3441
public void testEmptyHistogram() {
3542
ExponentialHistogram emptyHistogram = ExponentialHistogram.empty();
3643
assertThat(toJson(emptyHistogram), equalTo("{\"scale\":" + emptyHistogram.scale() + ",\"sum\":0.0}"));
@@ -62,18 +69,21 @@ public void testFullHistogram() {
6269
+ "}"
6370
)
6471
);
72+
checkRoundTrip(histo);
6573
}
6674

6775
public void testOnlyZeroThreshold() {
6876
ExponentialHistogram histo = createAutoReleasedHistogram(b -> b.scale(3).sum(1.1).zeroBucket(ZeroBucket.create(5.0, 0)));
6977
assertThat(toJson(histo), equalTo("{\"scale\":3,\"sum\":1.1,\"zero\":{\"threshold\":5.0}}"));
78+
checkRoundTrip(histo);
7079
}
7180

7281
public void testOnlyZeroCount() {
7382
ExponentialHistogram histo = createAutoReleasedHistogram(
7483
b -> b.zeroBucket(ZeroBucket.create(0.0, 7)).scale(2).sum(1.1).min(0).max(0)
7584
);
7685
assertThat(toJson(histo), equalTo("{\"scale\":2,\"sum\":1.1,\"min\":0.0,\"max\":0.0,\"zero\":{\"count\":7}}"));
86+
checkRoundTrip(histo);
7787
}
7888

7989
public void testOnlyPositiveBuckets() {
@@ -84,6 +94,7 @@ public void testOnlyPositiveBuckets() {
8494
toJson(histo),
8595
equalTo("{\"scale\":4,\"sum\":1.1,\"min\":0.5,\"max\":2.5,\"positive\":{\"indices\":[-1,2],\"counts\":[3,5]}}")
8696
);
97+
checkRoundTrip(histo);
8798
}
8899

89100
public void testOnlyNegativeBuckets() {
@@ -94,6 +105,7 @@ public void testOnlyNegativeBuckets() {
94105
toJson(histo),
95106
equalTo("{\"scale\":5,\"sum\":1.1,\"min\":-0.5,\"max\":-0.25,\"negative\":{\"indices\":[-1,2],\"counts\":[4,6]}}")
96107
);
108+
checkRoundTrip(histo);
97109
}
98110

99111
private static String toJson(ExponentialHistogram histo) {
@@ -105,4 +117,17 @@ private static String toJson(ExponentialHistogram histo) {
105117
}
106118
}
107119

120+
private static void checkRoundTrip(ExponentialHistogram histo) {
121+
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
122+
ExponentialHistogramXContent.serialize(builder, histo);
123+
String json = Strings.toString(builder);
124+
try (XContentParser parser = JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, json)) {
125+
ExponentialHistogram parsed = ExponentialHistogramXContent.parseForTesting(parser);
126+
assertThat(parsed, equalTo(histo));
127+
}
128+
} catch (IOException e) {
129+
throw new RuntimeException(e);
130+
}
131+
}
132+
108133
}

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,6 @@ tests:
405405
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
406406
method: test {p0=analytics/nested_top_metrics_sort/terms order by top metrics numeric not null integer values}
407407
issue: https://github.com/elastic/elasticsearch/issues/135162
408-
- class: org.elasticsearch.xpack.esql.qa.single_node.PushQueriesIT
409-
method: testEqualityAndOther {SEMANTIC_TEXT_WITH_KEYWORD}
410-
issue: https://github.com/elastic/elasticsearch/issues/135333
411408
- class: org.elasticsearch.search.sort.FieldSortIT
412409
method: testSortMixedFieldTypes
413410
issue: https://github.com/elastic/elasticsearch/issues/129445

server/src/main/java/org/elasticsearch/index/mapper/BlockLoader.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.lucene.index.SortedDocValues;
1414
import org.apache.lucene.index.SortedSetDocValues;
1515
import org.apache.lucene.util.BytesRef;
16+
import org.elasticsearch.common.breaker.CircuitBreakingException;
1617
import org.elasticsearch.core.Nullable;
1718
import org.elasticsearch.core.Releasable;
1819
import org.elasticsearch.index.mapper.blockloader.docvalues.BlockDocValuesReader;
@@ -377,6 +378,13 @@ interface Docs {
377378
* also a test implementation, but there may be no more other implementations.
378379
*/
379380
interface BlockFactory {
381+
/**
382+
* Adjust the circuit breaker with the given delta, if the delta is negative, the breaker will
383+
* be adjusted without tripping.
384+
* @throws CircuitBreakingException if the breaker was put above its limit
385+
*/
386+
void adjustBreaker(long delta) throws CircuitBreakingException;
387+
380388
/**
381389
* Build a builder to load booleans as loaded from doc values. Doc values
382390
* load booleans in sorted order.
@@ -486,6 +494,12 @@ interface BlockFactory {
486494
*/
487495
Block constantBytes(BytesRef value, int count);
488496

497+
/**
498+
* Build a block that contains {@code value} repeated
499+
* {@code count} times.
500+
*/
501+
Block constantInt(int value, int count);
502+
489503
/**
490504
* Build a reader for reading {@link SortedDocValues}
491505
*/

0 commit comments

Comments
 (0)