Skip to content

Commit c90766d

Browse files
authored
ESQL: Rework FieldExtractorIT's pragmas (#127117)
This reworks the way `FieldExtractorIT` requests fields to be loaded. Previously it used pragmas and would skip itself if it wasn't a unit test. This removes that behavior and sends pragmas but also sends the `accept_pragma_risks` option which is used in production releases to allow pragmas - it's especially useful for testing. This *should* make the tests more consistent. Closes #127100
1 parent 5964ad7 commit c90766d

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

x-pack/plugin/esql/qa/server/mixed-cluster/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/mixed/FieldExtractorIT.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.index.mapper.MappedFieldType;
1313
import org.elasticsearch.test.TestClustersThreadFilter;
1414
import org.elasticsearch.test.cluster.ElasticsearchCluster;
15+
import org.elasticsearch.test.cluster.util.Version;
1516
import org.elasticsearch.xpack.esql.qa.rest.FieldExtractorTestCase;
1617
import org.hamcrest.Matcher;
1718
import org.junit.ClassRule;
@@ -40,4 +41,16 @@ protected Matcher<Integer> pidMatcher() {
4041
return preference == MappedFieldType.FieldExtractPreference.STORED ? anyOf(equalTo(111), nullValue()) : nullValue(Integer.class);
4142
}
4243

44+
@Override
45+
protected void canUsePragmasOk() {
46+
String bwc = System.getProperty("tests.old_cluster_version");
47+
if (bwc == null) {
48+
bwc = System.getProperty("tests.serverless.bwc_stack_version");
49+
}
50+
if (bwc == null) {
51+
throw new AssertionError("can't find bwc version");
52+
}
53+
Version oldVersion = Version.fromString(bwc);
54+
assumeTrue("pragma ok not supported", oldVersion.onOrAfter("8.16.0"));
55+
}
4356
}

x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/FieldExtractorIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ public FieldExtractorIT(MappedFieldType.FieldExtractPreference preference) {
2828
protected String getTestRestCluster() {
2929
return cluster.getHttpAddresses();
3030
}
31+
32+
@Override
33+
protected void canUsePragmasOk() {
34+
// always ok
35+
}
3136
}

x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/FieldExtractorIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ public FieldExtractorIT(MappedFieldType.FieldExtractPreference preference) {
2828
protected String getTestRestCluster() {
2929
return cluster.getHttpAddresses();
3030
}
31+
32+
@Override
33+
protected void canUsePragmasOk() {
34+
// always can use
35+
}
3136
}

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1111

1212
import org.apache.http.util.EntityUtils;
13-
import org.elasticsearch.Build;
1413
import org.elasticsearch.Version;
1514
import org.elasticsearch.client.Request;
1615
import org.elasticsearch.client.Response;
@@ -35,7 +34,6 @@
3534
import org.elasticsearch.xpack.esql.core.type.DataType;
3635
import org.elasticsearch.xpack.esql.plugin.QueryPragmas;
3736
import org.hamcrest.Matcher;
38-
import org.junit.Before;
3937

4038
import java.io.IOException;
4139
import java.math.BigDecimal;
@@ -83,17 +81,6 @@ public static List<Object[]> args() throws Exception {
8381

8482
protected FieldExtractorTestCase(MappedFieldType.FieldExtractPreference preference) {
8583
this.preference = preference;
86-
if (preference != null) {
87-
assumeTrue("Requires pragma", Build.current().isSnapshot());
88-
}
89-
}
90-
91-
@Before
92-
public void notOld() {
93-
assumeTrue(
94-
"support changed pretty radically in 8.12 so we don't test against 8.11",
95-
getCachedNodesVersions().stream().allMatch(v -> Version.fromString(v).onOrAfter(Version.V_8_12_0))
96-
);
9784
}
9885

9986
public void testTextField() throws IOException {
@@ -1784,10 +1771,14 @@ private String deyaml(String err) {
17841771
private Map<String, Object> runEsql(String query) throws IOException {
17851772
RestEsqlTestCase.RequestObjectBuilder request = new RestEsqlTestCase.RequestObjectBuilder().query(query);
17861773
if (preference != null) {
1774+
canUsePragmasOk();
17871775
request = request.pragmas(
17881776
Settings.builder().put(QueryPragmas.FIELD_EXTRACT_PREFERENCE.getKey(), preference.toString()).build()
17891777
);
1778+
request.pragmasOk();
17901779
}
17911780
return runEsqlSync(request);
17921781
}
1782+
1783+
protected abstract void canUsePragmasOk();
17931784
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ public RequestObjectBuilder keepOnCompletion(boolean value) throws IOException {
178178
return this;
179179
}
180180

181+
/**
182+
* Allow sending pragmas even in non-snapshot builds.
183+
*/
184+
public RequestObjectBuilder pragmasOk() throws IOException {
185+
builder.field("accept_pragma_risks", true);
186+
return this;
187+
}
188+
181189
Boolean keepOnCompletion() {
182190
return keepOnCompletion;
183191
}

0 commit comments

Comments
 (0)