Skip to content

Commit 214beed

Browse files
committed
QL: move query AST from SQL to QL (#52069)
(cherry picked from commit 5936896)
1 parent 9f541d9 commit 214beed

29 files changed

+92
-76
lines changed

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/BoolQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/BoolQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.BoolQueryBuilder;
99
import org.elasticsearch.index.query.QueryBuilder;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/ExistsQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/ExistsQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.QueryBuilder;
99
import org.elasticsearch.xpack.ql.tree.Source;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/GeoDistanceQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/GeoDistanceQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.common.unit.DistanceUnit;
99
import org.elasticsearch.index.query.QueryBuilder;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/LeafQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/LeafQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.search.sort.NestedSortBuilder;
99
import org.elasticsearch.xpack.ql.tree.Source;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchAll.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MatchAll.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.QueryBuilder;
99
import org.elasticsearch.xpack.ql.tree.Source;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MatchQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.common.Booleans;
99
import org.elasticsearch.common.unit.Fuzziness;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MultiMatchQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.common.Booleans;
99
import org.elasticsearch.common.unit.Fuzziness;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/NestedQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/NestedQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.apache.lucene.search.join.ScoreMode;
99
import org.elasticsearch.index.query.InnerHitBuilder;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/NotQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/NotQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.QueryBuilder;
99
import org.elasticsearch.search.sort.NestedSortBuilder;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/Query.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/Query.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.QueryBuilder;
99
import org.elasticsearch.search.sort.NestedSortBuilder;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/QueryStringQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/QueryStringQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.common.Booleans;
99
import org.elasticsearch.common.unit.Fuzziness;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/RangeQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/RangeQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.common.Strings;
99
import org.elasticsearch.index.query.QueryBuilder;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/RegexQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/RegexQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.QueryBuilder;
99
import org.elasticsearch.xpack.ql.tree.Source;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/ScriptQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/ScriptQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.QueryBuilder;
99
import org.elasticsearch.xpack.ql.expression.gen.script.ScriptTemplate;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/TermQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.QueryBuilder;
99
import org.elasticsearch.xpack.ql.tree.Source;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/TermsQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermsQuery.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,11 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.QueryBuilder;
9-
import org.elasticsearch.xpack.ql.expression.Expression;
109
import org.elasticsearch.xpack.ql.tree.Source;
11-
import org.elasticsearch.xpack.ql.type.DataTypes;
12-
import org.elasticsearch.xpack.sql.expression.Foldables;
1310

14-
import java.util.Collections;
15-
import java.util.LinkedHashSet;
16-
import java.util.List;
1711
import java.util.Objects;
1812
import java.util.Set;
1913

@@ -24,15 +18,10 @@ public class TermsQuery extends LeafQuery {
2418
private final String term;
2519
private final Set<Object> values;
2620

27-
public TermsQuery(Source source, String term, List<Expression> values) {
21+
public TermsQuery(Source source, String term, Set<Object> values) {
2822
super(source);
2923
this.term = term;
30-
values.removeIf(e -> DataTypes.isNull(e.dataType()));
31-
if (values.isEmpty()) {
32-
this.values = Collections.emptySet();
33-
} else {
34-
this.values = new LinkedHashSet<>(Foldables.valuesOf(values, values.get(0).dataType()));
35-
}
24+
this.values = values;
3625
}
3726

3827
@Override
@@ -64,4 +53,4 @@ public boolean equals(Object obj) {
6453
protected String innerToString() {
6554
return term + ":" + values;
6655
}
67-
}
56+
}

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/WildcardQuery.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/WildcardQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.QueryBuilder;
99
import org.elasticsearch.xpack.ql.tree.Source;

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/BoolQueryTests.java renamed to x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/BoolQueryTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.search.sort.NestedSortBuilder;
99
import org.elasticsearch.test.ESTestCase;
10+
import org.elasticsearch.xpack.ql.querydsl.query.BoolQuery;
11+
import org.elasticsearch.xpack.ql.querydsl.query.ExistsQuery;
12+
import org.elasticsearch.xpack.ql.querydsl.query.MatchAll;
13+
import org.elasticsearch.xpack.ql.querydsl.query.NestedQuery;
14+
import org.elasticsearch.xpack.ql.querydsl.query.Query;
1015
import org.elasticsearch.xpack.ql.tree.Source;
1116
import org.elasticsearch.xpack.ql.tree.SourceTests;
1217
import org.elasticsearch.xpack.ql.util.StringUtils;

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/LeafQueryTests.java renamed to x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/LeafQueryTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.QueryBuilder;
99
import org.elasticsearch.search.sort.NestedSortBuilder;
1010
import org.elasticsearch.test.ESTestCase;
11+
import org.elasticsearch.xpack.ql.querydsl.query.LeafQuery;
12+
import org.elasticsearch.xpack.ql.querydsl.query.Query;
1113
import org.elasticsearch.xpack.ql.tree.Source;
1214
import org.elasticsearch.xpack.ql.tree.SourceTests;
1315
import org.elasticsearch.xpack.ql.util.StringUtils;

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQueryTests.java renamed to x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/MatchQueryTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.index.query.MatchQueryBuilder;
99
import org.elasticsearch.index.query.Operator;
1010
import org.elasticsearch.test.ESTestCase;
1111
import org.elasticsearch.xpack.ql.expression.FieldAttribute;
1212
import org.elasticsearch.xpack.ql.expression.predicate.fulltext.MatchQueryPredicate;
13+
import org.elasticsearch.xpack.ql.querydsl.query.MatchQuery;
1314
import org.elasticsearch.xpack.ql.tree.Source;
1415
import org.elasticsearch.xpack.ql.tree.SourceTests;
1516
import org.elasticsearch.xpack.ql.type.EsField;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.ElasticsearchParseException;
99
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
1010
import org.elasticsearch.test.ESTestCase;
1111
import org.elasticsearch.xpack.ql.expression.predicate.fulltext.MultiMatchQueryPredicate;
12+
import org.elasticsearch.xpack.ql.querydsl.query.MultiMatchQuery;
1213
import org.elasticsearch.xpack.ql.tree.Source;
1314
import org.elasticsearch.xpack.ql.util.StringUtils;
1415

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/NestedQueryTests.java renamed to x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/NestedQueryTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.search.sort.NestedSortBuilder;
99
import org.elasticsearch.test.ESTestCase;
10+
import org.elasticsearch.xpack.ql.querydsl.query.MatchAll;
11+
import org.elasticsearch.xpack.ql.querydsl.query.NestedQuery;
12+
import org.elasticsearch.xpack.ql.querydsl.query.Query;
1013
import org.elasticsearch.xpack.ql.tree.Source;
1114
import org.elasticsearch.xpack.ql.tree.SourceTests;
1215
import org.elasticsearch.xpack.ql.util.StringUtils;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.querydsl.query;
6+
package org.elasticsearch.xpack.ql.querydsl.query;
77

88
import org.elasticsearch.ElasticsearchParseException;
99
import org.elasticsearch.index.query.Operator;
1010
import org.elasticsearch.index.query.QueryStringQueryBuilder;
1111
import org.elasticsearch.test.ESTestCase;
1212
import org.elasticsearch.xpack.ql.expression.predicate.fulltext.StringQueryPredicate;
13+
import org.elasticsearch.xpack.ql.querydsl.query.QueryStringQuery;
1314
import org.elasticsearch.xpack.ql.tree.Source;
1415
import org.elasticsearch.xpack.ql.util.StringUtils;
1516

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryFolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.xpack.ql.expression.gen.pipeline.UnaryPipe;
3131
import org.elasticsearch.xpack.ql.expression.gen.processor.Processor;
3232
import org.elasticsearch.xpack.ql.expression.gen.script.ScriptTemplate;
33+
import org.elasticsearch.xpack.ql.querydsl.query.Query;
3334
import org.elasticsearch.xpack.ql.rule.Rule;
3435
import org.elasticsearch.xpack.ql.rule.RuleExecutor;
3536
import org.elasticsearch.xpack.sql.SqlIllegalArgumentException;
@@ -74,7 +75,6 @@
7475
import org.elasticsearch.xpack.sql.querydsl.container.Sort.Direction;
7576
import org.elasticsearch.xpack.sql.querydsl.container.Sort.Missing;
7677
import org.elasticsearch.xpack.sql.querydsl.container.TopHitsAggRef;
77-
import org.elasticsearch.xpack.sql.querydsl.query.Query;
7878
import org.elasticsearch.xpack.sql.session.EmptyExecutable;
7979
import org.elasticsearch.xpack.sql.util.Check;
8080
import org.elasticsearch.xpack.sql.util.DateUtils;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,25 @@
3838
import org.elasticsearch.xpack.ql.expression.predicate.regex.LikePattern;
3939
import org.elasticsearch.xpack.ql.expression.predicate.regex.RLike;
4040
import org.elasticsearch.xpack.ql.expression.predicate.regex.RegexMatch;
41+
import org.elasticsearch.xpack.ql.querydsl.query.BoolQuery;
42+
import org.elasticsearch.xpack.ql.querydsl.query.ExistsQuery;
43+
import org.elasticsearch.xpack.ql.querydsl.query.GeoDistanceQuery;
44+
import org.elasticsearch.xpack.ql.querydsl.query.MatchQuery;
45+
import org.elasticsearch.xpack.ql.querydsl.query.MultiMatchQuery;
46+
import org.elasticsearch.xpack.ql.querydsl.query.NestedQuery;
47+
import org.elasticsearch.xpack.ql.querydsl.query.NotQuery;
48+
import org.elasticsearch.xpack.ql.querydsl.query.Query;
49+
import org.elasticsearch.xpack.ql.querydsl.query.QueryStringQuery;
50+
import org.elasticsearch.xpack.ql.querydsl.query.RangeQuery;
51+
import org.elasticsearch.xpack.ql.querydsl.query.RegexQuery;
52+
import org.elasticsearch.xpack.ql.querydsl.query.ScriptQuery;
53+
import org.elasticsearch.xpack.ql.querydsl.query.TermQuery;
54+
import org.elasticsearch.xpack.ql.querydsl.query.TermsQuery;
55+
import org.elasticsearch.xpack.ql.querydsl.query.WildcardQuery;
4156
import org.elasticsearch.xpack.ql.tree.Source;
57+
import org.elasticsearch.xpack.ql.type.DataType;
58+
import org.elasticsearch.xpack.ql.type.DataTypes;
59+
import org.elasticsearch.xpack.ql.util.CollectionUtils;
4260
import org.elasticsearch.xpack.ql.util.Holder;
4361
import org.elasticsearch.xpack.ql.util.ReflectionUtils;
4462
import org.elasticsearch.xpack.sql.SqlIllegalArgumentException;
@@ -79,28 +97,16 @@
7997
import org.elasticsearch.xpack.sql.querydsl.agg.StatsAgg;
8098
import org.elasticsearch.xpack.sql.querydsl.agg.SumAgg;
8199
import org.elasticsearch.xpack.sql.querydsl.agg.TopHitsAgg;
82-
import org.elasticsearch.xpack.sql.querydsl.query.BoolQuery;
83-
import org.elasticsearch.xpack.sql.querydsl.query.ExistsQuery;
84-
import org.elasticsearch.xpack.sql.querydsl.query.GeoDistanceQuery;
85-
import org.elasticsearch.xpack.sql.querydsl.query.MatchQuery;
86-
import org.elasticsearch.xpack.sql.querydsl.query.MultiMatchQuery;
87-
import org.elasticsearch.xpack.sql.querydsl.query.NestedQuery;
88-
import org.elasticsearch.xpack.sql.querydsl.query.NotQuery;
89-
import org.elasticsearch.xpack.sql.querydsl.query.Query;
90-
import org.elasticsearch.xpack.sql.querydsl.query.QueryStringQuery;
91-
import org.elasticsearch.xpack.sql.querydsl.query.RangeQuery;
92-
import org.elasticsearch.xpack.sql.querydsl.query.RegexQuery;
93-
import org.elasticsearch.xpack.sql.querydsl.query.ScriptQuery;
94-
import org.elasticsearch.xpack.sql.querydsl.query.TermQuery;
95-
import org.elasticsearch.xpack.sql.querydsl.query.TermsQuery;
96-
import org.elasticsearch.xpack.sql.querydsl.query.WildcardQuery;
100+
import org.elasticsearch.xpack.sql.type.SqlDataTypeConverter;
97101
import org.elasticsearch.xpack.sql.util.Check;
98102

99103
import java.time.OffsetTime;
100104
import java.time.ZonedDateTime;
101105
import java.time.temporal.TemporalAccessor;
102106
import java.util.Arrays;
107+
import java.util.LinkedHashSet;
103108
import java.util.List;
109+
import java.util.Set;
104110
import java.util.function.Supplier;
105111

106112
import static java.util.Collections.singletonList;
@@ -584,9 +590,17 @@ protected QueryTranslation asQuery(In in, boolean onAggs) {
584590
else {
585591
Query q = null;
586592
if (in.value() instanceof FieldAttribute) {
587-
FieldAttribute fa = (FieldAttribute) in.value();
588593
// equality should always be against an exact match (which is important for strings)
589-
q = new TermsQuery(in.source(), fa.exactAttribute().name(), in.list());
594+
FieldAttribute fa = (FieldAttribute) in.value();
595+
List<Expression> list = in.list();
596+
// TODO: this needs to be handled inside the optimizer
597+
list.removeIf(e -> DataTypes.isNull(e.dataType()));
598+
DataType dt = list.get(0).dataType();
599+
Set<Object> set = new LinkedHashSet<>(CollectionUtils.mapSize(list.size()));
600+
for (Expression e : list) {
601+
set.add(SqlDataTypeConverter.convert(e.fold(), dt));
602+
}
603+
q = new TermsQuery(in.source(), fa.exactAttribute().name(), set);
590604
} else {
591605
q = new ScriptQuery(in.source(), in.asScript());
592606
}

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
import org.elasticsearch.xpack.ql.expression.function.scalar.ScalarFunction;
2222
import org.elasticsearch.xpack.ql.expression.gen.pipeline.ConstantInput;
2323
import org.elasticsearch.xpack.ql.expression.gen.pipeline.Pipe;
24+
import org.elasticsearch.xpack.ql.querydsl.query.BoolQuery;
25+
import org.elasticsearch.xpack.ql.querydsl.query.MatchAll;
26+
import org.elasticsearch.xpack.ql.querydsl.query.NestedQuery;
27+
import org.elasticsearch.xpack.ql.querydsl.query.Query;
2428
import org.elasticsearch.xpack.ql.tree.Source;
2529
import org.elasticsearch.xpack.ql.type.DataTypes;
2630
import org.elasticsearch.xpack.sql.SqlIllegalArgumentException;
@@ -30,10 +34,6 @@
3034
import org.elasticsearch.xpack.sql.querydsl.agg.Aggs;
3135
import org.elasticsearch.xpack.sql.querydsl.agg.GroupByKey;
3236
import org.elasticsearch.xpack.sql.querydsl.agg.LeafAgg;
33-
import org.elasticsearch.xpack.sql.querydsl.query.BoolQuery;
34-
import org.elasticsearch.xpack.sql.querydsl.query.MatchAll;
35-
import org.elasticsearch.xpack.sql.querydsl.query.NestedQuery;
36-
import org.elasticsearch.xpack.sql.querydsl.query.Query;
3737
import org.elasticsearch.xpack.sql.type.SqlDataTypes;
3838

3939
import java.io.IOException;

0 commit comments

Comments
 (0)