Skip to content

[9.0] ESQL: Fix some more usages of field attribute names in LOOKUP JOIN (#129355) #129577

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

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
*
* To adequately represent e.g. union types, the name of the attribute can be altered because we may have multiple synthetic field
* attributes that really belong to the same underlying field. For instance, if a multi-typed field is used both as {@code field::string}
* and {@code field::ip}, we'll generate 2 field attributes called {@code $$field$converted_to$string} and {@code $$field$converted_to$ip}
* but still referring to the same underlying field.
* and {@code field::ip}, we'll generate 2 field attributes called {@code $$field$converted_to$keyword} and {@code $$field$converted_to$ip}
* which still refer to the same underlying index field.
*/
public class FieldAttribute extends TypedAttribute {

Expand Down Expand Up @@ -211,6 +211,15 @@ public FieldName fieldName() {
return lazyFieldName;
}

/**
* The name of the attribute. Can deviate from the field name e.g. in case of union types. For the physical field name, use
* {@link FieldAttribute#fieldName()}.
*/
@Override
public String name() {
return super.name();
}

public EsField.Exact getExactInfo() {
return field.getExactInfo();
}
Expand All @@ -224,7 +233,7 @@ public FieldAttribute exactAttribute() {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,28 @@ language.id:integer | language.name:text | language.name.keyword:keyword | langu
2 | French | French | FR
;

###############################################
# union type behavior
###############################################

joinOnMultiTypedMatchFieldCastToInteger
required_capability: join_lookup_v12

FROM apps, apps_short METADATA _index
| EVAL language_code = id::integer
| KEEP _index, language_code
| WHERE language_code < 3
| LOOKUP JOIN languages_lookup ON language_code
| SORT _index ASC, language_code ASC
;

_index:keyword | language_code:integer | language_name:keyword
apps | 1 | English
apps | 2 | French
apps_short | 1 | English
apps_short | 2 | French
;

###############################################
# Tests with clientips_lookup index
###############################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.async.AsyncExecutionId;
import org.elasticsearch.xpack.esql.core.expression.Alias;
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
Expand Down Expand Up @@ -221,7 +222,7 @@ private void runLookup(DataType keyType, PopulateIndices populateIndices) throws
ctx -> internalCluster().getInstance(TransportEsqlQueryAction.class, finalNodeWithShard).getLookupFromIndexService(),
keyType,
"lookup",
"key",
new FieldAttribute.FieldName("key"),
List.of(new Alias(Source.EMPTY, "l", new ReferenceAttribute(Source.EMPTY, "l", DataType.LONG))),
Source.EMPTY
);
Expand Down
Loading