Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#1553: remove NativeStore extensions and replace with strategy
The NativeStoreExt was used to evaluate pre-compiled TupleExpr without applying any optimizer. With the latest API changes to EvaluationStrategy we can solve the same in the strategy. Signed-off-by: Andreas Schwarte <aschwarte10@gmail.com>
- Loading branch information
1 parent
b22ce54
commit 5346f78
Showing
8 changed files
with
226 additions
and
316 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
tools/federation/src/main/java/org/eclipse/rdf4j/federated/algebra/PrecompiledQueryNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Eclipse RDF4J contributors. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*******************************************************************************/ | ||
package org.eclipse.rdf4j.federated.algebra; | ||
|
||
import org.eclipse.rdf4j.federated.endpoint.provider.SailSourceEvaluationStrategyFactory; | ||
import org.eclipse.rdf4j.federated.evaluation.SailTripleSource; | ||
import org.eclipse.rdf4j.query.algebra.QueryRoot; | ||
import org.eclipse.rdf4j.query.algebra.TupleExpr; | ||
|
||
/** | ||
* Node representing a precompiled query. | ||
* | ||
* @author Andreas Schwarte | ||
* @see SailSourceEvaluationStrategyFactory | ||
* @see SailTripleSource | ||
*/ | ||
public class PrecompiledQueryNode extends QueryRoot { | ||
|
||
private static final long serialVersionUID = -5382415823483370751L; | ||
|
||
private TupleExpr query; | ||
|
||
public PrecompiledQueryNode(TupleExpr query) { | ||
super(query); | ||
this.query = query; | ||
} | ||
|
||
public TupleExpr getQuery() { | ||
return query; | ||
} | ||
|
||
@Override | ||
public PrecompiledQueryNode clone() { | ||
PrecompiledQueryNode clone = (PrecompiledQueryNode) super.clone(); | ||
clone.query = this.query; | ||
return clone; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
...va/org/eclipse/rdf4j/federated/endpoint/provider/SailSourceEvaluationStrategyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Eclipse RDF4J contributors. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*******************************************************************************/ | ||
package org.eclipse.rdf4j.federated.endpoint.provider; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.rdf4j.common.iteration.CloseableIteration; | ||
import org.eclipse.rdf4j.federated.algebra.PrecompiledQueryNode; | ||
import org.eclipse.rdf4j.model.Value; | ||
import org.eclipse.rdf4j.query.BindingSet; | ||
import org.eclipse.rdf4j.query.Dataset; | ||
import org.eclipse.rdf4j.query.QueryEvaluationException; | ||
import org.eclipse.rdf4j.query.algebra.Service; | ||
import org.eclipse.rdf4j.query.algebra.TupleExpr; | ||
import org.eclipse.rdf4j.query.algebra.ValueExpr; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.EvaluationStrategy; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.EvaluationStrategyFactory; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.QueryOptimizerPipeline; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.TripleSource; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.federation.FederatedService; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.impl.BindingAssigner; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.impl.EvaluationStatistics; | ||
|
||
/** | ||
* An {@link EvaluationStrategyFactory} which allows the evaluation of {@link PrecompiledQueryNode} without prior | ||
* optimization. | ||
* <p> | ||
* All other types of {@link TupleExpr} are optimized and evaluated through the configured delegate strategy, i.e. | ||
* typically the one provided by the sail itself. | ||
* </p> | ||
* | ||
* @author Andreas Schwarte | ||
* @see NativeStoreProvider | ||
*/ | ||
public class SailSourceEvaluationStrategyFactory implements EvaluationStrategyFactory { | ||
|
||
private final EvaluationStrategyFactory delegate; | ||
|
||
public SailSourceEvaluationStrategyFactory(EvaluationStrategyFactory delegate) { | ||
super(); | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void setQuerySolutionCacheThreshold(long threshold) { | ||
delegate.setQuerySolutionCacheThreshold(threshold); | ||
} | ||
|
||
@Override | ||
public long getQuerySolutionCacheThreshold() { | ||
return delegate.getQuerySolutionCacheThreshold(); | ||
} | ||
|
||
@Override | ||
public void setOptimizerPipeline(QueryOptimizerPipeline pipeline) { | ||
delegate.setOptimizerPipeline(pipeline); | ||
} | ||
|
||
@Override | ||
public Optional<QueryOptimizerPipeline> getOptimizerPipeline() { | ||
return delegate.getOptimizerPipeline(); | ||
} | ||
|
||
@Override | ||
public EvaluationStrategy createEvaluationStrategy(Dataset dataset, TripleSource tripleSource, | ||
EvaluationStatistics evaluationStatistics) { | ||
EvaluationStrategy delegateStrategy = delegate.createEvaluationStrategy(dataset, tripleSource, | ||
evaluationStatistics); | ||
return new SailSourceEvaluationStrategy(delegateStrategy, dataset); | ||
} | ||
|
||
/** | ||
* {@link EvaluationStrategy} that can handle {@link PrecompiledQueryNode} without prior optimization. All other | ||
* {@link TupleExpr} are handled in the respective delegate. | ||
* | ||
* @author Andreas Schwarte | ||
* | ||
*/ | ||
private static class SailSourceEvaluationStrategy implements EvaluationStrategy { | ||
|
||
private final EvaluationStrategy delegate; | ||
private final Dataset dataset; | ||
|
||
public SailSourceEvaluationStrategy(EvaluationStrategy delegate, Dataset dataset) { | ||
super(); | ||
this.delegate = delegate; | ||
this.dataset = dataset; | ||
} | ||
|
||
@Override | ||
public FederatedService getService(String serviceUrl) throws QueryEvaluationException { | ||
return delegate.getService(serviceUrl); | ||
} | ||
|
||
@Override | ||
public void setOptimizerPipeline(QueryOptimizerPipeline pipeline) { | ||
delegate.setOptimizerPipeline(pipeline); | ||
} | ||
|
||
@Override | ||
public TupleExpr optimize(TupleExpr expr, EvaluationStatistics evaluationStatistics, BindingSet bindings) { | ||
|
||
if (expr instanceof PrecompiledQueryNode) { | ||
return optimizePreparedQuery((PrecompiledQueryNode) expr, bindings); | ||
} | ||
return delegate.optimize(expr, evaluationStatistics, bindings); | ||
} | ||
|
||
@Override | ||
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Service expr, String serviceUri, | ||
CloseableIteration<BindingSet, QueryEvaluationException> bindings) throws QueryEvaluationException { | ||
return delegate.evaluate(expr, serviceUri, bindings); | ||
} | ||
|
||
@Override | ||
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(TupleExpr expr, BindingSet bindings) | ||
throws QueryEvaluationException { | ||
return delegate.evaluate(expr, bindings); | ||
} | ||
|
||
@Override | ||
public Value evaluate(ValueExpr expr, BindingSet bindings) | ||
throws ValueExprEvaluationException, QueryEvaluationException { | ||
return delegate.evaluate(expr, bindings); | ||
} | ||
|
||
@Override | ||
public boolean isTrue(ValueExpr expr, BindingSet bindings) | ||
throws ValueExprEvaluationException, QueryEvaluationException { | ||
return delegate.isTrue(expr, bindings); | ||
} | ||
|
||
protected TupleExpr optimizePreparedQuery(PrecompiledQueryNode preparedQuery, BindingSet bindings) { | ||
|
||
TupleExpr actualQuery = preparedQuery.getQuery(); | ||
|
||
if (bindings != null) { | ||
new BindingAssigner().optimize(actualQuery, dataset, bindings); | ||
} | ||
|
||
return actualQuery; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
tools/federation/src/main/java/org/eclipse/rdf4j/sail/base/SailDatasetTripleSourceExt.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.