Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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 @@ -163,6 +163,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 @@ -176,7 +185,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 @@ -732,6 +732,28 @@ language.id:integer | language.name:text | language.name.keyword:keyword | langu
2 | French | French | FR
;

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

joinOnMultiTypedMatchFieldCastToInteger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding tests for multi-typed numeric fields as join keys. We still have gaps in test coverage for multi-typed join keys involving string types (keyword, text, ip) and date types (millis, nanos). If these are not within the scope of this PR, they should be covered in a separate one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a more complete list of tests to LookupJoinTypesIT. It's still not exhaustive but IMO covers enough ground for now.

That required a bit of refactoring ^^

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 @@ -54,6 +54,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 @@ -229,7 +230,7 @@ private void runLookup(DataType keyType, PopulateIndices populateIndices) throws
keyType,
"lookup",
"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