Skip to content

Commit af26d5f

Browse files
committed
More code review fixes
1 parent 5c2c7d7 commit af26d5f

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestUtils.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ public static Tuple<Version, Version> skipVersionRange(String testName, String i
120120
return null;
121121
}
122122

123-
public record PageColumn(String name, DataType dataType) {}
124-
125-
public static Tuple<Page, List<PageColumn>> loadPageFromCsv(URL source, Map<String, String> typeMapping) throws Exception {
123+
public static Tuple<Page, List<String>> loadPageFromCsv(URL source, Map<String, String> typeMapping) throws Exception {
126124

127125
record CsvColumn(String name, Type type, BuilderWrapper builderWrapper) implements Releasable {
128126
void append(String stringValue) {
@@ -232,10 +230,10 @@ public void close() {
232230
lineNumber++;
233231
}
234232
}
235-
var pageColumns = new ArrayList<PageColumn>(columns.length);
233+
var pageColumns = new ArrayList<String>(columns.length);
236234
try {
237235
var blocks = Arrays.stream(columns)
238-
.peek(b -> pageColumns.add(new PageColumn(b.name, DataType.fromTypeName(b.type.name()))))
236+
.peek(b -> pageColumns.add(b.name))
239237
.map(b -> b.builderWrapper.builder().build())
240238
.toArray(Block[]::new);
241239
return new Tuple<>(new Page(blocks), pageColumns);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,13 @@ private List<Attribute> resolveUsingColumns(List<Attribute> cols, List<Attribute
669669
List<Attribute> resolved = new ArrayList<>(cols.size());
670670
for (Attribute col : cols) {
671671
if (col instanceof UnresolvedAttribute ua) {
672-
Attribute resolvedCol = maybeResolveAttribute(ua, output);
673-
if (resolvedCol instanceof UnresolvedAttribute ucol) {
672+
Attribute resolvedField = maybeResolveAttribute(ua, output);
673+
if (resolvedField instanceof UnresolvedAttribute ucol) {
674674
String message = ua.unresolvedMessage();
675675
String match = "column [" + ucol.name() + "]";
676-
resolvedCol = ucol.withUnresolvedMessage(message.replace(match, match + " in " + side + " side of join"));
676+
resolvedField = ucol.withUnresolvedMessage(message.replace(match, match + " in " + side + " side of join"));
677677
}
678-
resolved.add(resolvedCol);
678+
resolved.add(resolvedField);
679679
} else {
680680
throw new IllegalStateException(
681681
"Surprised to discover column [ " + col.name() + "] already resolved when resolving JOIN keys"
@@ -686,16 +686,16 @@ private List<Attribute> resolveUsingColumns(List<Attribute> cols, List<Attribute
686686
}
687687

688688
private LogicalPlan resolveInsist(Insist insist, List<Attribute> childrenOutput, IndexResolution indexResolution) {
689-
Attribute resolvedCol = maybeResolveAttribute(insist.getInsistIdentifier(), childrenOutput);
689+
Attribute resolvedCol = maybeResolveAttribute(insist.attribute(), childrenOutput);
690690
// Field isn't mapped anywhere.
691691
if (resolvedCol instanceof UnresolvedAttribute) {
692-
return pushdownInsist(insist, attrs -> attrs.add(insistKeyword(insist)));
692+
return mergeInsist(insist, attrs -> attrs.add(insistKeyword(insist)));
693693
}
694694

695695
String name = resolvedCol.name();
696696
// Field is partially unmapped.
697-
if (resolvedCol instanceof FieldAttribute f && indexResolution.get().partiallyUnmappedFields().contains(name)) {
698-
return pushdownInsist(insist, attrs -> {
697+
if (resolvedCol instanceof FieldAttribute f && indexResolution.get().isPartiallyUnmappedField(name)) {
698+
return mergeInsist(insist, attrs -> {
699699
var index = CollectionUtils.findFirstIndex(attrs, e -> e.name().equals(name)).getAsInt();
700700
Attribute attribute = f.field().getDataType() == KEYWORD ? insistKeyword(insist) : invalidInsistAttribute(insist, f);
701701
attrs.set(index, attribute);
@@ -706,7 +706,8 @@ private LogicalPlan resolveInsist(Insist insist, List<Attribute> childrenOutput,
706706
return insist.child();
707707
}
708708

709-
private static EsRelation pushdownInsist(Insist insist, Consumer<List<Attribute>> updateAttributes) {
709+
private static EsRelation mergeInsist(Insist insist, Consumer<List<Attribute>> updateAttributes) {
710+
assert insist.child() instanceof EsRelation : "INSIST should be on top of a relation (see LogicalPlanBuilder)";
710711
var relation = (EsRelation) insist.child();
711712
List<Attribute> newOutput = new ArrayList<>(relation.output());
712713
updateAttributes.accept(newOutput);
@@ -722,7 +723,7 @@ private static UnsupportedAttribute invalidInsistAttribute(Insist insist, FieldA
722723
}
723724

724725
private static FieldAttribute insistKeyword(Insist insist) {
725-
String name = insist.getInsistIdentifier().name();
726+
String name = insist.attribute().name();
726727
return new FieldAttribute(insist.source(), name, new PotentiallyUnmappedKeywordEsField(name));
727728
}
728729

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/index/EsIndex.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.index.IndexMode;
1414
import org.elasticsearch.xpack.esql.core.type.EsField;
1515

16+
import java.beans.Transient;
1617
import java.io.IOException;
1718
import java.util.Map;
1819
import java.util.Set;
@@ -24,7 +25,7 @@ public record EsIndex(
2425
Map<String, EsField> mapping,
2526
Map<String, IndexMode> indexNameWithModes,
2627
/** Fields mapped only in some (but *not* all) indices. Since this is only used by the analyzer, it is not serialized. */
27-
Set<String> partiallyUnmappedFields
28+
@Transient Set<String> partiallyUnmappedFields
2829
) implements Writeable {
2930

3031
public EsIndex {
@@ -81,6 +82,10 @@ public void writeTo(StreamOutput out) throws IOException {
8182
// partially unmapped fields shouldn't pass the coordinator node anyway, since they are only used by the Analyzer.
8283
}
8384

85+
public boolean isPartiallyUnmappedField(String fieldName) {
86+
return partiallyUnmappedFields.contains(fieldName);
87+
}
88+
8489
public Set<String> concreteIndices() {
8590
return indexNameWithModes.keySet();
8691
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
import java.util.Objects;
2020

2121
public class Insist extends UnaryPlan {
22-
private final UnresolvedAttribute insistIdentifier;
22+
private final UnresolvedAttribute insistedAttribute;
2323

24-
public Insist(Source source, UnresolvedAttribute insistIdentifier, LogicalPlan child) {
24+
public Insist(Source source, UnresolvedAttribute insistedAttribute, LogicalPlan child) {
2525
super(source, child);
26-
this.insistIdentifier = insistIdentifier;
26+
this.insistedAttribute = insistedAttribute;
2727
}
2828

2929
private @Nullable List<Attribute> lazyOutput = null;
@@ -38,27 +38,27 @@ public List<Attribute> output() {
3838

3939
private List<Attribute> computeOutput() {
4040
var result = new ArrayList<>(child().output());
41-
result.add(insistIdentifier);
41+
result.add(insistedAttribute);
4242
return result;
4343
}
4444

45-
public UnresolvedAttribute getInsistIdentifier() {
46-
return insistIdentifier;
45+
public UnresolvedAttribute attribute() {
46+
return insistedAttribute;
4747
}
4848

4949
@Override
5050
public Insist replaceChild(LogicalPlan newChild) {
51-
return new Insist(source(), insistIdentifier, newChild);
51+
return new Insist(source(), insistedAttribute, newChild);
5252
}
5353

5454
@Override
5555
public boolean expressionsResolved() {
56-
return computeOutput().stream().allMatch(Attribute::resolved);
56+
return insistedAttribute.resolved();
5757
}
5858

5959
@Override
6060
protected NodeInfo<? extends LogicalPlan> info() {
61-
return NodeInfo.create(this, Insist::new, insistIdentifier, child());
61+
return NodeInfo.create(this, Insist::new, insistedAttribute, child());
6262
}
6363

6464
@Override
@@ -73,11 +73,11 @@ public String getWriteableName() {
7373

7474
@Override
7575
public int hashCode() {
76-
return Objects.hash(super.hashCode(), Objects.hashCode(insistIdentifier));
76+
return Objects.hash(super.hashCode(), Objects.hashCode(insistedAttribute));
7777
}
7878

7979
@Override
8080
public boolean equals(Object obj) {
81-
return super.equals(obj) && ((Insist) obj).insistIdentifier.equals(insistIdentifier);
81+
return super.equals(obj) && ((Insist) obj).insistedAttribute.equals(insistedAttribute);
8282
}
8383
}

0 commit comments

Comments
 (0)