Skip to content

Commit dc8e243

Browse files
authored
Merge branch 'main' into esql-sample-parameter
2 parents 2cc85b8 + 6998c96 commit dc8e243

File tree

18 files changed

+107
-232
lines changed

18 files changed

+107
-232
lines changed

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ static TransportVersion def(int id) {
195195
public static final TransportVersion ML_INFERENCE_MISTRAL_CHAT_COMPLETION_ADDED_8_19 = def(8_841_0_47);
196196
public static final TransportVersion ML_INFERENCE_ELASTIC_RERANK_ADDED_8_19 = def(8_841_0_48);
197197
public static final TransportVersion NONE_CHUNKING_STRATEGY_8_19 = def(8_841_0_49);
198+
public static final TransportVersion IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST_8_19 = def(8_841_0_50);
198199
public static final TransportVersion V_9_0_0 = def(9_000_0_09);
199200
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_1 = def(9_000_0_10);
200201
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_2 = def(9_000_0_11);

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,12 +1326,15 @@ private Engine.GetResult innerGet(Engine.Get get, boolean translogOnly, Function
13261326
public Engine.RefreshResult refresh(String source) {
13271327
verifyNotClosed();
13281328
logger.trace("refresh with source [{}]", source);
1329-
return getEngine().refresh(source);
1329+
return withEngine(engine -> engine.refresh(source));
13301330
}
13311331

13321332
public void externalRefresh(String source, ActionListener<Engine.RefreshResult> listener) {
13331333
verifyNotClosed();
1334-
getEngine().externalRefresh(source, listener);
1334+
withEngine(engine -> {
1335+
engine.externalRefresh(source, listener);
1336+
return null;
1337+
});
13351338
}
13361339

13371340
/**

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/MetadataAttribute.java

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -69,53 +69,13 @@ public MetadataAttribute(Source source, String name, DataType dataType, boolean
6969
this(source, name, dataType, Nullability.TRUE, null, false, searchable);
7070
}
7171

72-
@Deprecated
73-
/**
74-
* Old constructor from when this had a qualifier string. Still needed to not break serialization.
75-
*/
76-
private MetadataAttribute(
77-
Source source,
78-
String name,
79-
DataType dataType,
80-
@Nullable String qualifier,
81-
Nullability nullability,
82-
@Nullable NameId id,
83-
boolean synthetic,
84-
boolean searchable
85-
) {
86-
this(source, name, dataType, nullability, id, synthetic, searchable);
87-
}
88-
89-
@SuppressWarnings("unchecked")
90-
private MetadataAttribute(StreamInput in) throws IOException {
91-
/*
92-
* The funny casting dance with `(StreamInput & PlanStreamInput) in` is required
93-
* because we're in esql-core here and the real PlanStreamInput is in
94-
* esql-proper. And because NamedWriteableRegistry.Entry needs StreamInput,
95-
* not a PlanStreamInput. And we need PlanStreamInput to handle Source
96-
* and NameId. This should become a hard cast when we move everything out
97-
* of esql-core.
98-
*/
99-
this(
100-
Source.readFrom((StreamInput & PlanStreamInput) in),
101-
in.readString(),
102-
DataType.readFrom(in),
103-
in.readOptionalString(),
104-
in.readEnum(Nullability.class),
105-
NameId.readFrom((StreamInput & PlanStreamInput) in),
106-
in.readBoolean(),
107-
in.readBoolean()
108-
);
109-
}
110-
11172
@Override
11273
public void writeTo(StreamOutput out) throws IOException {
11374
if (((PlanStreamOutput) out).writeAttributeCacheHeader(this)) {
11475
Source.EMPTY.writeTo(out);
11576
out.writeString(name());
11677
dataType().writeTo(out);
117-
// We used to write the qualifier here. We can still do if needed in the future.
118-
out.writeOptionalString(null);
78+
out.writeOptionalString(null); // qualifier, no longer used
11979
out.writeEnum(nullable());
12080
id().writeTo(out);
12181
out.writeBoolean(synthetic());
@@ -124,7 +84,25 @@ public void writeTo(StreamOutput out) throws IOException {
12484
}
12585

12686
public static MetadataAttribute readFrom(StreamInput in) throws IOException {
127-
return ((PlanStreamInput) in).readAttributeWithCache(MetadataAttribute::new);
87+
/*
88+
* The funny casting dance with `(StreamInput & PlanStreamInput) in` is required
89+
* because we're in esql-core here and the real PlanStreamInput is in
90+
* esql-proper. And because NamedWriteableRegistry.Entry needs StreamInput,
91+
* not a PlanStreamInput. And we need PlanStreamInput to handle Source
92+
* and NameId. This should become a hard cast when we move everything out
93+
* of esql-core.
94+
*/
95+
return ((PlanStreamInput) in).readAttributeWithCache(stream -> {
96+
Source source = Source.readFrom((StreamInput & PlanStreamInput) stream);
97+
String name = stream.readString();
98+
DataType dataType = DataType.readFrom(stream);
99+
String qualifier = stream.readOptionalString(); // qualifier, no longer used
100+
Nullability nullability = stream.readEnum(Nullability.class);
101+
NameId id = NameId.readFrom((StreamInput & PlanStreamInput) stream);
102+
boolean synthetic = stream.readBoolean();
103+
boolean searchable = stream.readBoolean();
104+
return new MetadataAttribute(source, name, dataType, nullability, id, synthetic, searchable);
105+
});
128106
}
129107

130108
@Override
@@ -134,7 +112,7 @@ public String getWriteableName() {
134112

135113
@Override
136114
protected MetadataAttribute clone(Source source, String name, DataType type, Nullability nullability, NameId id, boolean synthetic) {
137-
return new MetadataAttribute(source, name, type, null, nullability, id, synthetic, searchable);
115+
return new MetadataAttribute(source, name, type, nullability, id, synthetic, searchable);
138116
}
139117

140118
@Override

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestSampleTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class RestSampleTestCase extends ESRestTestCase {
3333
public void skipWhenSampleDisabled() throws IOException {
3434
assumeTrue(
3535
"Requires SAMPLE capability",
36-
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.SAMPLE_V2.capabilityName()))
36+
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.SAMPLE_V3.capabilityName()))
3737
);
3838
}
3939

x-pack/plugin/esql/qa/testFixtures/src/main/resources/sample.csv-spec

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// because the CSV tests don't support such assertions.
1010

1111
row
12-
required_capability: sample_v2
12+
required_capability: sample_v3
1313

1414
ROW x = 1 | SAMPLE .999999999
1515
;
@@ -20,7 +20,7 @@ x:integer
2020

2121

2222
row and mv_expand
23-
required_capability: sample_v2
23+
required_capability: sample_v3
2424

2525
ROW x = [1,2,3,4,5] | MV_EXPAND x | SAMPLE .999999999
2626
;
@@ -35,15 +35,14 @@ x:integer
3535

3636

3737
adjust stats for sampling
38-
required_capability: sample_v2
38+
required_capability: sample_v3
3939

4040
FROM employees
4141
| SAMPLE 0.5
42-
| STATS count = COUNT(), values_count = MV_COUNT(VALUES(emp_no)), avg_emp_no = AVG(emp_no), sum_emp_no = SUM(emp_no)
43-
| EVAL is_expected = count >= 20 AND count <= 180 AND
44-
values_count >= 10 AND values_count <= 90 AND
42+
| STATS count = COUNT(), avg_emp_no = AVG(emp_no), sum_emp_no = SUM(emp_no)
43+
| EVAL is_expected = count >= 10 AND count <= 90 AND
4544
avg_emp_no > 10010 AND avg_emp_no < 10090 AND
46-
sum_emp_no > 20*10010 AND sum_emp_no < 180*10090
45+
sum_emp_no > 10*10010 AND sum_emp_no < 90*10090
4746
| KEEP is_expected
4847
;
4948

@@ -53,14 +52,13 @@ true
5352

5453

5554
before where
56-
required_capability: sample_v2
55+
required_capability: sample_v3
5756

5857
FROM employees
5958
| SAMPLE 0.5
6059
| WHERE emp_no > 10050
61-
| STATS count = COUNT(), values_count = MV_COUNT(VALUES(emp_no)), avg_emp_no = AVG(emp_no)
62-
| EVAL is_expected = count >= 5 AND count <= 95 AND
63-
values_count >= 2 AND values_count <= 48 AND
60+
| STATS count = COUNT(), avg_emp_no = AVG(emp_no)
61+
| EVAL is_expected = count >= 2 AND count <= 48 AND
6462
avg_emp_no > 10055 AND avg_emp_no < 10095
6563
| KEEP is_expected
6664
;
@@ -71,14 +69,13 @@ true
7169

7270

7371
after where
74-
required_capability: sample_v2
72+
required_capability: sample_v3
7573

7674
FROM employees
7775
| WHERE emp_no <= 10050
7876
| SAMPLE 0.5
79-
| STATS count = COUNT(), values_count = MV_COUNT(VALUES(emp_no)), avg_emp_no = AVG(emp_no)
80-
| EVAL is_expected = count >= 5 AND count <= 95 AND
81-
values_count >= 2 AND values_count <= 48 AND
77+
| STATS count = COUNT(), avg_emp_no = AVG(emp_no)
78+
| EVAL is_expected = count >= 2 AND count <= 48 AND
8279
avg_emp_no > 10005 AND avg_emp_no < 10045
8380
| KEEP is_expected
8481
;
@@ -89,14 +86,13 @@ true
8986

9087

9188
before sort
92-
required_capability: sample_v2
89+
required_capability: sample_v3
9390

9491
FROM employees
9592
| SAMPLE 0.5
9693
| SORT emp_no
97-
| STATS count = COUNT(), values_count = MV_COUNT(VALUES(emp_no)), avg_emp_no = AVG(emp_no)
98-
| EVAL is_expected = count >= 20 AND count <= 180 AND
99-
values_count >= 10 AND values_count <= 90 AND
94+
| STATS count = COUNT(), avg_emp_no = AVG(emp_no)
95+
| EVAL is_expected = count >= 10 AND count <= 90 AND
10096
avg_emp_no > 10010 AND avg_emp_no < 10090
10197
| KEEP is_expected
10298
;
@@ -107,14 +103,13 @@ true
107103

108104

109105
after sort
110-
required_capability: sample_v2
106+
required_capability: sample_v3
111107

112108
FROM employees
113109
| SORT emp_no
114110
| SAMPLE 0.5
115-
| STATS count = COUNT(), values_count = MV_COUNT(VALUES(emp_no)), avg_emp_no = AVG(emp_no)
116-
| EVAL is_expected = count >= 20 AND count <= 180 AND
117-
values_count >= 10 AND values_count <= 90 AND
111+
| STATS count = COUNT(), avg_emp_no = AVG(emp_no)
112+
| EVAL is_expected = count >= 10 AND count <= 90 AND
118113
avg_emp_no > 10010 AND avg_emp_no < 10090
119114
| KEEP is_expected
120115
;
@@ -125,13 +120,13 @@ true
125120

126121

127122
before limit
128-
required_capability: sample_v2
123+
required_capability: sample_v3
129124

130125
FROM employees
131126
| SAMPLE 0.5
132127
| LIMIT 10
133-
| STATS count = COUNT(), values_count = MV_COUNT(VALUES(emp_no))
134-
| EVAL is_expected = count == 10 AND values_count == 10
128+
| STATS count = COUNT(emp_no)
129+
| EVAL is_expected = count == 10
135130
| KEEP is_expected
136131
;
137132

@@ -141,14 +136,13 @@ true
141136

142137

143138
after limit
144-
required_capability: sample_v2
139+
required_capability: sample_v3
145140

146141
FROM employees
147142
| LIMIT 50
148143
| SAMPLE 0.5
149-
| STATS count = COUNT(), values_count = MV_COUNT(VALUES(emp_no))
150-
| EVAL is_expected = count >= 5 AND count <= 95 AND
151-
values_count >= 2 AND values_count <= 48
144+
| STATS count = COUNT(emp_no)
145+
| EVAL is_expected = count >= 2 AND count <= 48
152146
| KEEP is_expected
153147
;
154148

@@ -158,7 +152,7 @@ true
158152

159153

160154
before mv_expand
161-
required_capability: sample_v2
155+
required_capability: sample_v3
162156

163157
ROW x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50], y = [1,2]
164158
| MV_EXPAND x
@@ -176,7 +170,7 @@ true
176170

177171

178172
after mv_expand
179-
required_capability: sample_v2
173+
required_capability: sample_v3
180174

181175
ROW x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50], y = [1,2]
182176
| MV_EXPAND x
@@ -194,15 +188,14 @@ true
194188

