Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbergmann2018-09-06 15:47:17 +0000
committerZoltan Ujhelyi2018-09-18 15:09:54 +0000
commit18aea31800f655139335c6bdb6a1d855aae85c43 (patch)
tree7e92595346178e7c4895e273f7fab147dd73c649
parent99bc73ac27cfcc08699aebb8f7c762340d982b01 (diff)
downloadorg.eclipse.viatra-18aea31800f655139335c6bdb6a1d855aae85c43.tar.gz
org.eclipse.viatra-18aea31800f655139335c6bdb6a1d855aae85c43.tar.xz
org.eclipse.viatra-18aea31800f655139335c6bdb6a1d855aae85c43.zip
[538742] Better control of LS pattern calls and hybridness
Change-Id: Iac31a930be3ff677e5780de408e53a4cff49ff9e Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=538742 Signed-off-by: bergmann <bergmann@mit.bme.hu>
-rw-r--r--documentation/org.eclipse.viatra.documentation.help/src/main/asciidoc/releases/viatra-2.1.adoc12
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/.settings/.api_filters64
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/CallWithAdornment.java57
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java34
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/AbstractLocalSearchResultProvider.java42
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/DontFlattenDisjunctive.java31
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/IAdornmentProvider.java13
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchBackend.java19
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchEMFBackendFactory.java5
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchGenericBackendFactory.java5
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchHintOptions.java9
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchHints.java61
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/AggregatorCheck.java2
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/BinaryTransitiveClosureCheck.java2
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/CheckPositivePatternCall.java2
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/CountCheck.java2
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/NACOperation.java2
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/AggregatorExtend.java2
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/CountOperation.java2
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendBinaryTransitiveClosure.java2
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendPositivePatternCall.java2
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/util/CallInformation.java34
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/IPlanProvider.java7
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/SearchPlanForBody.java7
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/SimplePlanProvider.java7
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchPlanner.java10
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchRuntimeBasedStrategy.java7
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/PConstraintInfo.java13
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/PConstraintInfoInferrer.java7
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/compiler/AbstractOperationCompiler.java32
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/compiler/IOperationCompiler.java7
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/IConstraintEvaluationContext.java8
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/impl/HybridMatcherConstraintCostFunction.java2
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/impl/StatisticsBasedConstraintCostFunction.java2
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.matchers/.settings/.api_filters8
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/ICallDelegationStrategy.java91
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/IQueryBackend.java6
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/ResultProviderRequestor.java76
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/psystem/rewriters/IFlattenCallPredicate.java21
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.rete/src/org/eclipse/viatra/query/runtime/rete/matcher/ReteEngine.java6
-rw-r--r--query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/FlattenerPredicateTest.xtend2
-rw-r--r--query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/LocalSearchPlanCostOverflowTest.xtend5
42 files changed, 638 insertions, 90 deletions
diff --git a/documentation/org.eclipse.viatra.documentation.help/src/main/asciidoc/releases/viatra-2.1.adoc b/documentation/org.eclipse.viatra.documentation.help/src/main/asciidoc/releases/viatra-2.1.adoc
index fb347de4e..71aadf572 100644
--- a/documentation/org.eclipse.viatra.documentation.help/src/main/asciidoc/releases/viatra-2.1.adoc
+++ b/documentation/org.eclipse.viatra.documentation.help/src/main/asciidoc/releases/viatra-2.1.adoc
@@ -20,6 +20,16 @@ The severity of missing variable types is increased to warning. The reason for t
TODO
== Migrating to VIATRA 2.1
+
+=== Conflict Resolution between Transformation Rules
+
The default rule priority in InvertedDisappearancePriorityConflictResolver was changed in version 2.1 from 0 to 1. This change was motivated by the fact that in case of 0 priority additions and deletions would have the same priority that is in contrast with the goal of the resolver.
-This is a breaking change as transformations using both priority '0' and '1' might change their internal behavior. To avoid this, it is recommended not to use priority '0' at all with this conflict resolver. \ No newline at end of file
+This is a breaking change as transformations using both priority '0' and '1' might change their internal behavior. To avoid this, it is recommended not to use priority '0' at all with this conflict resolver.
+
+=== Changed hybridization behaviour in the Local Search Query Backend
+
+To make behaviour more predictable, the default configuration of the Local Search query engine no longer allows hybrid pattern matching in conjuction with the incremental query backend across pattern calls, i.e. if the caller pattern is evaluated with LS, so will the callee pattern during the same matcher invocation. To enable hybrid matching, where the local search backend may request results of called patterns from the incremental backend (in case the callee is declared `incremental pattern`), use configurations that explicitly enable this, such as `LocalSearchHints.getDefaultGenericHybrid()`.
+
+
+
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/.settings/.api_filters b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/.settings/.api_filters
index fbefb523c..0d880f57d 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/.settings/.api_filters
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/.settings/.api_filters
@@ -1,6 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.viatra.query.runtime.localsearch" version="2">
+ <resource path="src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java" type="org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext">
+ <filter id="405901410">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext"/>
+ <message_argument value="getMatcher(MatcherReference)"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java" type="org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext$SearchContext">
+ <filter id="338722907">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext.SearchContext"/>
+ <message_argument value="SearchContext(IQueryBackendContext, QueryEvaluationHint, ICache)"/>
+ </message_arguments>
+ </filter>
+ <filter id="338792546">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext.SearchContext"/>
+ <message_argument value="getMatcher(MatcherReference)"/>
+ </message_arguments>
+ </filter>
<filter comment="Internal API implementation" id="576725006">
<message_arguments>
<message_argument value="ISearchContext"/>
@@ -45,7 +65,51 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/viatra/query/runtime/localsearch/plan/IPlanProvider.java" type="org.eclipse.viatra.query.runtime.localsearch.plan.IPlanProvider">
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.plan.IPlanProvider"/>
+ <message_argument value="getPlan(IQueryBackendContext, IOperationCompiler, ResultProviderRequestor, LocalSearchHints, MatcherReference)"/>
+ </message_arguments>
+ </filter>
+ <filter id="405901410">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.plan.IPlanProvider"/>
+ <message_argument value="getPlan(IQueryBackendContext, IOperationCompiler, LocalSearchHints, MatcherReference)"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/viatra/query/runtime/localsearch/plan/SimplePlanProvider.java" type="org.eclipse.viatra.query.runtime.localsearch.plan.SimplePlanProvider">
+ <filter id="338792546">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.plan.SimplePlanProvider"/>
+ <message_argument value="getPlan(IQueryBackendContext, IOperationCompiler, LocalSearchHints, MatcherReference)"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchPlanner.java" type="org.eclipse.viatra.query.runtime.localsearch.planner.LocalSearchPlanner">
+ <filter id="338722907">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.planner.LocalSearchPlanner"/>
+ <message_argument value="LocalSearchPlanner(IQueryBackendContext, IOperationCompiler, Logger, LocalSearchHints)"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchRuntimeBasedStrategy.java" type="org.eclipse.viatra.query.runtime.localsearch.planner.LocalSearchRuntimeBasedStrategy">
+ <filter id="338792546">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.planner.LocalSearchRuntimeBasedStrategy"/>
+ <message_argument value="plan(PBody, Set&lt;PVariable&gt;, IQueryBackendContext, LocalSearchHints)"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/viatra/query/runtime/localsearch/planner/PConstraintInfo.java" type="org.eclipse.viatra.query.runtime.localsearch.planner.PConstraintInfo">
+ <filter id="338722907">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.planner.PConstraintInfo"/>
+ <message_argument value="PConstraintInfo(PConstraint, Set&lt;PVariable&gt;, Set&lt;PVariable&gt;, Set&lt;PConstraintInfo&gt;, IQueryBackendContext, Function&lt;IConstraintEvaluationContext,Double&gt;)"/>
+ </message_arguments>
+ </filter>
<filter comment="Internal API implementation" id="576725006">
<message_arguments>
<message_argument value="IConstraintEvaluationContext"/>
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/CallWithAdornment.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/CallWithAdornment.java
new file mode 100644
index 000000000..2be2eb88e
--- /dev/null
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/CallWithAdornment.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2018, Gabor Bergmann, IncQuery Labs Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Gabor Bergmann - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.viatra.query.runtime.localsearch.matcher;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.viatra.query.runtime.matchers.psystem.IQueryReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery;
+
+/**
+ * Immutable data that represents the role of a pattern call within an LS query plan.
+ *
+ * <p> The call is expressed as the {@link PConstraint} {@link #call} (implementing {@link IQueryReference}),
+ * while the stored {@link #adornment} records the way it will be used within a search plan (specifically,
+ * pattern parameters within the adornment will have their values known at the point of evaluating the constraint).
+ *
+ *
+ * @author Gabor Bergmann
+ * @since 2.1
+ */
+public class CallWithAdornment {
+ private final IQueryReference call;
+ private final Set<PParameter> adornment;
+
+ public CallWithAdornment(IQueryReference call, Set<PParameter> adornment) {
+ this.call = call;
+ this.adornment = new HashSet<>(adornment);
+ }
+
+ public IQueryReference getCall() {
+ return call;
+ }
+
+ public Set<PParameter> getAdornment() {
+ return adornment;
+ }
+
+
+ public PQuery getReferredQuery() {
+ return call.getReferredQuery();
+ }
+
+ public MatcherReference getMatcherReference() {
+ return new MatcherReference(getReferredQuery(), adornment);
+ }
+}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java
index 58deaf9be..af9b8a74f 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java
@@ -20,14 +20,10 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.viatra.query.runtime.base.api.IndexingLevel;
import org.eclipse.viatra.query.runtime.base.api.NavigationHelper;
import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.IAdornmentProvider;
-import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHintOptions;
import org.eclipse.viatra.query.runtime.matchers.ViatraQueryRuntimeException;
import org.eclipse.viatra.query.runtime.matchers.backend.IQueryResultProvider;
-import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
-import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint.BackendRequirement;
-import org.eclipse.viatra.query.runtime.matchers.backend.QueryHintOption;
+import org.eclipse.viatra.query.runtime.matchers.backend.ResultProviderRequestor;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext;
-import org.eclipse.viatra.query.runtime.matchers.context.IQueryResultProviderAccess;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext;
import org.eclipse.viatra.query.runtime.matchers.util.ICache;
import org.eclipse.viatra.query.runtime.matchers.util.IProvider;
@@ -59,11 +55,10 @@ public interface ISearchContext {
/**
* Returns a matcher for a selected query specification.
*
- * @param reference
* @throws ViatraQueryRuntimeException
* @since 1.5
*/
- IQueryResultProvider getMatcher(MatcherReference reference);
+ IQueryResultProvider getMatcher(CallWithAdornment dependency);
/**
* Allows search operations to cache values through the entire lifecycle of the local search backend. The values are
@@ -88,22 +83,21 @@ public interface ISearchContext {
public class SearchContext implements ISearchContext {
private final NavigationHelper navigationHelper;
- private final IQueryResultProviderAccess resultProviderAccess;
- private final QueryEvaluationHint overrideHints;
private final IQueryRuntimeContext runtimeContext;
private final ICache backendLevelCache;
private final Logger logger;
+ private final ResultProviderRequestor resultProviderRequestor;
/**
* Initializes a search context using an arbitrary backend context
*/
- public SearchContext(IQueryBackendContext backendContext, QueryEvaluationHint overrideHints, ICache backendLevelCache) {
+ public SearchContext(IQueryBackendContext backendContext, ICache backendLevelCache,
+ ResultProviderRequestor resultProviderRequestor) {
+ this.resultProviderRequestor = resultProviderRequestor;
this.runtimeContext = backendContext.getRuntimeContext();
this.logger = backendContext.getLogger();
this.navigationHelper = null;
- this.resultProviderAccess = backendContext.getResultProviderAccess();
- this.overrideHints = overrideHints;
this.backendLevelCache = backendLevelCache;
}
@@ -118,23 +112,19 @@ public interface ISearchContext {
/**
* @throws ViatraQueryRuntimeException
- * @since 1.5
+ * @since 2.1
*/
@Override
- public IQueryResultProvider getMatcher(final MatcherReference reference) {
+ public IQueryResultProvider getMatcher(CallWithAdornment dependency) {
// Inject adornment for referenced pattern
IAdornmentProvider adornmentProvider = query -> {
- if (query.equals(reference.query)){
- return Collections.singleton(reference.adornment);
+ if (query.equals(dependency.getReferredQuery())){
+ return Collections.singleton(dependency.getAdornment());
}
return Collections.emptySet();
};
- QueryEvaluationHint hints = new QueryEvaluationHint(Collections.<QueryHintOption<?>, Object>singletonMap(LocalSearchHintOptions.ADORNMENT_PROVIDER, adornmentProvider), BackendRequirement.UNSPECIFIED);
- if (overrideHints != null){
- hints = overrideHints.overrideBy(hints);
- }
-
- return resultProviderAccess.getResultProvider(reference.getQuery(), hints);
+ return resultProviderRequestor.requestResultProvider(dependency.getCall(),
+ IAdornmentProvider.toHint(adornmentProvider));
}
@Override
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/AbstractLocalSearchResultProvider.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/AbstractLocalSearchResultProvider.java
index 1a26dd93a..f4912810d 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/AbstractLocalSearchResultProvider.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/AbstractLocalSearchResultProvider.java
@@ -25,6 +25,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.viatra.query.runtime.localsearch.exceptions.LocalSearchException;
+import org.eclipse.viatra.query.runtime.localsearch.matcher.CallWithAdornment;
import org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext;
import org.eclipse.viatra.query.runtime.localsearch.matcher.LocalSearchMatcher;
import org.eclipse.viatra.query.runtime.localsearch.matcher.MatcherReference;
@@ -39,13 +40,14 @@ import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackend;
import org.eclipse.viatra.query.runtime.matchers.backend.IQueryResultProvider;
import org.eclipse.viatra.query.runtime.matchers.backend.IUpdateable;
import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
-import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint.BackendRequirement;
import org.eclipse.viatra.query.runtime.matchers.backend.QueryHintOption;
+import org.eclipse.viatra.query.runtime.matchers.backend.ResultProviderRequestor;
import org.eclipse.viatra.query.runtime.matchers.context.IInputKey;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext;
import org.eclipse.viatra.query.runtime.matchers.context.IndexingService;
import org.eclipse.viatra.query.runtime.matchers.planning.QueryProcessingException;
+import org.eclipse.viatra.query.runtime.matchers.psystem.IQueryReference;
import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
@@ -73,6 +75,10 @@ public abstract class AbstractLocalSearchResultProvider implements IQueryResultP
private static final String PLAN_CACHE_KEY = AbstractLocalSearchResultProvider.class.getName() + "#planCache";
private final Map<MatcherReference, IPlanDescriptor> planCache;
protected final ISearchContext searchContext;
+ /**
+ * @since 2.1
+ */
+ protected ResultProviderRequestor resultProviderRequestor;
/**
* @since 1.5
@@ -87,7 +93,8 @@ public abstract class AbstractLocalSearchResultProvider implements IQueryResultP
this.planProvider = planProvider;
this.userHints = userHints;
this.runtimeContext = context.getRuntimeContext();
- this.searchContext = new ISearchContext.SearchContext(backendContext, userHints, backend.getCache());
+ this.resultProviderRequestor = backend.getResultProviderRequestor(query, userHints);
+ this.searchContext = new ISearchContext.SearchContext(backendContext, backend.getCache(), resultProviderRequestor);
this.planCache = backend.getCache().getValue(PLAN_CACHE_KEY, Map.class, HashMap::new);
}
@@ -109,7 +116,8 @@ public abstract class AbstractLocalSearchResultProvider implements IQueryResultP
if (planCache.containsKey(key)){
return planCache.get(key);
} else {
- IPlanDescriptor plan = planProvider.getPlan(backendContext, compiler, configuration, key);
+ IPlanDescriptor plan = planProvider.getPlan(backendContext, compiler,
+ resultProviderRequestor, configuration, key);
planCache.put(key, plan);
return plan;
}
@@ -121,7 +129,8 @@ public abstract class AbstractLocalSearchResultProvider implements IQueryResultP
} else {
LocalSearchHints configuration = overrideDefaultHints(key.getQuery());
IOperationCompiler compiler = getOperationCompiler(backendContext, configuration);
- IPlanDescriptor plan = planProvider.getPlan(backendContext, compiler, configuration, key);
+ IPlanDescriptor plan = planProvider.getPlan(backendContext, compiler,
+ resultProviderRequestor, configuration, key);
planCache.put(key, plan);
return plan;
}
@@ -179,7 +188,7 @@ public abstract class AbstractLocalSearchResultProvider implements IQueryResultP
}
//Prepare dependencies
for(SearchPlanForBody body: plan.getPlan()){
- for(MatcherReference dependency : body.getDependencies()){
+ for(CallWithAdornment dependency : body.getDependencies()){
searchContext.getMatcher(dependency);
}
}
@@ -189,9 +198,10 @@ public abstract class AbstractLocalSearchResultProvider implements IQueryResultP
protected void prepareDirectDependencies() {
// Do not prepare for any adornment at this point
IAdornmentProvider adornmentProvider = input -> Collections.emptySet();
- QueryEvaluationHint hints = new QueryEvaluationHint(Collections.singletonMap(LocalSearchHintOptions.ADORNMENT_PROVIDER, adornmentProvider), BackendRequirement.UNSPECIFIED);
- for(PQuery dep : getDirectPositiveDependencies()){
- backendContext.getResultProviderAccess().getResultProvider(dep, hints);
+ QueryEvaluationHint adornmentHint = IAdornmentProvider.toHint(adornmentProvider);
+
+ for(IQueryReference call : getDirectDependencies()){
+ resultProviderRequestor.requestResultProvider(call, adornmentHint);
}
}
@@ -216,25 +226,27 @@ public abstract class AbstractLocalSearchResultProvider implements IQueryResultP
);
}
- private Set<PQuery> getDirectPositiveDependencies() {
+ private Set<IQueryReference> getDirectDependencies() {
IFlattenCallPredicate flattenPredicate = overrideDefaultHints(query).getFlattenCallPredicate();
Queue<PQuery> queue = new LinkedList<>();
Set<PQuery> visited = new HashSet<>();
- Set<PQuery> result = new HashSet<>();
+ Set<IQueryReference> result = new HashSet<>();
queue.add(query);
while(!queue.isEmpty()){
PQuery next = queue.poll();
visited.add(next);
for(PBody body : next.getDisjunctBodies().getBodies()){
- for(PositivePatternCall ppc : body.getConstraintsOfType(PositivePatternCall.class)){
- PQuery dep = ppc.getSupplierKey();
- if (flattenPredicate.shouldFlatten(ppc)){
+ for (IQueryReference call : body.getConstraintsOfType(IQueryReference.class)) {
+ if (call instanceof PositivePatternCall &&
+ flattenPredicate.shouldFlatten((PositivePatternCall) call))
+ {
+ PQuery dep = ((PositivePatternCall) call).getReferredQuery();
if (!visited.contains(dep)){
queue.add(dep);
}
- }else{
- result.add(dep);
+ } else {
+ result.add(call);
}
}
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/DontFlattenDisjunctive.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/DontFlattenDisjunctive.java
new file mode 100644
index 000000000..aed5df5ee
--- /dev/null
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/DontFlattenDisjunctive.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2018, Gabor Bergmann, IncQuery Labs Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Gabor Bergmann - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.viatra.query.runtime.localsearch.matcher.integration;
+
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
+import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.IFlattenCallPredicate;
+
+/**
+ * Forbids flattening of patterns that have more than one body.
+ *
+ * @since 2.1
+
+ * @author Gabor Bergmann
+ *
+ */
+public class DontFlattenDisjunctive implements IFlattenCallPredicate {
+
+ @Override
+ public boolean shouldFlatten(PositivePatternCall positivePatternCall) {
+ return 1 >= positivePatternCall.getReferredQuery().getDisjunctBodies().getBodies().size();
+ }
+
+}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/IAdornmentProvider.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/IAdornmentProvider.java
index 79fd3e6e5..1bedd8edf 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/IAdornmentProvider.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/IAdornmentProvider.java
@@ -10,8 +10,11 @@
*******************************************************************************/
package org.eclipse.viatra.query.runtime.localsearch.matcher.integration;
+import java.util.Collections;
import java.util.Set;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint.BackendRequirement;
import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery;
@@ -56,4 +59,14 @@ public interface IAdornmentProvider {
*/
public Iterable<Set<PParameter>> getAdornments(PQuery query);
+ /**
+ * @return a simple hint that only overrides the adornment provider
+ * @since 2.1
+ */
+ public static QueryEvaluationHint toHint(IAdornmentProvider adornmentProvider) {
+ return new QueryEvaluationHint(
+ Collections.singletonMap(LocalSearchHintOptions.ADORNMENT_PROVIDER, adornmentProvider),
+ BackendRequirement.UNSPECIFIED);
+ }
+
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchBackend.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchBackend.java
index cd2a869b9..0d3fc9fdb 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchBackend.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchBackend.java
@@ -30,6 +30,7 @@ import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackend;
import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendHintProvider;
import org.eclipse.viatra.query.runtime.matchers.backend.IQueryResultProvider;
import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.backend.ResultProviderRequestor;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext;
import org.eclipse.viatra.query.runtime.matchers.psystem.analysis.QueryAnalyzer;
@@ -97,6 +98,24 @@ public abstract class LocalSearchBackend implements IQueryBackend {
}
/**
+ * Returns a requestor that this backend uses while processing pattern calls <i>from</i> this query.
+ * @noreference This method is not intended to be referenced by clients.
+ * @since 2.1
+ */
+ public ResultProviderRequestor getResultProviderRequestor(PQuery query, QueryEvaluationHint userHints) {
+ QueryEvaluationHint hintOnQuery =
+ context.getHintProvider().getQueryEvaluationHint(query).overrideBy(userHints);
+ LocalSearchHints defaultsApplied = LocalSearchHints.getDefaultOverriddenBy(hintOnQuery);
+
+ return new ResultProviderRequestor(this,
+ context.getResultProviderAccess(),
+ context.getHintProvider(),
+ defaultsApplied.getCallDelegationStrategy(),
+ userHints,
+ /* no global overrides */ null);
+ }
+
+ /**
* @throws ViatraQueryRuntimeException
* @since 1.7
*/
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchEMFBackendFactory.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchEMFBackendFactory.java
index a6aa666a0..f8226a362 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchEMFBackendFactory.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchEMFBackendFactory.java
@@ -38,6 +38,11 @@ public enum LocalSearchEMFBackendFactory implements IQueryBackendFactory {
protected AbstractLocalSearchResultProvider initializeResultProvider(PQuery query, QueryEvaluationHint hints) {
return new LocalSearchResultProvider(this, context, query, planProvider, hints);
}
+
+ @Override
+ public IQueryBackendFactory getFactory() {
+ return INSTANCE;
+ }
};
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchGenericBackendFactory.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchGenericBackendFactory.java
index ef874a7b8..174c69657 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchGenericBackendFactory.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchGenericBackendFactory.java
@@ -38,6 +38,11 @@ public enum LocalSearchGenericBackendFactory implements IQueryBackendFactory {
return new GenericLocalSearchResultProvider(this, context, query, planProvider, hints);
}
+ @Override
+ public IQueryBackendFactory getFactory() {
+ return INSTANCE;
+ }
+
};
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchHintOptions.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchHintOptions.java
index e7f806d57..c41038103 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchHintOptions.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchHintOptions.java
@@ -12,8 +12,10 @@ package org.eclipse.viatra.query.runtime.localsearch.matcher.integration;
import org.eclipse.viatra.query.runtime.localsearch.planner.cost.ICostFunction;
import org.eclipse.viatra.query.runtime.localsearch.planner.cost.impl.IndexerBasedConstraintCostFunction;
+import org.eclipse.viatra.query.runtime.matchers.backend.ICallDelegationStrategy;
import org.eclipse.viatra.query.runtime.matchers.backend.QueryHintOption;
import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.IFlattenCallPredicate;
+import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.NeverFlattenCallPredicate;
/**
*
@@ -45,6 +47,13 @@ public final class LocalSearchHintOptions {
*/
public static final QueryHintOption<IFlattenCallPredicate> FLATTEN_CALL_PREDICATE =
hintOption("FLATTEN_CALL_PREDICATE", new DontFlattenIncrementalPredicate());
+ /**
+ * Strategy to decide how hints (most importantly, backend selection) propagate across pattern calls.
+ * Must implement {@link ICallDelegationStrategy}.
+ * @since 2.1
+ */
+ public static final QueryHintOption<ICallDelegationStrategy> CALL_DELEGATION_STRATEGY =
+ hintOption("CALL_DELEGATION_STRATEGY", ICallDelegationStrategy.FULL_BACKEND_ADHESION);
/**
* A provider of expected adornments {@link IAdornmentProvider}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchHints.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchHints.java
index 079d7c648..87d9fb3da 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchHints.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchHints.java
@@ -11,6 +11,7 @@
package org.eclipse.viatra.query.runtime.localsearch.matcher.integration;
import static org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHintOptions.FLATTEN_CALL_PREDICATE;
+import static org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHintOptions.CALL_DELEGATION_STRATEGY;
import static org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHintOptions.PLANNER_COST_FUNCTION;
import static org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHintOptions.PLANNER_TABLE_ROW_COUNT;
import static org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHintOptions.USE_BASE_INDEX;
@@ -24,6 +25,7 @@ import java.util.Objects;
import org.eclipse.viatra.query.runtime.localsearch.planner.cost.ICostFunction;
import org.eclipse.viatra.query.runtime.localsearch.planner.cost.impl.IndexerBasedConstraintCostFunction;
import org.eclipse.viatra.query.runtime.localsearch.planner.cost.impl.VariableBindingBasedCostFunction;
+import org.eclipse.viatra.query.runtime.matchers.backend.ICallDelegationStrategy;
import org.eclipse.viatra.query.runtime.matchers.backend.IMatcherCapability;
import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory;
import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
@@ -51,6 +53,8 @@ public final class LocalSearchHints implements IMatcherCapability {
private IFlattenCallPredicate flattenCallPredicate = null;
+ private ICallDelegationStrategy callDelegationStrategy = null;
+
private IAdornmentProvider adornmentProvider = null;
private IRewriterTraceCollector traceCollector = NopTraceCollector.INSTANCE;
@@ -75,13 +79,14 @@ public final class LocalSearchHints implements IMatcherCapability {
result.rowCount = PLANNER_TABLE_ROW_COUNT.getDefaultValue();
result.costFunction = PLANNER_COST_FUNCTION.getDefaultValue();
result.flattenCallPredicate = FLATTEN_CALL_PREDICATE.getDefaultValue();
+ result.callDelegationStrategy = CALL_DELEGATION_STRATEGY.getDefaultValue();
result.adornmentProvider = ADORNMENT_PROVIDER.getDefaultValue();
result.backendFactory = LocalSearchEMFBackendFactory.INSTANCE;
return result;
}
/**
- * With this setting, the patterns are flattened before planning. This may cause performance gain in most of the cases compared to the {@link #getDefault()} settings,
+ * With this setting, the patterns are flattened before planning. This may cause performance gain in some cases compared to the {@link #getDefault()} settings,
* However this should be used with care for patterns containing calls with several bodies.
*/
public static LocalSearchHints getDefaultFlatten(){
@@ -90,6 +95,7 @@ public final class LocalSearchHints implements IMatcherCapability {
result.rowCount = 4;
result.costFunction = new IndexerBasedConstraintCostFunction();
result.flattenCallPredicate = new DefaultFlattenCallPredicate();
+ result.callDelegationStrategy = CALL_DELEGATION_STRATEGY.getDefaultValue();
result.adornmentProvider = ADORNMENT_PROVIDER.getDefaultValue();
result.backendFactory = LocalSearchEMFBackendFactory.INSTANCE;
return result;
@@ -104,6 +110,7 @@ public final class LocalSearchHints implements IMatcherCapability {
result.rowCount = 4;
result.costFunction = new VariableBindingBasedCostFunction();
result.flattenCallPredicate = new NeverFlattenCallPredicate();
+ result.callDelegationStrategy = ICallDelegationStrategy.FULL_BACKEND_ADHESION;
result.adornmentProvider = ADORNMENT_PROVIDER.getDefaultValue();
result.backendFactory = LocalSearchEMFBackendFactory.INSTANCE;
return result;
@@ -119,17 +126,43 @@ public final class LocalSearchHints implements IMatcherCapability {
result.rowCount = 4;
result.costFunction = new IndexerBasedConstraintCostFunction();
result.flattenCallPredicate = FLATTEN_CALL_PREDICATE.getDefaultValue();
+ result.callDelegationStrategy = ICallDelegationStrategy.FULL_BACKEND_ADHESION;
result.adornmentProvider = ADORNMENT_PROVIDER.getDefaultValue();
result.backendFactory = LocalSearchGenericBackendFactory.INSTANCE;
return result;
}
+ /**
+ * Initializes the default search backend with hybrid-enabled settings
+ * @since 2.1
+ */
+ public static LocalSearchHints getDefaultHybrid(){
+ LocalSearchHints result = getDefault();
+ result.callDelegationStrategy = ICallDelegationStrategy.PARTIAL_BACKEND_ADHESION;
+ result.flattenCallPredicate = new IFlattenCallPredicate.And(
+ new DontFlattenIncrementalPredicate(), new DontFlattenDisjunctive());
+ return result;
+ }
+
+ /**
+ * Initializes the generic (not EMF specific) search backend with hybrid-enabled settings
+ * @since 2.1
+ */
+ public static LocalSearchHints getDefaultGenericHybrid(){
+ LocalSearchHints result = getDefaultGeneric();
+ result.callDelegationStrategy = ICallDelegationStrategy.PARTIAL_BACKEND_ADHESION;
+ result.flattenCallPredicate = new IFlattenCallPredicate.And(
+ new DontFlattenIncrementalPredicate(), new DontFlattenDisjunctive());
+ return result;
+ }
+
public static LocalSearchHints parse(QueryEvaluationHint hint){
LocalSearchHints result = new LocalSearchHints();
result.useBase = USE_BASE_INDEX.getValueOrNull(hint);
result.rowCount = PLANNER_TABLE_ROW_COUNT.getValueOrNull(hint);
result.flattenCallPredicate = FLATTEN_CALL_PREDICATE.getValueOrNull(hint);
+ result.callDelegationStrategy = CALL_DELEGATION_STRATEGY.getValueOrNull(hint);
result.costFunction = PLANNER_COST_FUNCTION.getValueOrNull(hint);
result.adornmentProvider = ADORNMENT_PROVIDER.getValueOrNull(hint);
result.traceCollector = normalizationTraceCollector.getValueOrDefault(hint);
@@ -152,6 +185,9 @@ public final class LocalSearchHints implements IMatcherCapability {
if (flattenCallPredicate != null){
FLATTEN_CALL_PREDICATE.insertOverridingValue(map, flattenCallPredicate);
}
+ if (callDelegationStrategy != null){
+ CALL_DELEGATION_STRATEGY.insertOverridingValue(map, callDelegationStrategy);
+ }
if (adornmentProvider != null){
ADORNMENT_PROVIDER.insertOverridingValue(map, adornmentProvider);
}
@@ -196,6 +232,13 @@ public final class LocalSearchHints implements IMatcherCapability {
public IFlattenCallPredicate getFlattenCallPredicate() {
return flattenCallPredicate;
}
+
+ /**
+ * @since 2.1
+ */
+ public ICallDelegationStrategy getCallDelegationStrategy() {
+ return callDelegationStrategy;
+ }
public Integer getRowCount() {
return rowCount;
@@ -235,6 +278,15 @@ public final class LocalSearchHints implements IMatcherCapability {
return this;
}
+
+ /**
+ * @since 2.1
+ */
+ public LocalSearchHints setCallDelegationStrategy(ICallDelegationStrategy callDelegationStrategy) {
+ this.callDelegationStrategy = callDelegationStrategy;
+ return this;
+ }
+
/**
* @since 1.6
*/
@@ -268,6 +320,13 @@ public final class LocalSearchHints implements IMatcherCapability {
}
/**
+ * @since 2.1
+ */
+ public static LocalSearchHints customizeCallDelegationStrategy(ICallDelegationStrategy strategy){
+ return new LocalSearchHints().setCallDelegationStrategy(strategy);
+ }
+
+ /**
* @since 1.5
*/
public static LocalSearchHints customizeAdornmentProvider(IAdornmentProvider adornmentProvider){
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/AggregatorCheck.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/AggregatorCheck.java
index 1385f6f47..351ec4961 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/AggregatorCheck.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/AggregatorCheck.java
@@ -50,7 +50,7 @@ public class AggregatorCheck implements ISearchOperation, IPatternMatcherOperati
public void onInitialize(MatchingFrame frame, ISearchContext context) {
super.onInitialize(frame, context);
maskedTuple.updateTuple(frame);
- matcher = context.getMatcher(information.getReference());
+ matcher = context.getMatcher(information.getCallWithAdornment());
}
@Override
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/BinaryTransitiveClosureCheck.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/BinaryTransitiveClosureCheck.java
index f2c337def..3ad27768b 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/BinaryTransitiveClosureCheck.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/BinaryTransitiveClosureCheck.java
@@ -44,7 +44,7 @@ public class BinaryTransitiveClosureCheck implements ISearchOperation, IPatternM
@Override
public void onInitialize(MatchingFrame frame, ISearchContext context) {
super.onInitialize(frame, context);
- matcher = context.getMatcher(information.getReference());
+ matcher = context.getMatcher(information.getCallWithAdornment());
// Note: second parameter is NOT bound during execution, but the first is
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/CheckPositivePatternCall.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/CheckPositivePatternCall.java
index 2d5be4dd7..f6bea390c 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/CheckPositivePatternCall.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/CheckPositivePatternCall.java
@@ -43,7 +43,7 @@ public class CheckPositivePatternCall implements ISearchOperation, IPatternMatch
public void onInitialize(MatchingFrame frame, ISearchContext context) {
super.onInitialize(frame, context);
maskedTuple.updateTuple(frame);
- matcher = context.getMatcher(information.getReference());
+ matcher = context.getMatcher(information.getCallWithAdornment());
}
/**
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/CountCheck.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/CountCheck.java
index dd7a9cef8..9763a6a6e 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/CountCheck.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/CountCheck.java
@@ -44,7 +44,7 @@ public class CountCheck implements ISearchOperation, IPatternMatcherOperation {
public void onInitialize(MatchingFrame frame, ISearchContext context) {
super.onInitialize(frame, context);
maskedTuple.updateTuple(frame);
- matcher = context.getMatcher(information.getReference());
+ matcher = context.getMatcher(information.getCallWithAdornment());
}
@Override
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/NACOperation.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/NACOperation.java
index b6ef14990..327dce2c2 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/NACOperation.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/check/NACOperation.java
@@ -40,7 +40,7 @@ public class NACOperation implements ISearchOperation, IPatternMatcherOperation
public void onInitialize(MatchingFrame frame, ISearchContext context) {
super.onInitialize(frame, context);
maskedTuple.updateTuple(frame);
- matcher = context.getMatcher(information.getReference());
+ matcher = context.getMatcher(information.getCallWithAdornment());
}
@Override
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/AggregatorExtend.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/AggregatorExtend.java
index 24b6ec299..a93151e94 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/AggregatorExtend.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/AggregatorExtend.java
@@ -48,7 +48,7 @@ public class AggregatorExtend implements ISearchOperation, IPatternMatcherOpera
@Override
public Iterator<?> getIterator(MatchingFrame frame, ISearchContext context) {
maskedTuple.updateTuple(frame);
- matcher = context.getMatcher(information.getReference());
+ matcher = context.getMatcher(information.getCallWithAdornment());
Object aggregate = aggregate(aggregator.getAggregator().getOperator(), aggregator.getAggregatedColumn());
return aggregate == null ? Collections.emptyIterator() : Collections.singletonList(aggregate).iterator();
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/CountOperation.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/CountOperation.java
index 46e1029cc..5e8d975f0 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/CountOperation.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/CountOperation.java
@@ -41,7 +41,7 @@ public class CountOperation implements ISearchOperation, IPatternMatcherOperatio
@Override
public Iterator<Integer> getIterator(MatchingFrame frame, ISearchContext context) {
- matcher = context.getMatcher(information.getReference());
+ matcher = context.getMatcher(information.getCallWithAdornment());
maskedTuple.updateTuple(frame);
return Collections.singletonList(matcher.countMatches(information.getParameterMask(), maskedTuple)).iterator();
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendBinaryTransitiveClosure.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendBinaryTransitiveClosure.java
index acade423d..c859cd194 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendBinaryTransitiveClosure.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendBinaryTransitiveClosure.java
@@ -46,7 +46,7 @@ public abstract class ExtendBinaryTransitiveClosure implements ISearchOperation,
@Override
public Iterator<?> getIterator(MatchingFrame frame, ISearchContext context) {
// Note: second parameter is NOT bound during execution, but the first is
- IQueryResultProvider matcher = context.getMatcher(information.getReference());
+ IQueryResultProvider matcher = context.getMatcher(information.getCallWithAdornment());
Queue<Object> seedsToEvaluate = new LinkedList<>();
final Object seedValue = frame.get(seedPosition);
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendPositivePatternCall.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendPositivePatternCall.java
index 604af9aec..f12fc2b93 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendPositivePatternCall.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendPositivePatternCall.java
@@ -42,7 +42,7 @@ public class ExtendPositivePatternCall implements ISearchOperation, IPatternMatc
@Override
protected Iterator<? extends Tuple> getIterator(MatchingFrame frame, ISearchContext context) {
maskedTuple.updateTuple(frame);
- IQueryResultProvider matcher = context.getMatcher(information.getReference());
+ IQueryResultProvider matcher = context.getMatcher(information.getCallWithAdornment());
return matcher.getAllMatches(information.getParameterMask(), maskedTuple).iterator();
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/util/CallInformation.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/util/CallInformation.java
index 24b72eebf..7476043a2 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/util/CallInformation.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/util/CallInformation.java
@@ -19,7 +19,9 @@ import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
+import org.eclipse.viatra.query.runtime.localsearch.matcher.CallWithAdornment;
import org.eclipse.viatra.query.runtime.localsearch.matcher.MatcherReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.IQueryReference;
import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternCallBasedDeferred;
import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryReflexiveTransitiveClosure;
@@ -47,29 +49,32 @@ public final class CallInformation {
private final Set<PParameter> adornment = new HashSet<>();
private final PQuery referredQuery;
private final MatcherReference matcherReference;
+ private final IQueryReference call;
+ private CallWithAdornment callWithAdornment;
public static CallInformation create(PatternCallBasedDeferred constraint, Map<PVariable, Integer> variableMapping, Set<Integer> bindings) {
- return new CallInformation(constraint.getActualParametersTuple(), constraint.getReferredQuery(), bindings, variableMapping);
+ return new CallInformation(constraint.getActualParametersTuple(), constraint, bindings, variableMapping);
}
public static CallInformation create(PositivePatternCall pCall, Map<PVariable, Integer> variableMapping, Set<Integer> bindings) {
- return new CallInformation(pCall.getVariablesTuple(), pCall.getReferredQuery(), bindings, variableMapping);
+ return new CallInformation(pCall.getVariablesTuple(), pCall, bindings, variableMapping);
}
public static CallInformation create(BinaryTransitiveClosure constraint, Map<PVariable, Integer> variableMapping, Set<Integer> bindings) {
- return new CallInformation(constraint.getVariablesTuple(), constraint.getReferredQuery(), bindings, variableMapping);
+ return new CallInformation(constraint.getVariablesTuple(), constraint, bindings, variableMapping);
}
/**
* @since 2.0
*/
public static CallInformation create(BinaryReflexiveTransitiveClosure constraint, Map<PVariable, Integer> variableMapping, Set<Integer> bindings) {
- return new CallInformation(constraint.getVariablesTuple(), constraint.getReferredQuery(), bindings, variableMapping);
+ return new CallInformation(constraint.getVariablesTuple(), constraint, bindings, variableMapping);
}
- private CallInformation(Tuple actualParameters, PQuery referredQuery, final Set<Integer> bindings,
+ private CallInformation(Tuple actualParameters, IQueryReference call, final Set<Integer> bindings,
Map<PVariable, Integer> variableMapping) {
- this.referredQuery = referredQuery;
+ this.call = call;
+ this.referredQuery = call.getReferredQuery();
int keySize = actualParameters.getSize();
List<Integer> parameterMaskIndices = new ArrayList<>();
int[] fullParameterMaskIndices = new int[keySize];
@@ -103,7 +108,8 @@ public final class CallInformation {
}
}
parameterMask = TupleMask.fromSelectedIndices(keySize, boundParameterIndices);
- matcherReference = new MatcherReference(referredQuery, adornment);
+ callWithAdornment = new CallWithAdornment(call, adornment);
+ matcherReference = callWithAdornment.getMatcherReference();
}
/**
@@ -130,6 +136,20 @@ public final class CallInformation {
public MatcherReference getReference() {
return matcherReference;
}
+
+ /**
+ * @since 2.1
+ */
+ public IQueryReference getCall() {
+ return call;
+ }
+
+ /**
+ * @since 2.1
+ */
+ public CallWithAdornment getCallWithAdornment() {
+ return callWithAdornment;
+ }
/**
* Returns the parameter indices that are unbound before the call
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/IPlanProvider.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/IPlanProvider.java
index 1b6a1ea8f..e9f0e4184 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/IPlanProvider.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/IPlanProvider.java
@@ -14,6 +14,7 @@ import org.eclipse.viatra.query.runtime.localsearch.matcher.MatcherReference;
import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHints;
import org.eclipse.viatra.query.runtime.localsearch.planner.compiler.IOperationCompiler;
import org.eclipse.viatra.query.runtime.matchers.ViatraQueryRuntimeException;
+import org.eclipse.viatra.query.runtime.matchers.backend.ResultProviderRequestor;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext;
/**
@@ -25,8 +26,10 @@ public interface IPlanProvider {
/**
* @throws ViatraQueryRuntimeException
- * @since 1.7
+ * @since 2.1
*/
- public IPlanDescriptor getPlan(IQueryBackendContext backend, IOperationCompiler compiler, LocalSearchHints configuration, MatcherReference key);
+ public IPlanDescriptor getPlan(IQueryBackendContext backend, IOperationCompiler compiler,
+ ResultProviderRequestor resultProviderRequestor,
+ LocalSearchHints configuration, MatcherReference key);
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/SearchPlanForBody.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/SearchPlanForBody.java
index 741c0ab33..74c448148 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/SearchPlanForBody.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/SearchPlanForBody.java
@@ -17,6 +17,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import org.eclipse.viatra.query.runtime.localsearch.matcher.CallWithAdornment;
import org.eclipse.viatra.query.runtime.localsearch.matcher.MatcherReference;
import org.eclipse.viatra.query.runtime.localsearch.operations.ISearchOperation;
import org.eclipse.viatra.query.runtime.matchers.planning.SubPlan;
@@ -35,10 +36,10 @@ public class SearchPlanForBody {
private int[] parameterKeys;
private SubPlan plan;
private List<ISearchOperation> compiledOperations;
- private Collection<MatcherReference> dependencies;
+ private Collection<CallWithAdornment> dependencies;
public SearchPlanForBody(PBody body, Map<PVariable, Integer> variableKeys,
- SubPlan plan, List<ISearchOperation> compiledOperations, Collection<MatcherReference> dependencies) {
+ SubPlan plan, List<ISearchOperation> compiledOperations, Collection<CallWithAdornment> dependencies) {
super();
this.body = body;
this.variableKeys = variableKeys;
@@ -74,7 +75,7 @@ public class SearchPlanForBody {
return plan;
}
- public Collection<MatcherReference> getDependencies() {
+ public Collection<CallWithAdornment> getDependencies() {
return dependencies;
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/SimplePlanProvider.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/SimplePlanProvider.java
index 686f3ab89..0f1c75cee 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/SimplePlanProvider.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/plan/SimplePlanProvider.java
@@ -17,6 +17,7 @@ import org.eclipse.viatra.query.runtime.localsearch.matcher.MatcherReference;
import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHints;
import org.eclipse.viatra.query.runtime.localsearch.planner.LocalSearchPlanner;
import org.eclipse.viatra.query.runtime.localsearch.planner.compiler.IOperationCompiler;
+import org.eclipse.viatra.query.runtime.matchers.backend.ResultProviderRequestor;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext;
/**
@@ -35,9 +36,11 @@ public class SimplePlanProvider implements IPlanProvider {
}
@Override
- public IPlanDescriptor getPlan(IQueryBackendContext backend, IOperationCompiler compiler, final LocalSearchHints configuration, MatcherReference key) {
+ public IPlanDescriptor getPlan(IQueryBackendContext backend, IOperationCompiler compiler,
+ final ResultProviderRequestor resultRequestor,
+ final LocalSearchHints configuration, MatcherReference key) {
- LocalSearchPlanner planner = new LocalSearchPlanner(backend, compiler, logger, configuration);
+ LocalSearchPlanner planner = new LocalSearchPlanner(backend, compiler, logger, configuration, resultRequestor);
Collection<SearchPlanForBody> plansForBodies = planner.plan(key.getQuery(), key.getAdornment());
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchPlanner.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchPlanner.java
index 32d790f97..2cabb9863 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchPlanner.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchPlanner.java
@@ -23,6 +23,7 @@ import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSea
import org.eclipse.viatra.query.runtime.localsearch.operations.ISearchOperation;
import org.eclipse.viatra.query.runtime.localsearch.plan.SearchPlanForBody;
import org.eclipse.viatra.query.runtime.localsearch.planner.compiler.IOperationCompiler;
+import org.eclipse.viatra.query.runtime.matchers.backend.ResultProviderRequestor;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext;
import org.eclipse.viatra.query.runtime.matchers.planning.SubPlan;
@@ -50,15 +51,20 @@ public class LocalSearchPlanner implements ILocalSearchPlanner {
private final LocalSearchHints configuration;
private final IOperationCompiler operationCompiler;
private final IQueryBackendContext context;
+ private final ResultProviderRequestor resultRequestor;
/**
+ * @param resultRequestor
* @since 1.7
*/
- public LocalSearchPlanner(IQueryBackendContext backendContext, IOperationCompiler compiler, Logger logger, final LocalSearchHints configuration) {
+ public LocalSearchPlanner(IQueryBackendContext backendContext, IOperationCompiler compiler, Logger logger,
+ final LocalSearchHints configuration, ResultProviderRequestor resultRequestor)
+ {
this.runtimeContext = backendContext.getRuntimeContext();
this.configuration = configuration;
this.operationCompiler = compiler;
+ this.resultRequestor = resultRequestor;
PQueryFlattener flattener = new PQueryFlattener(configuration.getFlattenCallPredicate());
/*
* TODO https://bugs.eclipse.org/bugs/show_bug.cgi?id=439358: The normalizer is initialized with the false
@@ -103,7 +109,7 @@ public class LocalSearchPlanner implements ILocalSearchPlanner {
// 2. Plan creation
// Context has matchers for the referred Queries (IQuerySpecifications)
Set<PVariable> boundVariables = calculatePatternAdornmentForPlanner(boundParameters, normalizedBody);
- SubPlan plan = plannerStrategy.plan(normalizedBody, boundVariables, context, configuration);
+ SubPlan plan = plannerStrategy.plan(normalizedBody, boundVariables, context, resultRequestor, configuration);
// 3. PConstraint -> POperation compilation step
// * Pay extra caution to extend operations, when more than one variables are unbound
List<ISearchOperation> compiledOperations = operationCompiler.compile(plan, boundParameters);
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchRuntimeBasedStrategy.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchRuntimeBasedStrategy.java
index b95ee906e..7a07b6462 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchRuntimeBasedStrategy.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/LocalSearchRuntimeBasedStrategy.java
@@ -20,6 +20,7 @@ import org.eclipse.emf.ecore.EPackage;
import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHints;
import org.eclipse.viatra.query.runtime.localsearch.planner.cost.ICostFunction;
import org.eclipse.viatra.query.runtime.localsearch.planner.util.OperationCostComparator;
+import org.eclipse.viatra.query.runtime.matchers.backend.ResultProviderRequestor;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext;
import org.eclipse.viatra.query.runtime.matchers.planning.SubPlan;
import org.eclipse.viatra.query.runtime.matchers.planning.SubPlanFactory;
@@ -57,15 +58,15 @@ public class LocalSearchRuntimeBasedStrategy {
* @param context the backend context
* @param configuration the planner configuration
* @return the complete search plan for the given {@link PBody}
- * @since 1.5
+ * @since 2.1
*/
public SubPlan plan(PBody pBody, Set<PVariable> initialBoundVariables,
- IQueryBackendContext context,
+ IQueryBackendContext context, final ResultProviderRequestor resultRequestor,
LocalSearchHints configuration) {
final ICostFunction costFunction = configuration.getCostFunction();
PConstraintInfoInferrer pConstraintInfoInferrer = new PConstraintInfoInferrer(
- configuration.isUseBase(), context, costFunction::apply);
+ configuration.isUseBase(), context, resultRequestor, costFunction::apply);
// 1. INITIALIZATION
// Create a starting plan
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/PConstraintInfo.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/PConstraintInfo.java
index 90f2f16ac..f6f300efe 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/PConstraintInfo.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/PConstraintInfo.java
@@ -18,6 +18,7 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint;
import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
import org.eclipse.viatra.query.runtime.localsearch.planner.cost.IConstraintEvaluationContext;
import org.eclipse.viatra.query.runtime.matchers.psystem.analysis.QueryAnalyzer;
+import org.eclipse.viatra.query.runtime.matchers.backend.ResultProviderRequestor;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryResultProviderAccess;
@@ -37,6 +38,7 @@ public class PConstraintInfo implements IConstraintEvaluationContext {
private IQueryRuntimeContext runtimeContext;
private QueryAnalyzer queryAnalyzer;
private IQueryResultProviderAccess resultProviderAccess;
+ private ResultProviderRequestor resultRequestor;
private double cost;
@@ -54,11 +56,13 @@ public class PConstraintInfo implements IConstraintEvaluationContext {
public PConstraintInfo(PConstraint constraint, Set<PVariable> boundMaskVariables, Set<PVariable> freeMaskVariables,
Set<PConstraintInfo> sameWithDifferentBindings,
IQueryBackendContext context,
+ ResultProviderRequestor resultRequestor,
Function<IConstraintEvaluationContext, Double> costFunction) {
this.constraint = constraint;
this.boundMaskVariables = boundMaskVariables;
this.freeMaskVariables = freeMaskVariables;
this.sameWithDifferentBindings = sameWithDifferentBindings;
+ this.resultRequestor = resultRequestor;
this.runtimeContext = context.getRuntimeContext();
this.queryAnalyzer = context.getQueryAnalyzer();
this.resultProviderAccess = context.getResultProviderAccess();
@@ -116,9 +120,18 @@ public class PConstraintInfo implements IConstraintEvaluationContext {
return String.format("%s, bound variables: %s, cost: \"%.2f\"", constraint.toString(), boundMaskVariables.toString(), cost);
}
+ /**
+ * @deprecated use {@link #resultProviderRequestor()}
+ */
@Override
+ @Deprecated
public IQueryResultProviderAccess resultProviderAccess() {
return resultProviderAccess;
}
+
+ @Override
+ public ResultProviderRequestor resultProviderRequestor() {
+ return resultRequestor;
+ }
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/PConstraintInfoInferrer.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/PConstraintInfoInferrer.java
index 16bcdd8b5..af5f96a45 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/PConstraintInfoInferrer.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/PConstraintInfoInferrer.java
@@ -28,6 +28,7 @@ import org.eclipse.viatra.query.runtime.base.api.BaseIndexOptions;
import org.eclipse.viatra.query.runtime.base.comprehension.EMFModelComprehension;
import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
import org.eclipse.viatra.query.runtime.localsearch.planner.cost.IConstraintEvaluationContext;
+import org.eclipse.viatra.query.runtime.matchers.backend.ResultProviderRequestor;
import org.eclipse.viatra.query.runtime.matchers.context.IInputKey;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext;
import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint;
@@ -61,12 +62,16 @@ class PConstraintInfoInferrer {
private final Function<IConstraintEvaluationContext, Double> costFunction;
private final EMFModelComprehension modelComprehension;
private final IQueryBackendContext context;
+ private final ResultProviderRequestor resultRequestor;
+
public PConstraintInfoInferrer(boolean useIndex,
IQueryBackendContext backendContext,
+ ResultProviderRequestor resultRequestor,
Function<IConstraintEvaluationContext, Double> costFunction) {
this.useIndex = useIndex;
this.context = backendContext;
+ this.resultRequestor = resultRequestor;
this.costFunction = costFunction;
this.modelComprehension = new EMFModelComprehension(new BaseIndexOptions());
}
@@ -298,7 +303,7 @@ class PConstraintInfoInferrer {
PConstraintInfo info = new PConstraintInfo(pConstraint, boundVariables,
affectedVariables.stream().filter(input -> !boundVariables.contains(input)).collect(Collectors.toSet()),
- sameWithDifferentBindings, context, costFunction);
+ sameWithDifferentBindings, context, resultRequestor, costFunction);
constraintInfos.add(info);
sameWithDifferentBindings.add(info);
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/compiler/AbstractOperationCompiler.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/compiler/AbstractOperationCompiler.java
index b87c347a1..40fd9cbba 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/compiler/AbstractOperationCompiler.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/compiler/AbstractOperationCompiler.java
@@ -19,7 +19,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.eclipse.viatra.query.runtime.localsearch.matcher.MatcherReference;
+import org.eclipse.viatra.query.runtime.localsearch.matcher.CallWithAdornment;
import org.eclipse.viatra.query.runtime.localsearch.operations.ISearchOperation;
import org.eclipse.viatra.query.runtime.localsearch.operations.check.AggregatorCheck;
import org.eclipse.viatra.query.runtime.localsearch.operations.check.BinaryTransitiveClosureCheck;
@@ -91,7 +91,7 @@ public abstract class AbstractOperationCompiler implements IOperationCompiler {
protected abstract void createUnaryTypeCheck(IInputKey type, int position);
protected List<ISearchOperation> operations;
- protected Set<MatcherReference> dependencies = new HashSet<>();
+ protected Set<CallWithAdornment> dependencies = new HashSet<>();
protected Map<PConstraint, Set<Integer>> variableBindings;
private Map<PVariable, Integer> variableMappings;
protected final IQueryRuntimeContext runtimeContext;
@@ -254,7 +254,7 @@ public abstract class AbstractOperationCompiler implements IOperationCompiler {
}
@Override
- public Set<MatcherReference> getDependencies() {
+ public Set<CallWithAdornment> getDependencies() {
return dependencies;
}
@@ -269,13 +269,13 @@ public abstract class AbstractOperationCompiler implements IOperationCompiler {
protected void createCheck(PatternMatchCounter counter, Map<PVariable, Integer> variableMapping) {
CallInformation information = CallInformation.create(counter, variableMapping, variableBindings.get(counter));
operations.add(new CountCheck(information, variableMapping.get(counter.getResultVariable())));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
}
protected void createCheck(PositivePatternCall pCall, Map<PVariable, Integer> variableMapping) {
CallInformation information = CallInformation.create(pCall, variableMapping, variableBindings.get(pCall));
operations.add(new CheckPositivePatternCall(information));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
}
protected void createCheck(ConstantValue constant, Map<PVariable, Integer> variableMapping) {
@@ -290,7 +290,7 @@ public abstract class AbstractOperationCompiler implements IOperationCompiler {
//The second parameter is NOT bound during execution!
CallInformation information = CallInformation.create(binaryTransitiveClosure, variableMapping, Stream.of(sourcePosition).collect(Collectors.toSet()));
operations.add(new BinaryTransitiveClosureCheck(information, sourcePosition, targetPosition, false));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
}
/**
@@ -304,7 +304,7 @@ public abstract class AbstractOperationCompiler implements IOperationCompiler {
CallInformation information = CallInformation.create(binaryTransitiveClosure, variableMapping, Stream.of(sourcePosition).collect(Collectors.toSet()));
createUnaryTypeCheck(binaryTransitiveClosure.getUniverseType(), sourcePosition);
operations.add(new BinaryTransitiveClosureCheck(information, sourcePosition, targetPosition, true));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
}
protected void createCheck(ExpressionEvaluation expressionEvaluation, Map<PVariable, Integer> variableMapping) {
@@ -328,13 +328,13 @@ public abstract class AbstractOperationCompiler implements IOperationCompiler {
protected void createCheck(AggregatorConstraint aggregator, Map<PVariable, Integer> variableMapping) {
CallInformation information = CallInformation.create(aggregator, variableMapping, variableBindings.get(aggregator));
operations.add(new AggregatorCheck(information, aggregator, variableMapping.get(aggregator.getResultVariable())));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
}
protected void createCheck(NegativePatternCall negativePatternCall, Map<PVariable, Integer> variableMapping) {
CallInformation information = CallInformation.create(negativePatternCall, variableMapping, variableBindings.get(negativePatternCall));
operations.add(new NACOperation(information));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
}
protected void createCheck(Inequality inequality, Map<PVariable, Integer> variableMapping) {
@@ -344,7 +344,7 @@ public abstract class AbstractOperationCompiler implements IOperationCompiler {
protected void createExtend(PositivePatternCall pCall, Map<PVariable, Integer> variableMapping) {
CallInformation information = CallInformation.create(pCall, variableMapping, variableBindings.get(pCall));
operations.add(new ExtendPositivePatternCall(information));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
}
protected void createExtend(BinaryTransitiveClosure binaryTransitiveClosure, Map<PVariable, Integer> variableMapping) {
@@ -358,10 +358,10 @@ public abstract class AbstractOperationCompiler implements IOperationCompiler {
if (sourceBound && !targetBound) {
operations.add(new ExtendBinaryTransitiveClosure.Forward(information, sourcePosition, targetPosition, false));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
} else if (!sourceBound && targetBound) {
operations.add(new ExtendBinaryTransitiveClosure.Backward(information, sourcePosition, targetPosition, false));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
} else {
String msg = "Binary transitive closure not supported with two unbound parameters";
throw new QueryProcessingException(msg, null, msg, binaryTransitiveClosure.getPSystem().getPattern());
@@ -383,11 +383,11 @@ public abstract class AbstractOperationCompiler implements IOperationCompiler {
if (sourceBound && !targetBound) {
createUnaryTypeCheck(binaryTransitiveClosure.getUniverseType(), sourcePosition);
operations.add(new ExtendBinaryTransitiveClosure.Forward(information, sourcePosition, targetPosition, true));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
} else if (!sourceBound && targetBound) {
createUnaryTypeCheck(binaryTransitiveClosure.getUniverseType(), targetPosition);
operations.add(new ExtendBinaryTransitiveClosure.Backward(information, sourcePosition, targetPosition, true));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
} else {
String msg = "Binary reflective transitive closure not supported with two unbound parameters";
throw new QueryProcessingException(msg, null, msg, binaryTransitiveClosure.getPSystem().getPattern());
@@ -420,13 +420,13 @@ public abstract class AbstractOperationCompiler implements IOperationCompiler {
protected void createExtend(AggregatorConstraint aggregator, Map<PVariable, Integer> variableMapping) {
CallInformation information = CallInformation.create(aggregator, variableMapping, variableBindings.get(aggregator));
operations.add(new AggregatorExtend(information, aggregator, variableMapping.get(aggregator.getResultVariable())));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
}
protected void createExtend(PatternMatchCounter patternMatchCounter, Map<PVariable, Integer> variableMapping) {
CallInformation information = CallInformation.create(patternMatchCounter, variableMapping, variableBindings.get(patternMatchCounter));
operations.add(new CountOperation(information, variableMapping.get(patternMatchCounter.getResultVariable())));
- dependencies.add(information.getReference());
+ dependencies.add(information.getCallWithAdornment());
}
} \ No newline at end of file
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/compiler/IOperationCompiler.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/compiler/IOperationCompiler.java
index 24b049c09..0d85f10fe 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/compiler/IOperationCompiler.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/compiler/IOperationCompiler.java
@@ -14,6 +14,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.eclipse.viatra.query.runtime.localsearch.matcher.CallWithAdornment;
import org.eclipse.viatra.query.runtime.localsearch.matcher.MatcherReference;
import org.eclipse.viatra.query.runtime.localsearch.operations.ISearchOperation;
import org.eclipse.viatra.query.runtime.matchers.ViatraQueryRuntimeException;
@@ -40,7 +41,11 @@ public interface IOperationCompiler {
*/
List<ISearchOperation> compile(SubPlan plan, Set<PParameter> boundParameters);
- Set<MatcherReference> getDependencies();
+ /**
+ * Replaces previous method returning {@link MatcherReference}
+ * @since 2.1
+ */
+ Set<CallWithAdornment> getDependencies();
/**
* @return the cached variable bindings for the previously created plan
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/IConstraintEvaluationContext.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/IConstraintEvaluationContext.java
index 446e9f3f0..31ca22756 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/IConstraintEvaluationContext.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/IConstraintEvaluationContext.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.viatra.query.runtime.localsearch.planner.cost;
+import org.eclipse.viatra.query.runtime.matchers.backend.ResultProviderRequestor;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryResultProviderAccess;
import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext;
import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint;
@@ -50,8 +51,15 @@ public interface IConstraintEvaluationContext {
public QueryAnalyzer getQueryAnalyzer();
/**
+ * @deprecated use {@link #resultProviderRequestor()}
* @since 1.5
*/
+ @Deprecated
public IQueryResultProviderAccess resultProviderAccess();
+ /**
+ * @since 2.1
+ */
+ public ResultProviderRequestor resultProviderRequestor();
+
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/impl/HybridMatcherConstraintCostFunction.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/impl/HybridMatcherConstraintCostFunction.java
index f1ac2fdd9..4e23cb0b3 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/impl/HybridMatcherConstraintCostFunction.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/impl/HybridMatcherConstraintCostFunction.java
@@ -64,7 +64,7 @@ public class HybridMatcherConstraintCostFunction extends IndexerBasedConstraintC
.map(variableIndices::get)
.collect(Collectors.toList());
- IQueryResultProvider resultProvider = context.resultProviderAccess().getResultProvider(patternCall.getReferredQuery(), null);
+ IQueryResultProvider resultProvider = context.resultProviderRequestor().requestResultProvider(patternCall, null);
Map<Tuple, Integer> aggregatedCounts = new HashMap<>();
// Iterate over all matches and count together matches that has equal values on
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/impl/StatisticsBasedConstraintCostFunction.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/impl/StatisticsBasedConstraintCostFunction.java
index 61910d162..1e8100178 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/impl/StatisticsBasedConstraintCostFunction.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/planner/cost/impl/StatisticsBasedConstraintCostFunction.java
@@ -228,7 +228,7 @@ public abstract class StatisticsBasedConstraintCostFunction implements ICostFunc
for (int i = 0; (i < parameters.size()); i++) {
final PVariable variable = patternCall.getVariableInTuple(i);
final IInputKey type = parameters.get(i).getDeclaredUnaryType();
- double multiplier = (boundOrImplied.contains(variable)) ? 0.9 : (type == null) ? DEFAULT_COST : countTuples(input, type);
+ double multiplier = (boundOrImplied.contains(variable)) ? 0.9 : (type == null || !type.isEnumerable()) ? DEFAULT_COST : countTuples(input, type);
result *= multiplier;
}
return result;
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.matchers/.settings/.api_filters b/query/plugins/org.eclipse.viatra.query.runtime.matchers/.settings/.api_filters
index e4d813f62..5b150a304 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.matchers/.settings/.api_filters
+++ b/query/plugins/org.eclipse.viatra.query.runtime.matchers/.settings/.api_filters
@@ -84,6 +84,14 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/viatra/query/runtime/matchers/backend/IQueryBackend.java" type="org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackend">
+ <filter comment="interface used internally only" id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackend"/>
+ <message_argument value="getFactory()"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/viatra/query/runtime/matchers/context/AbstractQueryMetaContext.java" type="org.eclipse.viatra.query.runtime.matchers.context.AbstractQueryMetaContext">
<filter comment="Internal API implementation" id="576725006">
<message_arguments>
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/ICallDelegationStrategy.java b/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/ICallDelegationStrategy.java
new file mode 100644
index 000000000..b2ee3e101
--- /dev/null
+++ b/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/ICallDelegationStrategy.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2018, Gabor Bergmann, IncQuery Labs Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Gabor Bergmann - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.viatra.query.runtime.matchers.backend;
+
+import org.eclipse.viatra.query.runtime.matchers.context.IQueryResultProviderAccess;
+import org.eclipse.viatra.query.runtime.matchers.psystem.IQueryReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint;
+
+/**
+ * Function object that specifies how hints (including backend preferences) shall propagate through pattern calls.
+ *
+ * <p> A few useful default implementations are included as static fields.
+ *
+ * <p> As of 2.1, only suppported by the local search backend, and only if the pattern call is not flattened.
+ *
+ * @author Gabor Bergmann
+ * @since 2.1
+ */
+@FunctionalInterface
+public interface ICallDelegationStrategy {
+
+ /**
+ * Specifies how hints (including backend preferences) shall propagate through pattern calls.
+ *
+ * @param call a {@link PConstraint} in a query that calls another query.
+ * @param callerHint a hint under which the calling pattern is evaluated,
+ * @param callerBackend the actual backend evaluating the calling pattern.
+ * @param calleeHintProvider the provider of hints for the called pattern.
+ * @return the hints, including backend selection,
+ * that the backend responsible for the caller pattern must specify when
+ * requesting the {@link IQueryResultProvider} for the called pattern via {@link IQueryResultProviderAccess}.
+ */
+ public QueryEvaluationHint transformHints(IQueryReference call,
+ QueryEvaluationHint callerHint,
+ IQueryBackend callerBackend,
+ IQueryBackendHintProvider calleeHintProvider);
+
+
+ /**
+ * Options known for callee are used to override caller options, except the backend selection.
+ * Always use the same backend for the callee and the caller, regardless what is specified for the callee pattern.
+ * @author Gabor Bergmann
+ */
+ public static final ICallDelegationStrategy FULL_BACKEND_ADHESION = (call, callerHint, callerBackend, calleeHintProvider) -> {
+ QueryEvaluationHint calleeHint =
+ calleeHintProvider.getQueryEvaluationHint(call.getReferredQuery());
+ QueryEvaluationHint result =
+ callerHint == null ? calleeHint : callerHint.overrideBy(calleeHint);
+
+ QueryEvaluationHint backendAdhesion = new QueryEvaluationHint(
+ null /* settings-ignorant */, callerBackend.getFactory());
+ result = result.overrideBy(backendAdhesion);
+ return result;
+ };
+ /**
+ * Options known for callee are used to override caller options, including the backend selection.
+ * If callee does not specify a backend requirement, the backend of the caller is kept.
+ * @author Gabor Bergmann
+ */
+ public static final ICallDelegationStrategy PARTIAL_BACKEND_ADHESION = (call, callerHint, callerBackend, calleeHintProvider) -> {
+ QueryEvaluationHint backendAdhesion = new QueryEvaluationHint(
+ null /* settings-ignorant */, callerBackend.getFactory());
+
+ QueryEvaluationHint result =
+ callerHint == null ? backendAdhesion : callerHint.overrideBy(backendAdhesion);
+
+ QueryEvaluationHint calleeHint = calleeHintProvider.getQueryEvaluationHint(call.getReferredQuery());
+ result = result.overrideBy(calleeHint);
+
+ return result;
+ };
+ /**
+ * Options known for callee are used to override caller options, including the backend selection.
+ * Always use the backend specified for the callee (or the default if none), regardless of the backend of the caller.
+ * @author Gabor Bergmann
+ */
+ public static final ICallDelegationStrategy NO_BACKEND_ADHESION = (call, callerHint, callerBackend, calleeHintProvider) -> {
+ QueryEvaluationHint calleeHint = calleeHintProvider.getQueryEvaluationHint(call.getReferredQuery());
+ return callerHint == null ? calleeHint : callerHint.overrideBy(calleeHint);
+ };
+
+
+}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/IQueryBackend.java b/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/IQueryBackend.java
index 2047e6b79..07acb6485 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/IQueryBackend.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/IQueryBackend.java
@@ -59,5 +59,11 @@ public interface IQueryBackend {
* Disposes the query backend.
*/
public abstract void dispose();
+
+ /**
+ * @return the factory that created this backend, if this functionality is supported
+ * @since 2.1
+ */
+ public IQueryBackendFactory getFactory();
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/ResultProviderRequestor.java b/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/ResultProviderRequestor.java
new file mode 100644
index 000000000..43d897ab6
--- /dev/null
+++ b/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/backend/ResultProviderRequestor.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2018, Gabor Bergmann, IncQuery Labs Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Gabor Bergmann - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.viatra.query.runtime.matchers.backend;
+
+import org.eclipse.viatra.query.runtime.matchers.context.IQueryResultProviderAccess;
+import org.eclipse.viatra.query.runtime.matchers.psystem.IQueryReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint;
+
+/**
+ * Uniform way of requesting result providers for pattern calls within queries.
+ * Intended users are query backends, for calling other backends to deliver results of dependee queries.
+ *
+ * @author Gabor Bergmann
+ * @since 2.1
+ */
+public class ResultProviderRequestor {
+ IQueryBackend callerBackend;
+ IQueryResultProviderAccess resultProviderAccess;
+ IQueryBackendHintProvider hintProvider;
+ ICallDelegationStrategy delegationStrategy;
+ QueryEvaluationHint callerHint;
+ QueryEvaluationHint universalOverride;
+
+
+ /**
+ * @param callerBackend the actual backend evaluating the calling pattern.
+ * @param resultProviderAccess
+ * @param hintProvider
+ * @param delegationStrategy
+ * @param callerHint a hint under which the calling pattern is evaluated,
+ * @param universalOverride if non-null, overrides the hint with extra options <i>after</i> the {@link ICallDelegationStrategy}
+ */
+ public ResultProviderRequestor(IQueryBackend callerBackend, IQueryResultProviderAccess resultProviderAccess,
+ IQueryBackendHintProvider hintProvider, ICallDelegationStrategy delegationStrategy,
+ QueryEvaluationHint callerHint, QueryEvaluationHint universalOverride) {
+ super();
+ this.callerBackend = callerBackend;
+ this.resultProviderAccess = resultProviderAccess;
+ this.hintProvider = hintProvider;
+ this.delegationStrategy = delegationStrategy;
+ this.callerHint = callerHint;
+ this.universalOverride = universalOverride;
+ }
+
+
+
+
+ /**
+ *
+ * @param call a {@link PConstraint} in a query that calls another query.
+ * @param spotOverride if non-null, overrides the hint with extra options <i>after</i> the {@link ICallDelegationStrategy}
+ * and the universal override specified in the constructor
+ * @return the obtained result provider
+ */
+ public IQueryResultProvider requestResultProvider(IQueryReference call, QueryEvaluationHint spotOverride) {
+ QueryEvaluationHint hints =
+ delegationStrategy.transformHints(call, callerHint, callerBackend, hintProvider);
+
+ if (universalOverride != null)
+ hints = hints.overrideBy(universalOverride);
+
+ if (spotOverride != null)
+ hints = hints.overrideBy(spotOverride);
+
+ return resultProviderAccess.getResultProvider(call.getReferredQuery(), hints);
+ }
+
+}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/psystem/rewriters/IFlattenCallPredicate.java b/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/psystem/rewriters/IFlattenCallPredicate.java
index eec00c926..ac16c8006 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/psystem/rewriters/IFlattenCallPredicate.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.matchers/src/org/eclipse/viatra/query/runtime/matchers/psystem/rewriters/IFlattenCallPredicate.java
@@ -14,7 +14,7 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.Positi
/**
- * Interface used by the PQueryFlattener to decide which pattern calls to flatten
+ * Interface used by the PQueryFlattener to decide which positive pattern calls to flatten
*
* @author Marton Bur
*
@@ -30,4 +30,23 @@ public interface IFlattenCallPredicate {
*/
boolean shouldFlatten(PositivePatternCall positivePatternCall);
+ /**
+ * Flattens only if all operand predicates vote for flattening.
+ * @author Gabor Bergmann
+ * @since 2.1
+ */
+ public static class And implements IFlattenCallPredicate {
+ private IFlattenCallPredicate[] operands;
+ public And(IFlattenCallPredicate... operands) {
+ this.operands = operands;
+ }
+
+ @Override
+ public boolean shouldFlatten(PositivePatternCall positivePatternCall) {
+ for (IFlattenCallPredicate operand : operands) {
+ if (!operand.shouldFlatten(positivePatternCall)) return false;
+ }
+ return true;
+ }
+ }
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.rete/src/org/eclipse/viatra/query/runtime/rete/matcher/ReteEngine.java b/query/plugins/org.eclipse.viatra.query.runtime.rete/src/org/eclipse/viatra/query/runtime/rete/matcher/ReteEngine.java
index be7ef629c..cc0093e3b 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.rete/src/org/eclipse/viatra/query/runtime/rete/matcher/ReteEngine.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.rete/src/org/eclipse/viatra/query/runtime/rete/matcher/ReteEngine.java
@@ -20,6 +20,7 @@ import java.util.concurrent.Callable;
import org.apache.log4j.Logger;
import org.eclipse.viatra.query.runtime.matchers.ViatraQueryRuntimeException;
import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackend;
+import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory;
import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendHintProvider;
import org.eclipse.viatra.query.runtime.matchers.backend.IQueryResultProvider;
import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
@@ -541,4 +542,9 @@ public class ReteEngine implements IQueryBackend {
return hintConfigurator;
}
+ @Override
+ public IQueryBackendFactory getFactory() {
+ return ReteBackendFactory.INSTANCE;
+ }
+
}
diff --git a/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/FlattenerPredicateTest.xtend b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/FlattenerPredicateTest.xtend
index a5b941591..6c5813850 100644
--- a/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/FlattenerPredicateTest.xtend
+++ b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/FlattenerPredicateTest.xtend
@@ -93,7 +93,7 @@ class FlattenerPredicateTest {
def void flattenedPatternCallTest() {
val engine = AdvancedViatraQueryEngine.createUnmanagedEngine(new EMFScope(rs), engineOptions)
try {
- engine.getMatcher(queryToFlatten, LocalSearchHints.^default.build)
+ engine.getMatcher(queryToFlatten, LocalSearchHints.defaultGenericHybrid.build)
Assert.assertTrue(shouldCallBeFlattened.xor(engine.hasResultProviderForQuery(queryFlattened)))
} finally {
engine.dispose
diff --git a/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/LocalSearchPlanCostOverflowTest.xtend b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/LocalSearchPlanCostOverflowTest.xtend
index 42c27415b..d295418df 100644
--- a/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/LocalSearchPlanCostOverflowTest.xtend
+++ b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/LocalSearchPlanCostOverflowTest.xtend
@@ -69,11 +69,14 @@ class LocalSearchPlanCostOverflowTest {
val engine = AdvancedViatraQueryEngine.createUnmanagedEngine(scope)
val backend = engine.getQueryBackend(LocalSearchEMFBackendFactory.INSTANCE) as LocalSearchBackend
+ val requestor = backend.getResultProviderRequestor(pattern.internalQueryRepresentation, null)
val planner = new SimplePlanProvider(null);
val adornment = #{}
val compiler = new EMFOperationCompiler(backend.getRuntimeContext(), hints.isUseBase());
- val plan = planner.getPlan(backend.backendContext, compiler, hints, new MatcherReference(pattern.internalQueryRepresentation, adornment))
+ val plan = planner.getPlan(backend.backendContext, compiler, requestor, hints,
+ new MatcherReference(pattern.internalQueryRepresentation, adornment)
+ )
Assert.assertEquals(1,plan.iteratedKeys.size)
engine.dispose

Back to the top