- Notifications
You must be signed in to change notification settings - Fork 25.6k
ES|QL: Fix wrong pruning of plans with no output columns #133405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ad961ae 21dc299 de95b79 42d364f 544d6dd c2f01d6 ba01afe 764cace 642b50a 3ae2314 e09cabd a1aaa5b 0421de5 34b995a 2e35ab3 be75856 657c94e a3cccde dd74c0b afd0350 b45fc9a b42b09a 3a388a7 076db41 b0a9d02 130fa2e c0ac934 710fdcc edc3890 d2a5631 921ecb8 59207cb bb45498 d059447 f8ca703 e9ebf8b File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 133405 | ||
| summary: Fix wrong pruning of plans with no output columns | ||
| area: ES|QL | ||
| type: bug | ||
| issues: [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 9186000 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| initial_9.2.0,9185000 | ||
| esql_plan_with_no_columns,9186000 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| | ||
| package org.elasticsearch.xpack.esql.generator.command.pipe; | ||
| | ||
| import org.elasticsearch.xpack.esql.generator.Column; | ||
| import org.elasticsearch.xpack.esql.generator.EsqlQueryGenerator; | ||
| import org.elasticsearch.xpack.esql.generator.QueryExecutor; | ||
| import org.elasticsearch.xpack.esql.generator.command.CommandGenerator; | ||
| | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| | ||
| public class DropAllGenerator implements CommandGenerator { | ||
| | ||
| public static final String DROP_ALL = "drop_all"; | ||
| public static final String DROPPED_COLUMNS = "dropped_columns"; | ||
| | ||
| public static final CommandGenerator INSTANCE = new DropAllGenerator(); | ||
| | ||
| @Override | ||
| public CommandDescription generate( | ||
| List<CommandDescription> previousCommands, | ||
| List<Column> previousOutput, | ||
| QuerySchema schema, | ||
| QueryExecutor executor | ||
| ) { | ||
| Set<String> droppedColumns = new HashSet<>(); | ||
| String name = EsqlQueryGenerator.randomStringField(previousOutput); | ||
| if (name == null || name.isEmpty()) { | ||
| return CommandGenerator.EMPTY_DESCRIPTION; | ||
| } | ||
| | ||
| String cmdString = " | keep " + name + " | drop " + name; | ||
| return new CommandDescription(DROP_ALL, this, cmdString, Map.ofEntries(Map.entry(DROPPED_COLUMNS, droppedColumns))); | ||
| } | ||
| | ||
| @Override | ||
| @SuppressWarnings("unchecked") | ||
| public ValidationResult validateOutput( | ||
| List<CommandDescription> previousCommands, | ||
| CommandDescription commandDescription, | ||
| List<Column> previousColumns, | ||
| List<List<Object>> previousOutput, | ||
| List<Column> columns, | ||
| List<List<Object>> output | ||
| ) { | ||
| if (commandDescription == EMPTY_DESCRIPTION) { | ||
| return VALIDATION_OK; | ||
| } | ||
| | ||
| if (columns.size() > 0) { | ||
| return new ValidationResult( | ||
| false, | ||
| "Expecting no columns, got [" + columns.stream().map(Column::name).collect(Collectors.joining(", ")) + "]" | ||
| ); | ||
| } | ||
| | ||
| return VALIDATION_OK; | ||
| } | ||
| | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -12,6 +12,7 @@ | |
| import org.elasticsearch.common.lucene.BytesRefs; | ||
| import org.elasticsearch.compute.data.AggregateMetricDoubleBlockBuilder; | ||
| import org.elasticsearch.compute.data.Block; | ||
| import org.elasticsearch.compute.data.Page; | ||
| import org.elasticsearch.core.Strings; | ||
| import org.elasticsearch.index.IndexMode; | ||
| import org.elasticsearch.logging.Logger; | ||
| | @@ -472,7 +473,7 @@ private LocalRelation tableMapAsRelation(Source source, Map<String, Column> mapT | |
| // prepare the block for the supplier | ||
| blocks[i++] = column.values(); | ||
| } | ||
| LocalSupplier supplier = LocalSupplier.of(blocks); | ||
| LocalSupplier supplier = LocalSupplier.of(blocks.length > 0 ? new Page(blocks) : new Page(0)); | ||
| Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering if we could integrate the logic "if the blocks size is 0 then Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want this in general, in some cases we want no blocks but | ||
| return new LocalRelation(source, attributes, supplier); | ||
| } | ||
| } | ||
| | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it!