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
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,14 @@ public void test() throws IOException {
var exec = new EsqlQueryGenerator.Executor() {
@Override
public void run(CommandGenerator generator, CommandGenerator.CommandDescription current) {
previousCommands.add(current);
final String command = current.commandString();

final QueryExecuted result = previousResult == null
? execute(command, 0)
: execute(previousResult.query() + command, previousResult.depth());

final boolean hasException = result.exception() != null;
if (hasException || checkResults(List.of(), generator, current, previousResult, result).success() == false) {
if (hasException || checkResults(previousCommands, generator, current, previousResult, result).success() == false) {
if (hasException) {
checkException(result);
}
Expand All @@ -192,6 +191,7 @@ public void run(CommandGenerator generator, CommandGenerator.CommandDescription
continueExecuting = true;
currentSchema = result.outputSchema();
}
previousCommands.add(current);
previousResult = result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.elasticsearch.xpack.esql.CsvTestsDataLoader;
import org.elasticsearch.xpack.esql.generator.Column;
import org.elasticsearch.xpack.esql.generator.EsqlQueryGenerator;
import org.elasticsearch.xpack.esql.generator.FunctionGenerator;
import org.elasticsearch.xpack.esql.generator.LookupIdx;
import org.elasticsearch.xpack.esql.generator.QueryExecutor;

Expand Down Expand Up @@ -119,7 +120,15 @@ static ValidationResult expectSameRowCount(
return VALIDATION_OK;
}

static ValidationResult expectSameColumns(List<Column> previousColumns, List<Column> columns) {
static ValidationResult expectSameColumns(
List<CommandDescription> previousCommands,
List<Column> previousColumns,
List<Column> columns
) {

if (FunctionGenerator.isUnmappedFieldsEnabled(previousCommands)) {
return VALIDATION_OK;
}
Comment on lines +123 to +131
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as a temporary fix, but the method now doesn't do what it says it will, and it doesn't feel good.
In theory, unmapped fields should be detected in the expectation an increase the expected column count (I think it's possible?).
But I think it's fine to have it as a continuation or an issue. Specially with unmapped field being very new


if (previousColumns.stream().anyMatch(x -> x.name().contains("<all-fields-projected>"))) {
return VALIDATION_OK; // known bug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.elasticsearch.xpack.esql.generator.Column;
import org.elasticsearch.xpack.esql.generator.EsqlQueryGenerator;
import org.elasticsearch.xpack.esql.generator.FunctionGenerator;
import org.elasticsearch.xpack.esql.generator.QueryExecutor;
import org.elasticsearch.xpack.esql.generator.command.CommandGenerator;

Expand Down Expand Up @@ -89,7 +90,8 @@ public ValidationResult validateOutput(
List<String> expectedColumns = (List<String>) commandDescription.context().get(NEW_COLUMNS);
List<String> resultColNames = columns.stream().map(Column::name).toList();
List<String> lastColumns = resultColNames.subList(resultColNames.size() - expectedColumns.size(), resultColNames.size());
if (columns.size() < expectedColumns.size() || lastColumns.equals(expectedColumns) == false) {
if (FunctionGenerator.isUnmappedFieldsEnabled(previousCommands) == false
&& (columns.size() < expectedColumns.size() || lastColumns.equals(expectedColumns) == false)) {
return new ValidationResult(
false,
"Expecting the following as last columns ["
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public ValidationResult validateOutput(
if (output.size() > limit) {
return new ValidationResult(false, "Expecting at most [" + limit + "] records, got [" + output.size() + "]");
}
return CommandGenerator.expectSameColumns(previousColumns, columns);
return CommandGenerator.expectSameColumns(previousCommands, previousColumns, columns);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public CommandDescription generate(
}
}
String cmdString = stringBuilder.toString();
return new CommandDescription(LOOKUP_JOIN, this, cmdString, Map.of());
return new CommandDescription(LOOKUP_JOIN, this, cmdString, Map.of("nKeys", keyNames.size()));
}

@Override
Expand All @@ -107,8 +107,8 @@ public ValidationResult validateOutput(
return VALIDATION_OK;
}

// the -1 is for the additional RENAME, that could drop one column
int prevCols = previousColumns.size() - 1;
// this is for the additional RENAME, that could drop columns
int prevCols = previousColumns.size() - (Integer) commandDescription.context().get("nKeys");

if (previousColumns.stream().anyMatch(x -> x.name().equals("<all-fields-projected>"))) {
// known bug https://github.com/elastic/elasticsearch/issues/121741
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ValidationResult validateOutput(
if (commandDescription == EMPTY_DESCRIPTION) {
return VALIDATION_OK;
}
return CommandGenerator.expectSameColumns(previousColumns, columns);
return CommandGenerator.expectSameColumns(previousCommands, previousColumns, columns);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public ValidationResult validateOutput(
List<Column> columns,
List<List<Object>> output
) {
return CommandGenerator.expectSameColumns(previousColumns, columns);
return CommandGenerator.expectSameColumns(previousCommands, previousColumns, columns);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public ValidationResult validateOutput(
List<Column> columns,
List<List<Object>> output
) {
return CommandGenerator.expectSameColumns(previousColumns, columns);
return CommandGenerator.expectSameColumns(previousCommands, previousColumns, columns);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public ValidationResult validateOutput(
List<Column> columns,
List<List<Object>> output
) {
return CommandGenerator.expectSameColumns(previousColumns, columns);
return CommandGenerator.expectSameColumns(previousCommands, previousColumns, columns);
}
}