195189

196190
multiple samples
197-
required_capability: sample_v2
191+
required_capability: sample_v3
198192

199193
FROM employees
200194
| SAMPLE 0.7
201195
| SAMPLE 0.8
202196
| SAMPLE 0.9
203-
| STATS count = COUNT(), values_count = MV_COUNT(VALUES(emp_no)), avg_emp_no = AVG(emp_no)
204-
| EVAL is_expected = count >= 20 AND count <= 180 AND
205-
values_count >= 10 AND values_count <= 90 AND
197+
| STATS count = COUNT(), avg_emp_no = AVG(emp_no)
198+
| EVAL is_expected = count >= 10 AND count <= 90 AND
206199
avg_emp_no > 10010 AND avg_emp_no < 10090
207200
| KEEP is_expected
208201
;
@@ -213,15 +206,14 @@ true
213206

214207

215208
after stats
216-
required_capability: sample_v2
209+
required_capability: sample_v3
217210

218211
FROM employees
219212
| SAMPLE 0.5
220213
| STATS avg_salary = AVG(salary) BY job_positions
221214
| SAMPLE 0.8
222-
| STATS count = COUNT(), values_count = MV_COUNT(VALUES(avg_salary)), avg_avg_salary = AVG(avg_salary)
223-
| EVAL is_expected = count >= 1 AND count <= 20 AND
224-
values_count >= 1 AND values_count <= 16 AND
215+
| STATS count = COUNT(), avg_avg_salary = AVG(avg_salary)
216+
| EVAL is_expected = count >= 1 AND count <= 16 AND
225217
avg_avg_salary > 25000 AND avg_avg_salary < 75000
226218
| KEEP is_expected
227219
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ public enum Cap {
10821082
/**
10831083
* Support for the SAMPLE command
10841084
*/
1085-
SAMPLE_V2(Build.current().isSnapshot()),
1085+
SAMPLE_V3(Build.current().isSnapshot()),
10861086

10871087
/**
10881088
* The {@code _query} API now gives a cast recommendation if multiple types are found in certain instances.

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Count.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
import org.elasticsearch.xpack.esql.expression.function.FunctionType;
2626
import org.elasticsearch.xpack.esql.expression.function.Param;
2727
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.FromAggregateMetricDouble;
28-
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.ToLong;
2928
import org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvCount;
3029
import org.elasticsearch.xpack.esql.expression.function.scalar.nulls.Coalesce;
31-
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Div;
3230
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Mul;
3331
import org.elasticsearch.xpack.esql.planner.ToAggregator;
3432

@@ -39,11 +37,9 @@
3937
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
4038
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
4139

42-
public class Count extends AggregateFunction implements ToAggregator, SurrogateExpression, HasSampleCorrection {
40+
public class Count extends AggregateFunction implements ToAggregator, SurrogateExpression {
4341
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Count", Count::new);
4442

45-
private final boolean isSampleCorrected;
46-
4743
@FunctionInfo(
4844
returnType = "long",
4945
description = "Returns the total number (count) of input values.",
@@ -98,20 +94,11 @@ public Count(
9894
}
9995

10096
public Count(Source source, Expression field, Expression filter) {
101-
this(source, field, filter, false);
102-
}
103-
104-
private Count(Source source, Expression field, Expression filter, boolean isSampleCorrected) {
10597
super(source, field, filter, emptyList());
106-
this.isSampleCorrected = isSampleCorrected;
10798
}
10899

109100
private Count(StreamInput in) throws IOException {
110101
super(in);
111-
// isSampleCorrected is only used during query optimization to mark
112-
// whether this function has been processed. Hence there's no need to
113-
// serialize it.
114-
this.isSampleCorrected = false;
115102
}
116103

117104
@Override
@@ -182,14 +169,4 @@ public Expression surrogate() {
182169

183170
return null;
184171
}
185-
186-
@Override
187-
public boolean isSampleCorrected() {
188-
return isSampleCorrected;
189-
}
190-
191-
@Override
192-
public Expression sampleCorrection(Expression sampleProbability) {
193-
return new ToLong(source(), new Div(source(), new Count(source(), field(), filter(), true), sampleProbability));
194-
}
195172
}

0 commit comments

Comments
 (0)