Skip to content

Commit bc8ea7c

Browse files
authored
ESQL: Fix some more usages of field attribute names in LOOKUP JOIN (#129355) (#129579)
* Add a test that demonstrates that LOOKUP JOIN works with union types. * Fix usage of FieldAttribute#name where we should use FieldAttribute#fieldName in LOOKUP JOIN. * Refactor LookupJoinTypesIT This doesn't fix any bugs per se, but will avoid bwc problems once we propagate union type field attributes into Join LogicalPlan nodes. (cherry picked from commit 65cbccc) # Conflicts: # x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/LookupFromIndexIT.java # x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/LookupJoinTypesIT.java # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java
1 parent 75c3728 commit bc8ea7c

File tree

9 files changed

+364
-155
lines changed

9 files changed

+364
-155
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/FieldAttribute.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
*
3535
* To adequately represent e.g. union types, the name of the attribute can be altered because we may have multiple synthetic field
3636
* attributes that really belong to the same underlying field. For instance, if a multi-typed field is used both as {@code field::string}
37-
* and {@code field::ip}, we'll generate 2 field attributes called {@code $$field$converted_to$string} and {@code $$field$converted_to$ip}
38-
* but still referring to the same underlying field.
37+
* and {@code field::ip}, we'll generate 2 field attributes called {@code $$field$converted_to$keyword} and {@code $$field$converted_to$ip}
38+
* which still refer to the same underlying index field.
3939
*/
4040
public class FieldAttribute extends TypedAttribute {
4141

@@ -211,6 +211,15 @@ public FieldName fieldName() {
211211
return lazyFieldName;
212212
}
213213

214+
/**
215+
* The name of the attribute. Can deviate from the field name e.g. in case of union types. For the physical field name, use
216+
* {@link FieldAttribute#fieldName()}.
217+
*/
218+
@Override
219+
public String name() {
220+
return super.name();
221+
}
222+
214223
public EsField.Exact getExactInfo() {
215224
return field.getExactInfo();
216225
}
@@ -224,7 +233,7 @@ public FieldAttribute exactAttribute() {
224233
}
225234

226235
private FieldAttribute innerField(EsField type) {
227-
return new FieldAttribute(source(), name(), name() + "." + type.getName(), type, nullable(), id(), synthetic());
236+
return new FieldAttribute(source(), fieldName().string, name() + "." + type.getName(), type, nullable(), id(), synthetic());
228237
}
229238

230239
@Override

x-pack/plugin/esql/qa/testFixtures/src/main/resources/lookup-join.csv-spec

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,28 @@ language.id:integer | language.name:text | language.name.keyword:keyword | langu
648648
2 | French | French | FR
649649
;
650650

651+
###############################################
652+
# union type behavior
653+
###############################################
654+
655+
joinOnMultiTypedMatchFieldCastToInteger
656+
required_capability: join_lookup_v12
657+
658+
FROM apps, apps_short METADATA _index
659+
| EVAL language_code = id::integer
660+
| KEEP _index, language_code
661+
| WHERE language_code < 3
662+
| LOOKUP JOIN languages_lookup ON language_code
663+
| SORT _index ASC, language_code ASC
664+
;
665+
666+
_index:keyword | language_code:integer | language_name:keyword
667+
apps | 1 | English
668+
apps | 2 | French
669+
apps_short | 1 | English
670+
apps_short | 2 | French
671+
;
672+
651673
###############################################
652674
# Tests with clientips_lookup index
653675
###############################################

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/LookupFromIndexIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.elasticsearch.threadpool.ThreadPool;
4848
import org.elasticsearch.xpack.core.async.AsyncExecutionId;
4949
import org.elasticsearch.xpack.esql.core.expression.Alias;
50+
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
5051
import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute;
5152
import org.elasticsearch.xpack.esql.core.tree.Source;
5253
import org.elasticsearch.xpack.esql.core.type.DataType;
@@ -220,7 +221,7 @@ private void runLookup(DataType keyType, PopulateIndices populateIndices) throws
220221
ctx -> internalCluster().getInstance(TransportEsqlQueryAction.class, finalNodeWithShard).getLookupFromIndexService(),
221222
keyType,
222223
"lookup",
223-
"key",
224+
new FieldAttribute.FieldName("key"),
224225
List.of(new Alias(Source.EMPTY, "l", new ReferenceAttribute(Source.EMPTY, "l", DataType.LONG))),
225226
Source.EMPTY
226227
);

0 commit comments

Comments
 (0)