Skip to content

Commit 89e4b59

Browse files
authored
Fix query builder rewriting when using lookup join (#123498)
1 parent ff93aa3 commit 89e4b59

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
_id:keyword,semantic_text_field:semantic_text,st_bool:semantic_text,st_cartesian_point:semantic_text,st_cartesian_shape:semantic_text,st_datetime:semantic_text,st_double:semantic_text,st_geopoint:semantic_text,st_geoshape:semantic_text,st_integer:semantic_text,st_ip:semantic_text,st_long:semantic_text,st_unsigned_long:semantic_text,st_version:semantic_text,st_multi_value:semantic_text,st_unicode:semantic_text,host:keyword,description:text,value:long,st_base64:semantic_text,st_logs:semantic_text
2-
1,live long and prosper,false,"POINT(4297.11 -1475.53)",,1953-09-02T00:00:00.000Z,5.20128E11,"POINT(42.97109630194 14.7552534413725)","POLYGON ((30 10\, 40 40\, 20 40\, 10 20\, 30 10))",23,1.1.1.1,2147483648,2147483648,1.2.3,["Hello there!", "This is a random value", "for testing purposes"],你吃饭了吗,"host1","some description1",1001,ZWxhc3RpYw==,"2024-12-23T12:15:00.000Z 1.2.3.4 [email protected] 4553"
3-
2,all we have to decide is what to do with the time that is given to us,true,"POINT(7580.93 2272.77)",,2023-09-24T15:57:00.000Z,4541.11,"POINT(37.97109630194 21.7552534413725)","POLYGON ((30 10\, 40 40\, 20 40\, 10 20\, 30 10))",122,1.1.2.1,123,2147483648.2,9.0.0,["nice to meet you", "bye bye!"],["谢谢", "对不起我的中文不好"],"host2","some description2",1002,aGVsbG8=,"2024-01-23T12:15:00.000Z 1.2.3.4 [email protected] 42"
4-
3,be excellent to each other,,,,,,,,,,,,,,,"host3","some description3",1003,,"2023-01-23T12:15:00.000Z 127.0.0.1 [email protected] 42"
1+
_id:keyword,semantic_text_field:semantic_text,st_bool:semantic_text,st_cartesian_point:semantic_text,st_cartesian_shape:semantic_text,st_datetime:semantic_text,st_double:semantic_text,st_geopoint:semantic_text,st_geoshape:semantic_text,st_integer:semantic_text,st_ip:semantic_text,st_long:semantic_text,st_unsigned_long:semantic_text,st_version:semantic_text,st_multi_value:semantic_text,st_unicode:semantic_text,host:keyword,description:text,value:long,st_base64:semantic_text,st_logs:semantic_text,language_name:keyword
2+
1,live long and prosper,false,"POINT(4297.11 -1475.53)",,1953-09-02T00:00:00.000Z,5.20128E11,"POINT(42.97109630194 14.7552534413725)","POLYGON ((30 10\, 40 40\, 20 40\, 10 20\, 30 10))",23,1.1.1.1,2147483648,2147483648,1.2.3,["Hello there!", "This is a random value", "for testing purposes"],你吃饭了吗,"host1","some description1",1001,ZWxhc3RpYw==,"2024-12-23T12:15:00.000Z 1.2.3.4 [email protected] 4553",English
3+
2,all we have to decide is what to do with the time that is given to us,true,"POINT(7580.93 2272.77)",,2023-09-24T15:57:00.000Z,4541.11,"POINT(37.97109630194 21.7552534413725)","POLYGON ((30 10\, 40 40\, 20 40\, 10 20\, 30 10))",122,1.1.2.1,123,2147483648.2,9.0.0,["nice to meet you", "bye bye!"],["谢谢", "对不起我的中文不好"],"host2","some description2",1002,aGVsbG8=,"2024-01-23T12:15:00.000Z 1.2.3.4 [email protected] 42",French
4+
3,be excellent to each other,,,,,,,,,,,,,,,"host3","some description3",1003,,"2023-01-23T12:15:00.000Z 127.0.0.1 [email protected] 42",Spanish

x-pack/plugin/esql/qa/testFixtures/src/main/resources/mapping-semantic_text.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
"st_logs": {
7777
"type": "semantic_text",
7878
"inference_id": "test_sparse_inference"
79+
},
80+
"language_name": {
81+
"type": "keyword"
7982
}
8083
}
8184
}

x-pack/plugin/esql/qa/testFixtures/src/main/resources/match-operator.csv-spec

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,39 @@ book_no:keyword
721721
7140
722722
2714
723723
;
724+
725+
testMatchWithSemanticTextAndLookupJoin
726+
required_capability: match_operator_colon
727+
required_capability: semantic_text_field_caps
728+
required_capability: join_lookup_v12
729+
730+
from semantic_text METADATA _id
731+
| where semantic_text_field:"something"
732+
| LOOKUP JOIN languages_lookup ON language_name
733+
| KEEP _id, language_name, language_code
734+
;
735+
736+
ignoreOrder: true
737+
738+
_id:keyword | language_name:keyword | language_code:integer
739+
1 | English | 1
740+
2 | French | 2
741+
3 | Spanish | 3
742+
;
743+
744+
testMatchWithSemanticTextKqlAndLookupJoin
745+
required_capability: match_operator_colon
746+
required_capability: semantic_text_type
747+
required_capability: kql_function
748+
required_capability: semantic_text_field_caps
749+
required_capability: join_lookup_v12
750+
751+
from semantic_text
752+
| where kql("host:host1") AND semantic_text_field:"something"
753+
| LOOKUP JOIN languages_lookup ON language_name
754+
| KEEP host, semantic_text_field, language_name, language_code
755+
;
756+
757+
host:keyword | semantic_text_field:text | language_name:keyword | language_code:integer
758+
"host1" | live long and prosper | English | 1
759+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/QueryBuilderResolver.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.elasticsearch.index.query.Rewriteable;
1717
import org.elasticsearch.search.SearchService;
1818
import org.elasticsearch.transport.TransportService;
19-
import org.elasticsearch.xpack.esql.core.util.Holder;
2019
import org.elasticsearch.xpack.esql.expression.function.fulltext.FullTextFunction;
2120
import org.elasticsearch.xpack.esql.plan.logical.EsRelation;
2221
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
@@ -98,9 +97,9 @@ private Set<FullTextFunction> fullTextFunctions(LogicalPlan plan) {
9897
}
9998

10099
public Set<String> indexNames(LogicalPlan plan) {
101-
Holder<Set<String>> indexNames = new Holder<>();
102-
plan.forEachDown(EsRelation.class, esRelation -> indexNames.set(esRelation.concreteIndices()));
103-
return indexNames.get();
100+
Set<String> indexNames = new HashSet<>();
101+
plan.forEachDown(EsRelation.class, esRelation -> indexNames.addAll(esRelation.concreteIndices()));
102+
return indexNames;
104103
}
105104

106105
public LogicalPlan planWithResolvedQueryBuilders(LogicalPlan plan, Map<FullTextFunction, QueryBuilder> newQueryBuilders) {

0 commit comments

Comments
 (0)