From e37f54dbbb38ff2369e9df39c9a74190458d2aa1 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 7 Feb 2020 19:55:53 +0200 Subject: [PATCH 1/2] QL: move query AST from SQL to QL --- .../xpack/ql}/querydsl/query/BoolQuery.java | 2 +- .../xpack/ql}/querydsl/query/ExistsQuery.java | 2 +- .../ql}/querydsl/query/GeoDistanceQuery.java | 2 +- .../xpack/ql}/querydsl/query/LeafQuery.java | 2 +- .../xpack/ql}/querydsl/query/MatchAll.java | 2 +- .../xpack/ql}/querydsl/query/MatchQuery.java | 2 +- .../ql}/querydsl/query/MultiMatchQuery.java | 2 +- .../xpack/ql}/querydsl/query/NestedQuery.java | 2 +- .../xpack/ql}/querydsl/query/NotQuery.java | 2 +- .../xpack/ql}/querydsl/query/Query.java | 2 +- .../ql}/querydsl/query/QueryStringQuery.java | 2 +- .../xpack/ql}/querydsl/query/RangeQuery.java | 2 +- .../xpack/ql}/querydsl/query/RegexQuery.java | 2 +- .../xpack/ql}/querydsl/query/ScriptQuery.java | 2 +- .../xpack/ql}/querydsl/query/TermQuery.java | 2 +- .../xpack/ql}/querydsl/query/TermsQuery.java | 20 ++++++++++--- .../ql}/querydsl/query/WildcardQuery.java | 2 +- .../ql}/querydsl/query/BoolQueryTests.java | 7 ++++- .../ql}/querydsl/query/LeafQueryTests.java | 4 ++- .../ql}/querydsl/query/MatchQueryTests.java | 3 +- .../querydsl/query/MultiMatchQueryTests.java | 3 +- .../ql}/querydsl/query/NestedQueryTests.java | 5 +++- .../querydsl/query/QueryStringQueryTests.java | 3 +- .../xpack/sql/planner/QueryFolder.java | 2 +- .../xpack/sql/planner/QueryTranslator.java | 30 +++++++++---------- .../querydsl/container/QueryContainer.java | 8 ++--- .../search/SourceGeneratorTests.java | 2 +- .../sql/planner/QueryTranslatorTests.java | 22 +++++++------- .../container/QueryContainerTests.java | 10 +++---- 29 files changed, 88 insertions(+), 63 deletions(-) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/BoolQuery.java (98%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/ExistsQuery.java (93%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/GeoDistanceQuery.java (97%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/LeafQuery.java (94%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/MatchAll.java (93%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/MatchQuery.java (98%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/MultiMatchQuery.java (98%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/NestedQuery.java (99%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/NotQuery.java (97%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/Query.java (97%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/QueryStringQuery.java (99%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/RangeQuery.java (98%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/RegexQuery.java (96%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/ScriptQuery.java (96%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/TermQuery.java (96%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/TermsQuery.java (69%) rename x-pack/plugin/{sql/src/main/java/org/elasticsearch/xpack/sql => ql/src/main/java/org/elasticsearch/xpack/ql}/querydsl/query/WildcardQuery.java (96%) rename x-pack/plugin/{sql/src/test/java/org/elasticsearch/xpack/sql => ql/src/test/java/org/elasticsearch/xpack/ql}/querydsl/query/BoolQueryTests.java (93%) rename x-pack/plugin/{sql/src/test/java/org/elasticsearch/xpack/sql => ql/src/test/java/org/elasticsearch/xpack/ql}/querydsl/query/LeafQueryTests.java (93%) rename x-pack/plugin/{sql/src/test/java/org/elasticsearch/xpack/sql => ql/src/test/java/org/elasticsearch/xpack/ql}/querydsl/query/MatchQueryTests.java (97%) rename x-pack/plugin/{sql/src/test/java/org/elasticsearch/xpack/sql => ql/src/test/java/org/elasticsearch/xpack/ql}/querydsl/query/MultiMatchQueryTests.java (95%) rename x-pack/plugin/{sql/src/test/java/org/elasticsearch/xpack/sql => ql/src/test/java/org/elasticsearch/xpack/ql}/querydsl/query/NestedQueryTests.java (96%) rename x-pack/plugin/{sql/src/test/java/org/elasticsearch/xpack/sql => ql/src/test/java/org/elasticsearch/xpack/ql}/querydsl/query/QueryStringQueryTests.java (95%) diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/BoolQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/BoolQuery.java similarity index 98% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/BoolQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/BoolQuery.java index 446a7d12737f0..d15e781f24119 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/BoolQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/BoolQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/ExistsQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/ExistsQuery.java similarity index 93% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/ExistsQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/ExistsQuery.java index e639e1cfe3a82..afe3653cdbf57 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/ExistsQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/ExistsQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.xpack.ql.tree.Source; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/GeoDistanceQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/GeoDistanceQuery.java similarity index 97% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/GeoDistanceQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/GeoDistanceQuery.java index 351bde8d9f182..0775cad92016e 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/GeoDistanceQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/GeoDistanceQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.index.query.QueryBuilder; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/LeafQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/LeafQuery.java similarity index 94% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/LeafQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/LeafQuery.java index c96d53c909c64..955d262ad276e 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/LeafQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/LeafQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.search.sort.NestedSortBuilder; import org.elasticsearch.xpack.ql.tree.Source; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchAll.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MatchAll.java similarity index 93% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchAll.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MatchAll.java index 82d5a12d23547..8f24dd93ec7a0 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchAll.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MatchAll.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.xpack.ql.tree.Source; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MatchQuery.java similarity index 98% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MatchQuery.java index 86a7004eb449d..ac081bc408c79 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MatchQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.unit.Fuzziness; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MultiMatchQuery.java similarity index 98% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MultiMatchQuery.java index 0704d1fb3310b..5d1d7535c2afb 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/MultiMatchQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.unit.Fuzziness; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/NestedQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/NestedQuery.java similarity index 99% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/NestedQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/NestedQuery.java index 91aa7211cdd93..0ee7326977a44 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/NestedQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/NestedQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.apache.lucene.search.join.ScoreMode; import org.elasticsearch.index.query.InnerHitBuilder; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/NotQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/NotQuery.java similarity index 97% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/NotQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/NotQuery.java index 19e978f6e89b1..19f85c1996471 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/NotQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/NotQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.sort.NestedSortBuilder; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/Query.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/Query.java similarity index 97% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/Query.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/Query.java index 6d35823b20bcb..2bbf41b96792b 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/Query.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/Query.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.sort.NestedSortBuilder; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/QueryStringQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/QueryStringQuery.java similarity index 99% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/QueryStringQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/QueryStringQuery.java index b774e95bf86aa..b6edc36a5d260 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/QueryStringQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/QueryStringQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.unit.Fuzziness; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/RangeQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/RangeQuery.java similarity index 98% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/RangeQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/RangeQuery.java index e64993c3202a5..1bc460175c8fe 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/RangeQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/RangeQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.common.Strings; import org.elasticsearch.index.query.QueryBuilder; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/RegexQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/RegexQuery.java similarity index 96% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/RegexQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/RegexQuery.java index eaa166aa3a10c..92d7b983af166 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/RegexQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/RegexQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.xpack.ql.tree.Source; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/ScriptQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/ScriptQuery.java similarity index 96% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/ScriptQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/ScriptQuery.java index af1919efab391..c0260a5bd798a 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/ScriptQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/ScriptQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.xpack.ql.expression.gen.script.ScriptTemplate; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/TermQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermQuery.java similarity index 96% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/TermQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermQuery.java index 2c10ae8d666a2..229a459e73e3f 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/TermQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.xpack.ql.tree.Source; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/TermsQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermsQuery.java similarity index 69% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/TermsQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermsQuery.java index 6b12c83b4acb0..7ad6778aef105 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/TermsQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermsQuery.java @@ -3,13 +3,16 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.xpack.ql.QlIllegalArgumentException; import org.elasticsearch.xpack.ql.expression.Expression; import org.elasticsearch.xpack.ql.tree.Source; +import org.elasticsearch.xpack.ql.type.DataType; +import org.elasticsearch.xpack.ql.type.DataTypeConverter; import org.elasticsearch.xpack.ql.type.DataTypes; -import org.elasticsearch.xpack.sql.expression.Foldables; +import org.elasticsearch.xpack.ql.util.CollectionUtils; import java.util.Collections; import java.util.LinkedHashSet; @@ -31,7 +34,16 @@ public TermsQuery(Source source, String term, List values) { if (values.isEmpty()) { this.values = Collections.emptySet(); } else { - this.values = new LinkedHashSet<>(Foldables.valuesOf(values, values.get(0).dataType())); + DataType dt = values.get(0).dataType(); + Set set = new LinkedHashSet<>(CollectionUtils.mapSize(values.size())); + for (Expression e : values) { + if (e.foldable()) { + set.add(DataTypeConverter.convert(e.fold(), dt)); + } else { + throw new QlIllegalArgumentException("Cannot determine value for {}", e); + } + } + this.values = set; } } @@ -64,4 +76,4 @@ public boolean equals(Object obj) { protected String innerToString() { return term + ":" + values; } -} +} \ No newline at end of file diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/WildcardQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/WildcardQuery.java similarity index 96% rename from x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/WildcardQuery.java rename to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/WildcardQuery.java index 337d3339614b6..47d5624dbab36 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/WildcardQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/WildcardQuery.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.xpack.ql.tree.Source; diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/BoolQueryTests.java b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/BoolQueryTests.java similarity index 93% rename from x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/BoolQueryTests.java rename to x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/BoolQueryTests.java index 43f49630e4b2a..82475035de83f 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/BoolQueryTests.java +++ b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/BoolQueryTests.java @@ -3,10 +3,15 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.search.sort.NestedSortBuilder; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.ql.querydsl.query.BoolQuery; +import org.elasticsearch.xpack.ql.querydsl.query.ExistsQuery; +import org.elasticsearch.xpack.ql.querydsl.query.MatchAll; +import org.elasticsearch.xpack.ql.querydsl.query.NestedQuery; +import org.elasticsearch.xpack.ql.querydsl.query.Query; import org.elasticsearch.xpack.ql.tree.Source; import org.elasticsearch.xpack.ql.tree.SourceTests; import org.elasticsearch.xpack.ql.util.StringUtils; diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/LeafQueryTests.java b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/LeafQueryTests.java similarity index 93% rename from x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/LeafQueryTests.java rename to x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/LeafQueryTests.java index 58bd29f8593fa..5976899c655ca 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/LeafQueryTests.java +++ b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/LeafQueryTests.java @@ -3,11 +3,13 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.sort.NestedSortBuilder; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.ql.querydsl.query.LeafQuery; +import org.elasticsearch.xpack.ql.querydsl.query.Query; import org.elasticsearch.xpack.ql.tree.Source; import org.elasticsearch.xpack.ql.tree.SourceTests; import org.elasticsearch.xpack.ql.util.StringUtils; diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQueryTests.java b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/MatchQueryTests.java similarity index 97% rename from x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQueryTests.java rename to x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/MatchQueryTests.java index 2928ab3b98946..904d3b8263d88 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQueryTests.java +++ b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/MatchQueryTests.java @@ -3,13 +3,14 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.MatchQueryBuilder; import org.elasticsearch.index.query.Operator; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.ql.expression.FieldAttribute; import org.elasticsearch.xpack.ql.expression.predicate.fulltext.MatchQueryPredicate; +import org.elasticsearch.xpack.ql.querydsl.query.MatchQuery; import org.elasticsearch.xpack.ql.tree.Source; import org.elasticsearch.xpack.ql.tree.SourceTests; import org.elasticsearch.xpack.ql.type.EsField; diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQueryTests.java b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/MultiMatchQueryTests.java similarity index 95% rename from x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQueryTests.java rename to x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/MultiMatchQueryTests.java index 6fddc2eabc975..66d740b0cb082 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQueryTests.java +++ b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/MultiMatchQueryTests.java @@ -3,12 +3,13 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.index.query.MultiMatchQueryBuilder; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.ql.expression.predicate.fulltext.MultiMatchQueryPredicate; +import org.elasticsearch.xpack.ql.querydsl.query.MultiMatchQuery; import org.elasticsearch.xpack.ql.tree.Source; import org.elasticsearch.xpack.ql.util.StringUtils; diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/NestedQueryTests.java b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/NestedQueryTests.java similarity index 96% rename from x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/NestedQueryTests.java rename to x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/NestedQueryTests.java index 4975ac6326ec0..b0e334e68dfeb 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/NestedQueryTests.java +++ b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/NestedQueryTests.java @@ -3,10 +3,13 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.search.sort.NestedSortBuilder; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.ql.querydsl.query.MatchAll; +import org.elasticsearch.xpack.ql.querydsl.query.NestedQuery; +import org.elasticsearch.xpack.ql.querydsl.query.Query; import org.elasticsearch.xpack.ql.tree.Source; import org.elasticsearch.xpack.ql.tree.SourceTests; import org.elasticsearch.xpack.ql.util.StringUtils; diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/QueryStringQueryTests.java b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/QueryStringQueryTests.java similarity index 95% rename from x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/QueryStringQueryTests.java rename to x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/QueryStringQueryTests.java index c97e6b678d353..deb496eeb78b7 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/QueryStringQueryTests.java +++ b/x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/querydsl/query/QueryStringQueryTests.java @@ -3,13 +3,14 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql.querydsl.query; +package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.index.query.Operator; import org.elasticsearch.index.query.QueryStringQueryBuilder; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.ql.expression.predicate.fulltext.StringQueryPredicate; +import org.elasticsearch.xpack.ql.querydsl.query.QueryStringQuery; import org.elasticsearch.xpack.ql.tree.Source; import org.elasticsearch.xpack.ql.util.StringUtils; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryFolder.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryFolder.java index f426cb6dfdfad..4c314442a5398 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryFolder.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryFolder.java @@ -30,6 +30,7 @@ import org.elasticsearch.xpack.ql.expression.gen.pipeline.UnaryPipe; import org.elasticsearch.xpack.ql.expression.gen.processor.Processor; import org.elasticsearch.xpack.ql.expression.gen.script.ScriptTemplate; +import org.elasticsearch.xpack.ql.querydsl.query.Query; import org.elasticsearch.xpack.ql.rule.Rule; import org.elasticsearch.xpack.ql.rule.RuleExecutor; import org.elasticsearch.xpack.sql.SqlIllegalArgumentException; @@ -74,7 +75,6 @@ import org.elasticsearch.xpack.sql.querydsl.container.Sort.Direction; import org.elasticsearch.xpack.sql.querydsl.container.Sort.Missing; import org.elasticsearch.xpack.sql.querydsl.container.TopHitsAggRef; -import org.elasticsearch.xpack.sql.querydsl.query.Query; import org.elasticsearch.xpack.sql.session.EmptyExecutable; import org.elasticsearch.xpack.sql.util.Check; import org.elasticsearch.xpack.sql.util.DateUtils; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java index 6c13da06629fc..ef33a85be16c0 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java @@ -38,6 +38,21 @@ import org.elasticsearch.xpack.ql.expression.predicate.regex.LikePattern; import org.elasticsearch.xpack.ql.expression.predicate.regex.RLike; import org.elasticsearch.xpack.ql.expression.predicate.regex.RegexMatch; +import org.elasticsearch.xpack.ql.querydsl.query.BoolQuery; +import org.elasticsearch.xpack.ql.querydsl.query.ExistsQuery; +import org.elasticsearch.xpack.ql.querydsl.query.GeoDistanceQuery; +import org.elasticsearch.xpack.ql.querydsl.query.MatchQuery; +import org.elasticsearch.xpack.ql.querydsl.query.MultiMatchQuery; +import org.elasticsearch.xpack.ql.querydsl.query.NestedQuery; +import org.elasticsearch.xpack.ql.querydsl.query.NotQuery; +import org.elasticsearch.xpack.ql.querydsl.query.Query; +import org.elasticsearch.xpack.ql.querydsl.query.QueryStringQuery; +import org.elasticsearch.xpack.ql.querydsl.query.RangeQuery; +import org.elasticsearch.xpack.ql.querydsl.query.RegexQuery; +import org.elasticsearch.xpack.ql.querydsl.query.ScriptQuery; +import org.elasticsearch.xpack.ql.querydsl.query.TermQuery; +import org.elasticsearch.xpack.ql.querydsl.query.TermsQuery; +import org.elasticsearch.xpack.ql.querydsl.query.WildcardQuery; import org.elasticsearch.xpack.ql.tree.Source; import org.elasticsearch.xpack.ql.util.Holder; import org.elasticsearch.xpack.ql.util.ReflectionUtils; @@ -79,21 +94,6 @@ import org.elasticsearch.xpack.sql.querydsl.agg.StatsAgg; import org.elasticsearch.xpack.sql.querydsl.agg.SumAgg; import org.elasticsearch.xpack.sql.querydsl.agg.TopHitsAgg; -import org.elasticsearch.xpack.sql.querydsl.query.BoolQuery; -import org.elasticsearch.xpack.sql.querydsl.query.ExistsQuery; -import org.elasticsearch.xpack.sql.querydsl.query.GeoDistanceQuery; -import org.elasticsearch.xpack.sql.querydsl.query.MatchQuery; -import org.elasticsearch.xpack.sql.querydsl.query.MultiMatchQuery; -import org.elasticsearch.xpack.sql.querydsl.query.NestedQuery; -import org.elasticsearch.xpack.sql.querydsl.query.NotQuery; -import org.elasticsearch.xpack.sql.querydsl.query.Query; -import org.elasticsearch.xpack.sql.querydsl.query.QueryStringQuery; -import org.elasticsearch.xpack.sql.querydsl.query.RangeQuery; -import org.elasticsearch.xpack.sql.querydsl.query.RegexQuery; -import org.elasticsearch.xpack.sql.querydsl.query.ScriptQuery; -import org.elasticsearch.xpack.sql.querydsl.query.TermQuery; -import org.elasticsearch.xpack.sql.querydsl.query.TermsQuery; -import org.elasticsearch.xpack.sql.querydsl.query.WildcardQuery; import org.elasticsearch.xpack.sql.util.Check; import java.time.OffsetTime; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainer.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainer.java index 0279dd49180e9..8d40dda7e5ae0 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainer.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainer.java @@ -21,6 +21,10 @@ import org.elasticsearch.xpack.ql.expression.function.scalar.ScalarFunction; import org.elasticsearch.xpack.ql.expression.gen.pipeline.ConstantInput; import org.elasticsearch.xpack.ql.expression.gen.pipeline.Pipe; +import org.elasticsearch.xpack.ql.querydsl.query.BoolQuery; +import org.elasticsearch.xpack.ql.querydsl.query.MatchAll; +import org.elasticsearch.xpack.ql.querydsl.query.NestedQuery; +import org.elasticsearch.xpack.ql.querydsl.query.Query; import org.elasticsearch.xpack.ql.tree.Source; import org.elasticsearch.xpack.ql.type.DataTypes; import org.elasticsearch.xpack.sql.SqlIllegalArgumentException; @@ -30,10 +34,6 @@ import org.elasticsearch.xpack.sql.querydsl.agg.Aggs; import org.elasticsearch.xpack.sql.querydsl.agg.GroupByKey; import org.elasticsearch.xpack.sql.querydsl.agg.LeafAgg; -import org.elasticsearch.xpack.sql.querydsl.query.BoolQuery; -import org.elasticsearch.xpack.sql.querydsl.query.MatchAll; -import org.elasticsearch.xpack.sql.querydsl.query.NestedQuery; -import org.elasticsearch.xpack.sql.querydsl.query.Query; import org.elasticsearch.xpack.sql.type.SqlDataTypes; import java.io.IOException; diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/SourceGeneratorTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/SourceGeneratorTests.java index 3fc5d96765ad9..64155093b87b9 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/SourceGeneratorTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/SourceGeneratorTests.java @@ -19,6 +19,7 @@ import org.elasticsearch.xpack.ql.expression.Expression; import org.elasticsearch.xpack.ql.expression.FieldAttribute; import org.elasticsearch.xpack.ql.expression.ReferenceAttribute; +import org.elasticsearch.xpack.ql.querydsl.query.MatchQuery; import org.elasticsearch.xpack.ql.tree.Source; import org.elasticsearch.xpack.ql.type.KeywordEsField; import org.elasticsearch.xpack.sql.expression.function.Score; @@ -29,7 +30,6 @@ import org.elasticsearch.xpack.sql.querydsl.container.ScoreSort; import org.elasticsearch.xpack.sql.querydsl.container.Sort.Direction; import org.elasticsearch.xpack.sql.querydsl.container.Sort.Missing; -import org.elasticsearch.xpack.sql.querydsl.query.MatchQuery; import java.util.LinkedHashMap; import java.util.Map; diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/planner/QueryTranslatorTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/planner/QueryTranslatorTests.java index bf1aeab38c432..b5138ae9e8cc4 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/planner/QueryTranslatorTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/planner/QueryTranslatorTests.java @@ -23,6 +23,17 @@ import org.elasticsearch.xpack.ql.plan.logical.Filter; import org.elasticsearch.xpack.ql.plan.logical.LogicalPlan; import org.elasticsearch.xpack.ql.plan.logical.Project; +import org.elasticsearch.xpack.ql.querydsl.query.BoolQuery; +import org.elasticsearch.xpack.ql.querydsl.query.ExistsQuery; +import org.elasticsearch.xpack.ql.querydsl.query.GeoDistanceQuery; +import org.elasticsearch.xpack.ql.querydsl.query.NotQuery; +import org.elasticsearch.xpack.ql.querydsl.query.Query; +import org.elasticsearch.xpack.ql.querydsl.query.RangeQuery; +import org.elasticsearch.xpack.ql.querydsl.query.RegexQuery; +import org.elasticsearch.xpack.ql.querydsl.query.ScriptQuery; +import org.elasticsearch.xpack.ql.querydsl.query.TermQuery; +import org.elasticsearch.xpack.ql.querydsl.query.TermsQuery; +import org.elasticsearch.xpack.ql.querydsl.query.WildcardQuery; import org.elasticsearch.xpack.ql.type.EsField; import org.elasticsearch.xpack.sql.SqlIllegalArgumentException; import org.elasticsearch.xpack.sql.SqlTestUtils; @@ -42,17 +53,6 @@ import org.elasticsearch.xpack.sql.planner.QueryTranslator.QueryTranslation; import org.elasticsearch.xpack.sql.querydsl.agg.AggFilter; import org.elasticsearch.xpack.sql.querydsl.agg.GroupByDateHistogram; -import org.elasticsearch.xpack.sql.querydsl.query.BoolQuery; -import org.elasticsearch.xpack.sql.querydsl.query.ExistsQuery; -import org.elasticsearch.xpack.sql.querydsl.query.GeoDistanceQuery; -import org.elasticsearch.xpack.sql.querydsl.query.NotQuery; -import org.elasticsearch.xpack.sql.querydsl.query.Query; -import org.elasticsearch.xpack.sql.querydsl.query.RangeQuery; -import org.elasticsearch.xpack.sql.querydsl.query.RegexQuery; -import org.elasticsearch.xpack.sql.querydsl.query.ScriptQuery; -import org.elasticsearch.xpack.sql.querydsl.query.TermQuery; -import org.elasticsearch.xpack.sql.querydsl.query.TermsQuery; -import org.elasticsearch.xpack.sql.querydsl.query.WildcardQuery; import org.elasticsearch.xpack.sql.stats.Metrics; import org.elasticsearch.xpack.sql.types.SqlTypesTests; import org.elasticsearch.xpack.sql.util.DateUtils; diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainerTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainerTests.java index e35b38ff4ada5..b5f87a64a5bd9 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainerTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainerTests.java @@ -11,14 +11,14 @@ import org.elasticsearch.xpack.ql.expression.AttributeMap; import org.elasticsearch.xpack.ql.expression.Expression; import org.elasticsearch.xpack.ql.expression.FieldAttribute; +import org.elasticsearch.xpack.ql.querydsl.query.BoolQuery; +import org.elasticsearch.xpack.ql.querydsl.query.MatchAll; +import org.elasticsearch.xpack.ql.querydsl.query.NestedQuery; +import org.elasticsearch.xpack.ql.querydsl.query.Query; +import org.elasticsearch.xpack.ql.querydsl.query.RangeQuery; import org.elasticsearch.xpack.ql.tree.Source; import org.elasticsearch.xpack.ql.tree.SourceTests; import org.elasticsearch.xpack.ql.type.EsField; -import org.elasticsearch.xpack.sql.querydsl.query.BoolQuery; -import org.elasticsearch.xpack.sql.querydsl.query.MatchAll; -import org.elasticsearch.xpack.sql.querydsl.query.NestedQuery; -import org.elasticsearch.xpack.sql.querydsl.query.Query; -import org.elasticsearch.xpack.sql.querydsl.query.RangeQuery; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Arrays; From fb55e153029c955a734324592b516503efd1782e Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 7 Feb 2020 21:59:58 +0200 Subject: [PATCH 2/2] Rework TermsQuery translation --- .../xpack/ql/querydsl/query/TermsQuery.java | 27 ++----------------- .../xpack/sql/planner/QueryTranslator.java | 18 +++++++++++-- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermsQuery.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermsQuery.java index 7ad6778aef105..aa611024de514 100644 --- a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermsQuery.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/querydsl/query/TermsQuery.java @@ -6,17 +6,8 @@ package org.elasticsearch.xpack.ql.querydsl.query; import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.xpack.ql.QlIllegalArgumentException; -import org.elasticsearch.xpack.ql.expression.Expression; import org.elasticsearch.xpack.ql.tree.Source; -import org.elasticsearch.xpack.ql.type.DataType; -import org.elasticsearch.xpack.ql.type.DataTypeConverter; -import org.elasticsearch.xpack.ql.type.DataTypes; -import org.elasticsearch.xpack.ql.util.CollectionUtils; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; import java.util.Objects; import java.util.Set; @@ -27,24 +18,10 @@ public class TermsQuery extends LeafQuery { private final String term; private final Set values; - public TermsQuery(Source source, String term, List values) { + public TermsQuery(Source source, String term, Set values) { super(source); this.term = term; - values.removeIf(e -> DataTypes.isNull(e.dataType())); - if (values.isEmpty()) { - this.values = Collections.emptySet(); - } else { - DataType dt = values.get(0).dataType(); - Set set = new LinkedHashSet<>(CollectionUtils.mapSize(values.size())); - for (Expression e : values) { - if (e.foldable()) { - set.add(DataTypeConverter.convert(e.fold(), dt)); - } else { - throw new QlIllegalArgumentException("Cannot determine value for {}", e); - } - } - this.values = set; - } + this.values = values; } @Override diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java index ef33a85be16c0..daed8b1c99401 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java @@ -54,6 +54,9 @@ import org.elasticsearch.xpack.ql.querydsl.query.TermsQuery; import org.elasticsearch.xpack.ql.querydsl.query.WildcardQuery; import org.elasticsearch.xpack.ql.tree.Source; +import org.elasticsearch.xpack.ql.type.DataType; +import org.elasticsearch.xpack.ql.type.DataTypes; +import org.elasticsearch.xpack.ql.util.CollectionUtils; import org.elasticsearch.xpack.ql.util.Holder; import org.elasticsearch.xpack.ql.util.ReflectionUtils; import org.elasticsearch.xpack.sql.SqlIllegalArgumentException; @@ -94,13 +97,16 @@ import org.elasticsearch.xpack.sql.querydsl.agg.StatsAgg; import org.elasticsearch.xpack.sql.querydsl.agg.SumAgg; import org.elasticsearch.xpack.sql.querydsl.agg.TopHitsAgg; +import org.elasticsearch.xpack.sql.type.SqlDataTypeConverter; import org.elasticsearch.xpack.sql.util.Check; import java.time.OffsetTime; import java.time.ZonedDateTime; import java.time.temporal.TemporalAccessor; import java.util.Arrays; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import java.util.function.Supplier; import static java.util.Collections.singletonList; @@ -584,9 +590,17 @@ protected QueryTranslation asQuery(In in, boolean onAggs) { else { Query q = null; if (in.value() instanceof FieldAttribute) { - FieldAttribute fa = (FieldAttribute) in.value(); // equality should always be against an exact match (which is important for strings) - q = new TermsQuery(in.source(), fa.exactAttribute().name(), in.list()); + FieldAttribute fa = (FieldAttribute) in.value(); + List list = in.list(); + // TODO: this needs to be handled inside the optimizer + list.removeIf(e -> DataTypes.isNull(e.dataType())); + DataType dt = list.get(0).dataType(); + Set set = new LinkedHashSet<>(CollectionUtils.mapSize(list.size())); + for (Expression e : list) { + set.add(SqlDataTypeConverter.convert(e.fold(), dt)); + } + q = new TermsQuery(in.source(), fa.exactAttribute().name(), set); } else { q = new ScriptQuery(in.source(), in.asScript()); }