Skip to content

Commit e9ebf8b

Browse files
Implement suggestions
1 parent f8ca703 commit e9ebf8b

File tree

4 files changed

+369
-613
lines changed

4 files changed

+369
-613
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PruneEmptyAggregates.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515

1616
import java.util.List;
1717

18+
/**
19+
* STATS with no aggregates and no groupings can be replaced with a single, empty row.
20+
* This can happen due to expression pruning at optimization time, after all them are dropped,
21+
* eg.
22+
*
23+
* STATS a = count(*) by b | drop a, b
24+
*/
1825
public final class PruneEmptyAggregates extends OptimizerRules.OptimizerRule<Aggregate> {
1926
@Override
2027
protected LogicalPlan rule(Aggregate agg) {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/local/CopyingLocalSupplier.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
import java.io.IOException;
2121

2222
/**
23-
* A {@link LocalSupplier} that allways creates a new copy of the {@link Block}s initially provided at creation time.
23+
* A {@link LocalSupplier} that allways creates a new copy of the {@link Page} initially provided at creation time.
2424
* This is created specifically for {@link InlineStats} usage in {@link EsqlSession} for queries that use ROW command.
2525
*
26-
* The ROW which gets replaced by {@link ReplaceRowAsLocalRelation} with a {@link LocalRelation} will have its blocks
26+
* The ROW which gets replaced by {@link ReplaceRowAsLocalRelation} with a {@link LocalRelation} will have its page
2727
* used (and released) at least twice:
2828
* - the {@link LocalRelation} from the left-hand side is used as a source for the right-hand side
2929
* - the same {@link LocalRelation} is then used to continue the execution of the query on the left-hand side
3030
*
3131
* It delegates all its operations to {@link ImmediateLocalSupplier} and, to prevent the double release, it will always
32-
* create a deep copy of the blocks received in the constructor initially.
32+
* create a deep copy of the page received in the constructor initially.
3333
*
34-
* Example with the flow and the blocks reuse for a query like "row x = 1 | inline stats y = max(x)"
34+
* Example with the flow and the page reuse for a query like "row x = 1 | inline stats y = max(x)"
3535
* Step 1:
3636
* Limit[1000[INTEGER],true]
3737
* \_InlineJoin[LEFT,[],[],[]]

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/FieldNameUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, boolean ha
244244
// there cannot be an empty list of fields, we'll ask the simplest and lightest one instead: _index
245245
return new PreAnalysisResult(IndexResolver.INDEX_METADATA_FIELD, wildcardJoinIndices);
246246
} else {
247-
fieldNames.add(MetadataAttribute.INDEX);
248-
return new PreAnalysisResult(fieldNames.stream().flatMap(FieldNameUtils::withSubfields).collect(toSet()), wildcardJoinIndices);
247+
HashSet<String> allFields = new HashSet<>(fieldNames.stream().flatMap(FieldNameUtils::withSubfields).collect(toSet()));
248+
allFields.add(MetadataAttribute.INDEX);
249+
return new PreAnalysisResult(allFields, wildcardJoinIndices);
249250
}
250251
}
251252

0 commit comments

Comments
 (0)