Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,12 @@ tests:
- class: org.elasticsearch.reindex.management.ReindexManagementClientYamlTestSuiteIT
method: test {yaml=reindex/30_cancel_reindex/Cancel running reindex returns response and GET confirms completed}
issue: https://github.com/elastic/elasticsearch/issues/142079
- class: org.elasticsearch.xpack.esql.qa.multi_node.GenerativeIT
method: test
issue: https://github.com/elastic/elasticsearch/issues/143023
- class: org.elasticsearch.xpack.sql.qa.security.CliApiKeyIT
method: testCliConnectionWithApiKey
issue: https://github.com/elastic/elasticsearch/issues/143125
- class: org.elasticsearch.packaging.test.DebMetadataTests
method: test05CheckLintian
issue: https://github.com/elastic/elasticsearch/issues/142819
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeIT
method: test
issue: https://github.com/elastic/elasticsearch/issues/143023
- class: org.elasticsearch.xpack.security.apikey.ApiKeyWorkflowsRestrictionRestIT
method: testWorkflowsRestrictionAllowsAccess
issue: https://github.com/elastic/elasticsearch/issues/143130
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import org.elasticsearch.xpack.esql.parser.ParserUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -48,6 +48,7 @@
import static org.elasticsearch.test.ESTestCase.randomFrom;
import static org.elasticsearch.test.ESTestCase.randomIntBetween;
import static org.elasticsearch.test.ESTestCase.randomLongBetween;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.COMMONLY_SUPPORTED_TYPES;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.areUnmappedFieldsAllowed;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.binaryMathFunction;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.caseFunction;
Expand All @@ -58,6 +59,7 @@
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.conversionFunction;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.dateDiffFunction;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.dateFunction;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.fullTextFunction;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.greatestLeastFunction;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.inExpression;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.ipPrefixFunction;
Expand All @@ -71,6 +73,7 @@
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.stringFunction;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.stringToBoolFunction;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.stringToIntFunction;
import static org.elasticsearch.xpack.esql.generator.FunctionGenerator.typeSafeExpression;
import static org.elasticsearch.xpack.esql.generator.command.pipe.KeepGenerator.randomUnmappedFieldName;

public class EsqlQueryGenerator {
Expand Down Expand Up @@ -170,7 +173,7 @@ public static void generatePipeline(
// do a dummy query to get available fields first
// TODO: modify when METRICS_INFO available https://github.com/elastic/elasticsearch/issues/141413
String index = promQLGenerator.generateIndices(schema);
var fromDesc = new CommandGenerator.CommandDescription("from", FromGenerator.INSTANCE, "FROM " + index, Map.of());
var fromDesc = new CommandGenerator.CommandDescription("from", FromGenerator.INSTANCE, "FROM " + index, new HashMap<>());
executor.run(FromGenerator.INSTANCE, fromDesc);
executor.clearCommandHistory();
desc = promQLGenerator.generateWithIndices(List.of(), executor.currentSchema(), schema, queryExecutor, index);
Expand Down Expand Up @@ -217,23 +220,14 @@ public static void generatePipeline(
}
}

/**
* Generates a boolean expression.
* @deprecated Use {@link #booleanExpression(List, List)} instead to properly handle unmapped fields
*/
@Deprecated
public static String booleanExpression(List<Column> previousOutput) {
return booleanExpression(previousOutput, null);
}

/**
* Generates a boolean expression.
* @param previousOutput the columns available in the current schema
* @param previousCommands the list of commands executed so far (used to determine if unmapped fields are allowed)
*/
public static String booleanExpression(List<Column> previousOutput, List<CommandGenerator.CommandDescription> previousCommands) {
boolean allowUnmapped = areUnmappedFieldsAllowed(previousCommands);
return switch (randomIntBetween(0, 11)) {
return switch (randomIntBetween(0, 13)) {
case 0, 1, 2 -> {
String field = randomNumericField(previousOutput);
if (field == null) {
Expand All @@ -249,6 +243,7 @@ public static String booleanExpression(List<Column> previousOutput, List<Command
case 8 -> likeExpression(previousOutput, allowUnmapped);
case 9 -> rlikeExpression(previousOutput, allowUnmapped);
case 10 -> cidrMatchFunction(previousOutput, allowUnmapped);
case 11, 12 -> fullTextFunction(previousOutput, previousCommands);
default -> {
// Numeric comparison on function result
String funcExpr = stringToIntFunction(previousOutput, allowUnmapped);
Expand Down Expand Up @@ -501,14 +496,14 @@ public static String agg(List<Column> previousOutput, List<CommandGenerator.Comm
case 6, 7 -> {
// top() accepts: boolean, double, integer, long, date, ip, keyword, text
Set<String> topTypes = Set.of("boolean", "double", "integer", "long", "date", "datetime", "ip", "keyword", "text");
String topField = FunctionGenerator.typeSafeExpression(previousOutput, topTypes, allowUnmapped);
String topField = typeSafeExpression(previousOutput, topTypes, allowUnmapped);
if (topField == null) topField = anyName;
String order = randomIntBetween(0, 1) == 0 ? "asc" : "desc";
yield "top(" + topField + ", " + randomIntBetween(1, 5) + ", \"" + order + "\")";
}
case 8 -> {
// sample() - use a commonly supported field to avoid type issues
String sampleField = randomName(previousOutput, FunctionGenerator.COMMONLY_SUPPORTED_TYPES);
String sampleField = randomName(previousOutput, COMMONLY_SUPPORTED_TYPES);
if (sampleField == null) sampleField = anyName;
yield "sample(" + sampleField + ", " + randomIntBetween(1, 10) + ")";
}
Expand Down Expand Up @@ -657,7 +652,7 @@ public static String functionExpression(List<Column> previousOutput, List<Comman
case 13 -> greatestLeastFunction(previousOutput, allowUnmapped);
case 14 -> mvSliceZipFunction(previousOutput, allowUnmapped);
case 15 -> splitFunction(previousOutput, allowUnmapped);
case 16 -> clampFunction(previousOutput, allowUnmapped);
case 16 -> clampFunction(previousOutput);
case 17 -> dateDiffFunction(previousOutput, allowUnmapped);
default -> ipPrefixFunction(previousOutput, allowUnmapped);
};
Expand Down
Loading