Skip to content

Commit 87aac2b

Browse files
committed
Adapt approach for missing AttributeSetBuilder
Builder is only available on main/9.x, so we have to correctly use the immutable AttributeSets directly.
1 parent f08bdba commit 87aac2b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/physical/ProjectAwayColumns.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ public PhysicalPlan apply(PhysicalPlan plan) {
6262
for (Attribute attribute : logicalFragment.output()) {
6363
if (requiredAttributes.get().contains(attribute)) {
6464
output.add(attribute);
65-
requiredAttributes.get().remove(attribute);
6665
}
6766
}
68-
// requiredAttrBuilder should be empty unless the plan is inconsistent due to a bug.
69-
// This can happen in case of remote ENRICH, see https://github.com/elastic/elasticsearch/issues/118531
67+
// requiredAttributes should only have attributes that are also in the fragment's output.
68+
// This assumption can be wrong in case of remote ENRICH, see https://github.com/elastic/elasticsearch/issues/118531
7069
// TODO: stop adding the remaining required attributes once remote ENRICH is fixed.
71-
output.addAll(requiredAttributes.get());
70+
if (output.size() != requiredAttributes.get().size()) {
71+
AttributeSet alreadyAdded = AttributeSet.of(output);
72+
AttributeSet remaining = requiredAttributes.get().subtract(alreadyAdded);
73+
output.addAll(remaining);
74+
}
7275

7376
// if all the fields are filtered out, it's only the count that matters
7477
// however until a proper fix (see https://github.com/elastic/elasticsearch/issues/98703)

0 commit comments

Comments
 (0)