Skip to content

Commit b211b03

Browse files
authored
ESQL: Further refine generative testing with known (reported) issues (#142786)
1 parent 69c5ff6 commit b211b03

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,6 @@ tests:
431431
- class: org.elasticsearch.xpack.esql.tree.EsqlNodeSubclassTests
432432
method: testTransform {class org.elasticsearch.xpack.esql.plan.logical.MMR}
433433
issue: https://github.com/elastic/elasticsearch/issues/142674
434-
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeIT
435-
method: test
436-
issue: https://github.com/elastic/elasticsearch/issues/142426
437434
- class: org.elasticsearch.xpack.esql.qa.multi_node.FieldExtractorIT
438435
method: testTsIndexConflictingTypes {null}
439436
issue: https://github.com/elastic/elasticsearch/issues/142410
@@ -443,9 +440,6 @@ tests:
443440
- class: org.elasticsearch.index.reindex.ReindexResumeIT
444441
method: testLocalResumeReindexFromScroll_slicedAuto
445442
issue: https://github.com/elastic/elasticsearch/issues/142749
446-
- class: org.elasticsearch.xpack.esql.qa.multi_node.GenerativeIT
447-
method: test
448-
issue: https://github.com/elastic/elasticsearch/issues/142426
449443

450444
# Examples:
451445
#

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import static org.elasticsearch.xpack.esql.generator.EsqlQueryGenerator.COLUMN_ORIGINAL_TYPES;
4343
import static org.elasticsearch.xpack.esql.generator.EsqlQueryGenerator.COLUMN_TYPE;
4444
import static org.elasticsearch.xpack.esql.generator.command.pipe.KeepGenerator.UNMAPPED_FIELD_NAMES;
45+
import static org.elasticsearch.xpack.esql.generator.command.source.FromGenerator.SET_UNMAPPED_FIELDS_PREFIX;
4546

4647
public abstract class GenerativeRestTest extends ESRestTestCase implements QueryExecutor {
4748

@@ -80,7 +81,9 @@ public abstract class GenerativeRestTest extends ESRestTestCase implements Query
8081
"illegal data type \\[datetime\\]", // https://github.com/elastic/elasticsearch/issues/142137
8182
"Expected to replace a single StubRelation in the plan, but none found", // https://github.com/elastic/elasticsearch/issues/142219
8283
"blocks is empty", // https://github.com/elastic/elasticsearch/issues/142473
83-
"Overflow to represent absolute value of Integer.MIN_VALUE", // https://github.com/elastic/elasticsearch/issues/142642
84+
"Overflow to represent absolute value of .*.MIN_VALUE", // https://github.com/elastic/elasticsearch/issues/142642
85+
"illegal query_string option \\[boost\\]", // https://github.com/elastic/elasticsearch/issues/142758
86+
"found value \\[.*\\] type \\[unsupported\\]", // https://github.com/elastic/elasticsearch/issues/142761
8487

8588
// Awaiting fixes for correctness
8689
"Expecting at most \\[.*\\] columns, got \\[.*\\]", // https://github.com/elastic/elasticsearch/issues/129561
@@ -261,7 +264,7 @@ protected CommandGenerator sourceCommand() {
261264
return EsqlQueryGenerator.sourceCommand();
262265
}
263266

264-
private static CommandGenerator.ValidationResult checkResults(
267+
protected static CommandGenerator.ValidationResult checkResults(
265268
List<CommandGenerator.CommandDescription> previousCommands,
266269
CommandGenerator commandGenerator,
267270
CommandGenerator.CommandDescription commandDescription,
@@ -288,12 +291,15 @@ private static CommandGenerator.ValidationResult checkResults(
288291
if (isFirstLastSameFieldError(outputValidation.errorMessage(), result.query())) {
289292
return outputValidation;
290293
}
294+
if (isForkOptimizationBugWithUnmappedFields(outputValidation.errorMessage(), result.query())) {
295+
return outputValidation;
296+
}
291297
fail("query: " + result.query() + "\nerror: " + outputValidation.errorMessage());
292298
}
293299
return outputValidation;
294300
}
295301

296-
private void checkException(QueryExecuted query) {
302+
protected void checkException(QueryExecuted query) {
297303
for (Pattern allowedError : ALLOWED_ERROR_PATTERNS) {
298304
if (isAllowedError(query.exception().getMessage(), allowedError)) {
299305
return;
@@ -305,6 +311,9 @@ private void checkException(QueryExecuted query) {
305311
if (isFirstLastSameFieldError(query.exception().getMessage(), query.query())) {
306312
return;
307313
}
314+
if (isForkOptimizationBugWithUnmappedFields(query.exception().getMessage(), query.query())) {
315+
return;
316+
}
308317
fail("query: " + query.query() + "\nexception: " + query.exception().getMessage());
309318
}
310319

@@ -389,6 +398,20 @@ private static boolean isFirstLastSameFieldError(String errorMessage, String que
389398
return false;
390399
}
391400

401+
private static final Pattern FORK_OPTIMIZED_INCORRECTLY_PATTERN = Pattern.compile(
402+
".*Plan \\[.*\\] optimized incorrectly due to missing references \\[_fork.*",
403+
Pattern.DOTALL
404+
);
405+
406+
/**
407+
* When {@code SET unmapped_fields="nullify"} is used, the _fork reference can go missing
408+
* during plan optimization.
409+
* See <a href="https://github.com/elastic/elasticsearch/issues/142762">#142762</a>
410+
*/
411+
static boolean isForkOptimizationBugWithUnmappedFields(String errorMessage, String query) {
412+
return query.startsWith(SET_UNMAPPED_FIELDS_PREFIX) && FORK_OPTIMIZED_INCORRECTLY_PATTERN.matcher(errorMessage).matches();
413+
}
414+
392415
@Override
393416
@SuppressWarnings("unchecked")
394417
public QueryExecuted execute(String query, int depth) {

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/EsqlQueryGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class EsqlQueryGenerator {
9494
/**
9595
* These are downstream commands, ie. that cannot appear as the first command in a query
9696
*/
97-
static List<CommandGenerator> PIPE_COMMANDS = List.of(
97+
public static List<CommandGenerator> PIPE_COMMANDS = List.of(
9898
ChangePointGenerator.INSTANCE,
9999
DissectGenerator.INSTANCE,
100100
DropGenerator.INSTANCE,

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/source/FromGenerator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class FromGenerator implements CommandGenerator {
2828
*/
2929
public static final String UNMAPPED_FIELDS_ENABLED = "unmappedFieldsEnabled";
3030

31+
public static final String SET_UNMAPPED_FIELDS_PREFIX = "SET unmapped_fields=\"nullify\";";
32+
3133
@Override
3234
public CommandDescription generate(
3335
List<CommandDescription> previousCommands,
@@ -38,7 +40,7 @@ public CommandDescription generate(
3840
boolean useUnmappedFields = shouldAddUnmappedFieldWithProbabilityIncrease(3);
3941
StringBuilder result = new StringBuilder();
4042
if (useUnmappedFields) {
41-
result.append("SET unmapped_fields=\"nullify\";");
43+
result.append(SET_UNMAPPED_FIELDS_PREFIX);
4244
}
4345
result.append("from ");
4446
int items = randomIntBetween(1, 3);

0 commit comments

Comments
 (0)