From 48cd016f909bbeca7b0d0a4926e36a333d021869 Mon Sep 17 00:00:00 2001 From: Daniel Worley Date: Tue, 27 Apr 2021 16:56:33 -0400 Subject: [PATCH] Es 7 12 (#364) * wip for 7.11 deprecations * Fix build errors for 7.11 * add public visibility to test templates * keeping threadpool over executor for now * remove all the checks except keep nebula disabled * Restore override annotation in TransportAddFeatureToSet * read() was removed * Bring back checkstyle and fix some violations * Clean up unused vars * 7.12 changes Co-authored-by: Nathan Day --- gradle.properties | 4 ++-- .../o19s/es/explore/ExplorerQueryBuilder.java | 4 ++-- .../java/com/o19s/es/ltr/LtrQueryContext.java | 10 ++++----- .../store/PrecompiledTemplateFeature.java | 7 +++--- .../es/ltr/feature/store/ScriptFeature.java | 14 ++++++------ .../es/ltr/feature/store/StoredFeature.java | 5 +++-- .../o19s/es/ltr/query/LtrQueryBuilder.java | 4 ++-- .../es/ltr/query/StoredLtrQueryBuilder.java | 6 ++--- .../ltr/query/ValidatingLtrQueryBuilder.java | 8 +++---- .../es/termstat/TermStatQueryBuilder.java | 8 +++---- .../es/explore/ExplorerQueryBuilderTests.java | 6 ++--- .../es/ltr/query/LtrQueryBuilderTests.java | 14 ++++++------ .../ltr/query/StoredLtrQueryBuilderTests.java | 22 +++++++++---------- .../query/ValidatingLtrQueryBuilderTests.java | 5 +++-- .../termstat/TermStatQueryBuilderTests.java | 4 ++-- 15 files changed, 62 insertions(+), 59 deletions(-) diff --git a/gradle.properties b/gradle.properties index 10717d12..c8416f9c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ ltrVersion = 1.5.4 -elasticsearchVersion = 7.11.1 -luceneVersion = 8.7.0 +elasticsearchVersion = 7.12.0 +luceneVersion = 8.8.0 ow2Version = 8.0.1 antlrVersion = 4.5.1-1 diff --git a/src/main/java/com/o19s/es/explore/ExplorerQueryBuilder.java b/src/main/java/com/o19s/es/explore/ExplorerQueryBuilder.java index 8e4fb04c..86ded2c7 100644 --- a/src/main/java/com/o19s/es/explore/ExplorerQueryBuilder.java +++ b/src/main/java/com/o19s/es/explore/ExplorerQueryBuilder.java @@ -27,7 +27,7 @@ import org.elasticsearch.index.query.AbstractQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryRewriteContext; -import org.elasticsearch.index.query.QueryShardContext; +import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.index.query.Rewriteable; import java.io.IOException; @@ -98,7 +98,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } @Override - protected Query doToQuery(QueryShardContext context) throws IOException { + protected Query doToQuery(SearchExecutionContext context) throws IOException { return new ExplorerQuery(query.toQuery(context), type); } diff --git a/src/main/java/com/o19s/es/ltr/LtrQueryContext.java b/src/main/java/com/o19s/es/ltr/LtrQueryContext.java index 7d10f2d7..2912a02f 100644 --- a/src/main/java/com/o19s/es/ltr/LtrQueryContext.java +++ b/src/main/java/com/o19s/es/ltr/LtrQueryContext.java @@ -16,7 +16,7 @@ package com.o19s.es.ltr; -import org.elasticsearch.index.query.QueryShardContext; +import org.elasticsearch.index.query.SearchExecutionContext; import java.util.Collections; import java.util.Set; @@ -25,19 +25,19 @@ * LTR queryShardContext used to track information needed for building lucene queries */ public class LtrQueryContext { - private final QueryShardContext queryShardContext; + private final SearchExecutionContext queryShardContext; private final Set activeFeatures; - public LtrQueryContext(QueryShardContext context) { + public LtrQueryContext(SearchExecutionContext context) { this(context, Collections.emptySet()); } - public LtrQueryContext(QueryShardContext context, Set activeFeatures) { + public LtrQueryContext(SearchExecutionContext context, Set activeFeatures) { this.queryShardContext = context; this.activeFeatures = activeFeatures; } - public QueryShardContext getQueryShardContext() { + public SearchExecutionContext getSearchExecutionContext() { return queryShardContext; } diff --git a/src/main/java/com/o19s/es/ltr/feature/store/PrecompiledTemplateFeature.java b/src/main/java/com/o19s/es/ltr/feature/store/PrecompiledTemplateFeature.java index 14d7a3f0..4d887275 100644 --- a/src/main/java/com/o19s/es/ltr/feature/store/PrecompiledTemplateFeature.java +++ b/src/main/java/com/o19s/es/ltr/feature/store/PrecompiledTemplateFeature.java @@ -93,14 +93,15 @@ public Query doToQuery(LtrQueryContext context, FeatureSet set, Map features = new ArrayList<>(_features.size()); for (QueryBuilder builder : _features) { features.add(new PrebuiltFeature(builder.queryName(), builder.toQuery(context))); diff --git a/src/main/java/com/o19s/es/ltr/query/StoredLtrQueryBuilder.java b/src/main/java/com/o19s/es/ltr/query/StoredLtrQueryBuilder.java index 2d18239b..dc59dbf0 100644 --- a/src/main/java/com/o19s/es/ltr/query/StoredLtrQueryBuilder.java +++ b/src/main/java/com/o19s/es/ltr/query/StoredLtrQueryBuilder.java @@ -33,7 +33,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.AbstractQueryBuilder; -import org.elasticsearch.index.query.QueryShardContext; +import org.elasticsearch.index.query.SearchExecutionContext; import java.io.IOException; import java.util.Arrays; @@ -66,7 +66,7 @@ public class StoredLtrQueryBuilder extends AbstractQueryBuilder builder.toQuery(createShardContext())).getMessage(), + assertThat(expectThrows(IllegalArgumentException.class, () -> builder.toQuery(createSearchExecutionContext())).getMessage(), equalTo("Missing required param(s): [query_string]")); Map params = new HashMap<>(); params.put("query_string2", "a wonderful query"); builder.params(params); - assertThat(expectThrows(IllegalArgumentException.class, () -> builder.toQuery(createShardContext())).getMessage(), + assertThat(expectThrows(IllegalArgumentException.class, () -> builder.toQuery(createSearchExecutionContext())).getMessage(), equalTo("Missing required param(s): [query_string]")); } @@ -147,7 +147,7 @@ public void testInvalidActiveFeatures() { StoredLtrQueryBuilder builder = new StoredLtrQueryBuilder(LtrTestUtils.wrapMemStore(StoredLtrQueryBuilderTests.store)); builder.modelName("model1"); builder.activeFeatures(Collections.singletonList("non_existent_feature")); - assertThat(expectThrows(IllegalArgumentException.class, () -> builder.toQuery(createShardContext())).getMessage(), + assertThat(expectThrows(IllegalArgumentException.class, () -> builder.toQuery(createSearchExecutionContext())).getMessage(), equalTo("Feature: [non_existent_feature] provided in active_features does not exist")); } @@ -184,14 +184,14 @@ private void assertQueryClass(Class clazz, boolean setActiveFeature) throws I builder.activeFeatures(Arrays.asList("match1", "match2")); } - RankerQuery rankerQuery = builder.doToQuery(createShardContext()); + RankerQuery rankerQuery = builder.doToQuery(createSearchExecutionContext()); List queries = rankerQuery.stream().collect(Collectors.toList()); assertEquals(clazz, queries.get(2).getClass()); } @Override protected void doAssertLuceneQuery(StoredLtrQueryBuilder queryBuilder, - Query query, QueryShardContext context) throws IOException { + Query query, SearchExecutionContext context) throws IOException { assertThat(query, instanceOf(RankerQuery.class)); RankerQuery rquery = (RankerQuery) query; Iterator ite = rquery.stream().iterator(); @@ -209,7 +209,7 @@ protected void doAssertLuceneQuery(StoredLtrQueryBuilder queryBuilder, assertTrue(ite.hasNext()); Query featureQuery = ite.next(); QueryBuilder builder = new MatchQueryBuilder("field1", queryBuilder.params().get("query_string")); - QueryShardContext qcontext = createShardContext(); + SearchExecutionContext qcontext = createSearchExecutionContext(); Query expected = Rewriteable.rewrite(builder, qcontext).toQuery(qcontext); assertEquals(expected, featureQuery); @@ -217,7 +217,7 @@ protected void doAssertLuceneQuery(StoredLtrQueryBuilder queryBuilder, assertTrue(ite.hasNext()); featureQuery = ite.next(); builder = new MatchQueryBuilder("field2", queryBuilder.params().get("query_string")); - qcontext = createShardContext(); + qcontext = createSearchExecutionContext(); expected = Rewriteable.rewrite(builder, qcontext).toQuery(qcontext); assertEquals(expected, featureQuery); assertTrue(ite.hasNext()); @@ -227,7 +227,7 @@ protected void doAssertLuceneQuery(StoredLtrQueryBuilder queryBuilder, .factor(1.2F) .modifier(FieldValueFactorFunction.Modifier.LN2P) .missing(0F)); - qcontext = createShardContext(); + qcontext = createSearchExecutionContext(); expected = Rewriteable.rewrite(builder, qcontext).toQuery(qcontext); assertEquals(expected, featureQuery); @@ -237,9 +237,9 @@ protected void doAssertLuceneQuery(StoredLtrQueryBuilder queryBuilder, @Override public void testCacheability() throws IOException { StoredLtrQueryBuilder queryBuilder = createTestQueryBuilder(); - QueryShardContext context = createShardContext(); + SearchExecutionContext context = createSearchExecutionContext(); assert context.isCacheable(); - QueryBuilder rewritten = rewriteQuery(queryBuilder, new QueryShardContext(context)); + QueryBuilder rewritten = rewriteQuery(queryBuilder, new SearchExecutionContext(context)); assertNotNull(rewritten.toQuery(context)); assertTrue("query should be cacheable: " + queryBuilder.toString(), context.isCacheable()); } diff --git a/src/test/java/com/o19s/es/ltr/query/ValidatingLtrQueryBuilderTests.java b/src/test/java/com/o19s/es/ltr/query/ValidatingLtrQueryBuilderTests.java index 68befa37..5c5deda8 100644 --- a/src/test/java/com/o19s/es/ltr/query/ValidatingLtrQueryBuilderTests.java +++ b/src/test/java/com/o19s/es/ltr/query/ValidatingLtrQueryBuilderTests.java @@ -29,7 +29,7 @@ import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.query.QueryShardContext; +import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.AbstractQueryTestCase; import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin; @@ -125,7 +125,8 @@ protected boolean supportsQueryName() { } @Override - protected void doAssertLuceneQuery(ValidatingLtrQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { + protected void doAssertLuceneQuery(ValidatingLtrQueryBuilder queryBuilder, Query query, + SearchExecutionContext context) throws IOException { if (StoredFeature.TYPE.equals(queryBuilder.getElement().type())) { assertThat(query, instanceOf(MatchNoDocsQuery.class)); } else if (StoredFeatureSet.TYPE.equals(queryBuilder.getElement().type())) { diff --git a/src/test/java/com/o19s/es/termstat/TermStatQueryBuilderTests.java b/src/test/java/com/o19s/es/termstat/TermStatQueryBuilderTests.java index a4f98d45..cdb725f1 100644 --- a/src/test/java/com/o19s/es/termstat/TermStatQueryBuilderTests.java +++ b/src/test/java/com/o19s/es/termstat/TermStatQueryBuilderTests.java @@ -5,7 +5,7 @@ import com.o19s.es.ltr.LtrQueryParserPlugin; import org.apache.lucene.search.Query; import org.elasticsearch.common.ParsingException; -import org.elasticsearch.index.query.QueryShardContext; +import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.AbstractQueryTestCase; import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin; @@ -69,7 +69,7 @@ public void testMissingExpr() throws Exception { } @Override - protected void doAssertLuceneQuery(TermStatQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { + protected void doAssertLuceneQuery(TermStatQueryBuilder queryBuilder, Query query, SearchExecutionContext context) throws IOException { assertThat(query, instanceOf(TermStatQuery.class)); } }