use of com.yahoo.collections.Pair in project vespa by vespa-engine.
the class RankingExpressionShadowingTestCase method testMultiLevelMacroShadowing.
@Test
public void testMultiLevelMacroShadowing() throws ParseException {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
SearchBuilder builder = new SearchBuilder(rankProfileRegistry);
builder.importString("search test {\n" + " document test { \n" + " field a type string { \n" + " indexing: index \n" + " }\n" + " }\n" + " \n" + " rank-profile test {\n" + " macro tan(x) {\n" + " expression: x * x\n" + " }\n" + " macro cos(x) {\n" + " expression: tan(x)\n" + " }\n" + " macro sin(x) {\n" + " expression: cos(x)\n" + " }\n" + " first-phase {\n" + " expression: sin(2)\n" + " }\n" + " }\n" + "\n" + "}\n");
builder.build();
Search s = builder.getSearch();
RankProfile test = rankProfileRegistry.getRankProfile(s, "test").compile(new QueryProfileRegistry());
List<Pair<String, String>> testRankProperties = new RawRankProfile(test, new QueryProfileRegistry(), new AttributeFields(s)).configProperties();
assertEquals("(rankingExpression(tan).rankingScript,x * x)", testRankProperties.get(0).toString());
assertEquals("(rankingExpression(tan@).rankingScript,x * x)", censorBindingHash(testRankProperties.get(1).toString()));
assertEquals("(rankingExpression(cos).rankingScript,rankingExpression(tan@))", censorBindingHash(testRankProperties.get(2).toString()));
assertEquals("(rankingExpression(cos@).rankingScript,rankingExpression(tan@))", censorBindingHash(testRankProperties.get(3).toString()));
assertEquals("(rankingExpression(sin).rankingScript,rankingExpression(cos@))", censorBindingHash(testRankProperties.get(4).toString()));
assertEquals("(rankingExpression(tan@).rankingScript,2 * 2)", censorBindingHash(testRankProperties.get(5).toString()));
assertEquals("(rankingExpression(cos@).rankingScript,rankingExpression(tan@))", censorBindingHash(testRankProperties.get(6).toString()));
assertEquals("(rankingExpression(sin@).rankingScript,rankingExpression(cos@))", censorBindingHash(testRankProperties.get(7).toString()));
assertEquals("(vespa.rank.firstphase,rankingExpression(sin@))", censorBindingHash(testRankProperties.get(8).toString()));
}
use of com.yahoo.collections.Pair in project vespa by vespa-engine.
the class RankingExpressionShadowingTestCase method testBasicMacroShadowing.
@Test
public void testBasicMacroShadowing() throws ParseException {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
SearchBuilder builder = new SearchBuilder(rankProfileRegistry);
builder.importString("search test {\n" + " document test { \n" + " field a type string { \n" + " indexing: index \n" + " }\n" + " }\n" + " \n" + " rank-profile test {\n" + " macro sin(x) {\n" + " expression: x * x\n" + " }\n" + " first-phase {\n" + " expression: sin(2)\n" + " }\n" + " }\n" + "\n" + "}\n");
builder.build();
Search s = builder.getSearch();
RankProfile test = rankProfileRegistry.getRankProfile(s, "test").compile(new QueryProfileRegistry());
List<Pair<String, String>> testRankProperties = new RawRankProfile(test, new QueryProfileRegistry(), new AttributeFields(s)).configProperties();
assertEquals("(rankingExpression(sin).rankingScript,x * x)", testRankProperties.get(0).toString());
assertEquals("(rankingExpression(sin@).rankingScript,2 * 2)", censorBindingHash(testRankProperties.get(1).toString()));
assertEquals("(vespa.rank.firstphase,rankingExpression(sin@))", censorBindingHash(testRankProperties.get(2).toString()));
}
use of com.yahoo.collections.Pair in project vespa by vespa-engine.
the class ValidationTester method deploy.
/**
* Deploys an application
*
* @param previousModel the previous model, or null if no previous
* @param services the services file content
* @param validationOverrides the validation overrides file content, or null if none
* @return the new model and any change actions
*/
public Pair<VespaModel, List<ConfigChangeAction>> deploy(VespaModel previousModel, String services, String validationOverrides) {
Instant now = LocalDate.parse("2000-01-01", DateTimeFormatter.ISO_DATE).atStartOfDay().atZone(ZoneOffset.UTC).toInstant();
ApplicationPackage newApp = new MockApplicationPackage.Builder().withServices(services).withSearchDefinition(MockApplicationPackage.MUSIC_SEARCHDEFINITION).withValidationOverrides(validationOverrides).build();
VespaModelCreatorWithMockPkg newModelCreator = new VespaModelCreatorWithMockPkg(newApp);
DeployState.Builder deployStateBuilder = new DeployState.Builder().applicationPackage(newApp).properties(new DeployProperties.Builder().hostedVespa(true).build()).modelHostProvisioner(new InMemoryProvisioner(nodeCount)).now(now);
if (previousModel != null)
deployStateBuilder.previousModel(previousModel);
VespaModel newModel = newModelCreator.create(deployStateBuilder);
return new Pair<>(newModel, newModelCreator.configChangeActions);
}
use of com.yahoo.collections.Pair in project vespa by vespa-engine.
the class TensorTransformTestCase method buildSearch.
private List<Pair<String, String>> buildSearch(String expression) throws ParseException {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
QueryProfileRegistry queryProfiles = setupQueryProfileTypes();
SearchBuilder builder = new SearchBuilder(rankProfileRegistry, queryProfiles);
builder.importString("search test {\n" + " document test { \n" + " field double_field type double { \n" + " indexing: summary | attribute \n" + " }\n" + " field double_array_field type array<double> { \n" + " indexing: summary | attribute \n" + " }\n" + " field weightedset_field type weightedset<double> { \n" + " indexing: summary | attribute \n" + " }\n" + " field tensor_field_1 type tensor(x{}) { \n" + " indexing: summary | attribute \n" + " attribute: tensor(x{}) \n" + " }\n" + " field tensor_field_2 type tensor(x[3],y[3]) { \n" + " indexing: summary | attribute \n" + " attribute: tensor(x[3],y[3]) \n" + " }\n" + " }\n" + " constant file_constant_tensor {\n" + " file: constants/tensor.json\n" + " type: tensor(x{})\n" + " }\n" + " rank-profile base {\n" + " constants {\n" + " base_constant_tensor {\n" + " value: { {x:0}:0 }\n" + " }\n" + " }\n" + " macro base_tensor() {\n" + " expression: constant(base_constant_tensor)\n" + " }\n" + " }\n" + " rank-profile test inherits base {\n" + " constants {\n" + " test_constant_tensor {\n" + " value: { {x:0}:1 }\n" + " }\n" + " }\n" + " macro returns_tensor_with_arg(arg1) {\n" + " expression: 2.0 * arg1\n" + " }\n" + " macro wraps_returns_tensor() {\n" + " expression: returns_tensor\n" + " }\n" + " macro returns_tensor() {\n" + " expression: attribute(tensor_field_2)\n" + " }\n" + " macro tensor_inheriting() {\n" + " expression: base_tensor\n" + " }\n" + " macro testexpression() {\n" + " expression: " + expression + "\n" + " }\n" + " }\n" + "}\n");
builder.build(true, new BaseDeployLogger());
Search s = builder.getSearch();
RankProfile test = rankProfileRegistry.getRankProfile(s, "test").compile(queryProfiles);
List<Pair<String, String>> testRankProperties = new RawRankProfile(test, queryProfiles, new AttributeFields(s)).configProperties();
return testRankProperties;
}
use of com.yahoo.collections.Pair in project vespa by vespa-engine.
the class FederationSearcher method fill.
@Override
public void fill(Result result, String summaryClass, Execution execution) {
UniqueExecutionsToResults uniqueExecutionsToResults = new UniqueExecutionsToResults();
addResultsToFill(result.hits(), result, summaryClass, uniqueExecutionsToResults);
Set<Entry<Chain<Searcher>, Map<Query, Result>>> resultsForAllChains = uniqueExecutionsToResults.resultsToFill.entrySet();
int numberOfCallsToFillNeeded = 0;
for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
numberOfCallsToFillNeeded += resultsToFillForAChain.getValue().size();
}
List<Pair<Result, FutureResult>> futureFilledResults = new ArrayList<>();
for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
Chain<Searcher> chain = resultsToFillForAChain.getKey();
Execution chainExecution = (chain == null) ? execution : new Execution(chain, execution.context());
for (Entry<Query, Result> resultsToFillForAChainAndQuery : resultsToFillForAChain.getValue().entrySet()) {
Result resultToFill = resultsToFillForAChainAndQuery.getValue();
if (numberOfCallsToFillNeeded == 1) {
chainExecution.fill(resultToFill, summaryClass);
propagateErrors(resultToFill, result);
} else {
AsyncExecution asyncFill = new AsyncExecution(chainExecution);
futureFilledResults.add(new Pair<>(resultToFill, asyncFill.fill(resultToFill, summaryClass)));
}
}
}
for (Pair<Result, FutureResult> futureFilledResult : futureFilledResults) {
// futureFilledResult is a pair of a result to be filled and the future in which that same result is filled
Optional<Result> filledResult = futureFilledResult.getSecond().getIfAvailable(result.getQuery().getTimeLeft(), TimeUnit.MILLISECONDS);
if (filledResult.isPresent()) {
// fill completed
propagateErrors(filledResult.get(), result);
} else {
// fill timed out: Remove these hits as they are incomplete and may cause a race when accessed later
result.hits().addError(futureFilledResult.getSecond().createTimeoutError());
for (Iterator<Hit> i = futureFilledResult.getFirst().hits().unorderedDeepIterator(); i.hasNext(); ) {
// Note that some of these hits may be filled, but as the fill thread may still be working on them
// and we do not synchronize with it we need to discard all
Hit removed = result.hits().remove(i.next().getId());
}
}
}
}
Aggregations