diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-09-08 15:17:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-08 15:17:30 +0200 |
commit | 35cae1a9c3af6237a8f507067391708f879fd241 (patch) | |
tree | 5d6d2e0056fcab572f97f7c259edf23fb55300b7 /container-search | |
parent | a9cf3c2e33969a66980d1a8cbbacbffeef92ccef (diff) |
Revert "Warmup yql"
Diffstat (limited to 'container-search')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java | 63 | ||||
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java | 5 |
2 files changed, 16 insertions, 52 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java b/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java index 21f8c15fdd4..940d6d51975 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java +++ b/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java @@ -2,9 +2,6 @@ package com.yahoo.search.yql; import com.google.common.annotations.Beta; -import com.google.inject.Inject; -import com.yahoo.language.Linguistics; -import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.Searcher; @@ -21,8 +18,6 @@ import com.yahoo.yolean.chain.After; import com.yahoo.yolean.chain.Before; import com.yahoo.yolean.chain.Provides; -import java.util.logging.Logger; - /** * Minimal combinator for YQL+ syntax and heuristically parsed user queries. * @@ -40,62 +35,44 @@ public class MinimalQueryInserter extends Searcher { private static final CompoundName MAX_HITS = new CompoundName("maxHits"); private static final CompoundName MAX_OFFSET = new CompoundName("maxOffset"); - private static Logger log = Logger.getLogger(MinimalQueryInserter.class.getName()); - @Inject - public MinimalQueryInserter(Linguistics linguistics) { - // Warmup is needed to avoid a large 400ms init cost during first execution of yql code. - warmup(linguistics); - } - MinimalQueryInserter() { - this(new SimpleLinguistics()); - } - static boolean warmup() { - return warmup(new SimpleLinguistics()); - } - private static boolean warmup(Linguistics linguistics) { - Query query = new Query("search/?yql=select%20*%20from%20sources%20where%20title%20contains%20'xyz';"); - Result result = insertQuery(query, new ParserEnvironment().setLinguistics(linguistics)); - if (result != null) { - log.warning("Warmup code trigger an error. Error = " + result.toString()); - return false; - } - if ( ! "select * from sources where title contains \"xyz\";".equals(query.yqlRepresentation())) { - log.warning("Warmup code generated unexpected yql: " + query.yqlRepresentation()); - return false; - } - return true; - } + @Override + public Result search(Query query, Execution execution) { + if (query.properties().get(YQL) == null) return execution.search(query); - private static Result insertQuery(Query query, ParserEnvironment env) { + ParserEnvironment env = ParserEnvironment.fromExecutionContext(execution.context()); YqlParser parser = (YqlParser) ParserFactory.newInstance(Query.Type.YQL, env); parser.setQueryParser(false); parser.setUserQuery(query); QueryTree newTree; try { - Parsable parsable = Parsable.fromQueryModel(query.getModel()).setQuery(query.properties().getString(YQL)); - newTree = parser.parse(parsable); + newTree = parser.parse(Parsable.fromQueryModel(query.getModel()) + .setQuery(query.properties().getString(YQL))); } catch (RuntimeException e) { - return new Result(query, ErrorMessage.createInvalidQueryParameter("Could not instantiate query from YQL", e)); + return new Result(query, ErrorMessage.createInvalidQueryParameter( + "Could not instantiate query from YQL", e)); } if (parser.getOffset() != null) { int maxHits = query.properties().getInteger(MAX_HITS); int maxOffset = query.properties().getInteger(MAX_OFFSET); if (parser.getOffset() > maxOffset) { return new Result(query, ErrorMessage.createInvalidQueryParameter("Requested offset " + parser.getOffset() - + ", but the max offset allowed is " + maxOffset + ".")); + + ", but the max offset allowed is " + + maxOffset + ".")); } if (parser.getHits() > maxHits) { return new Result(query, ErrorMessage.createInvalidQueryParameter("Requested " + parser.getHits() - + " hits returned, but max hits allowed is " + maxHits + ".")); + + " hits returned, but max hits allowed is " + + maxHits + ".")); + } } query.getModel().getQueryTree().setRoot(newTree.getRoot()); query.getPresentation().getSummaryFields().addAll(parser.getYqlSummaryFields()); for (VespaGroupingStep step : parser.getGroupingSteps()) { GroupingRequest.newInstance(query) - .setRootOperation(step.getOperation()) - .continuations().addAll(step.continuations()); + .setRootOperation(step.getOperation()) + .continuations().addAll(step.continuations()); } if (parser.getYqlSources().size() == 0) { query.getModel().getSources().clear(); @@ -113,15 +90,7 @@ public class MinimalQueryInserter extends Searcher { query.getRanking().setSorting(parser.getSorting()); } query.trace("YQL+ query parsed", true, 2); - return null; - } - - @Override - public Result search(Query query, Execution execution) { - if (query.properties().get(YQL) == null) return execution.search(query); - - Result result = insertQuery(query, ParserEnvironment.fromExecutionContext(execution.context())); - return (result == null) ? execution.search(query) : result; + return execution.search(query); } } diff --git a/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java b/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java index d832ba52ceb..22c17f556c8 100644 --- a/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java @@ -341,11 +341,6 @@ public class MinimalQueryInserterTestCase { query.yqlRepresentation()); } - @Test - public void verifyThatWarmupIsSane() { - assertTrue(MinimalQueryInserter.warmup()); - } - private static void assertGrouping(String expected, Query query) { List<String> actual = new ArrayList<>(); |