This repository has been archived by the owner on Feb 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eclipse-rdf4j/rdf4j#1378 simplified code
Signed-off-by: Håvard Ottestad <[email protected]>
- Loading branch information
1 parent
4389140
commit 89243d6
Showing
4 changed files
with
105 additions
and
108 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/planNodes/AbstractBulkJoinPlanNode.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,85 @@ | ||
/******************************************************************************* | ||
* 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.sail.shacl.planNodes; | ||
|
||
import org.eclipse.rdf4j.common.iteration.Iterations; | ||
import org.eclipse.rdf4j.model.Resource; | ||
import org.eclipse.rdf4j.query.BindingSet; | ||
import org.eclipse.rdf4j.query.algebra.BindingSetAssignment; | ||
import org.eclipse.rdf4j.query.algebra.helpers.AbstractQueryModelVisitor; | ||
import org.eclipse.rdf4j.query.impl.ListBindingSet; | ||
import org.eclipse.rdf4j.query.impl.MapBindingSet; | ||
import org.eclipse.rdf4j.query.parser.ParsedQuery; | ||
import org.eclipse.rdf4j.sail.SailConnection; | ||
import org.eclipse.rdf4j.sail.shacl.ShaclSailConnection; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
abstract class AbstractBulkJoinPlanNode implements PlanNode { | ||
|
||
static void runQuery(ArrayDeque<Tuple> left, ArrayDeque<Tuple> right, SailConnection connection, | ||
ParsedQuery parsedQuery, boolean skipBasedOnPreviousConnection) { | ||
List<BindingSet> newBindindingset = buildBindingSets(left, connection, skipBasedOnPreviousConnection); | ||
|
||
if (!newBindindingset.isEmpty()) { | ||
updateQuery(parsedQuery, newBindindingset); | ||
executeQuery(right, connection, parsedQuery); | ||
} | ||
} | ||
|
||
private static void executeQuery(ArrayDeque<Tuple> right, SailConnection connection, ParsedQuery parsedQuery) { | ||
|
||
try (Stream<? extends BindingSet> stream = Iterations.stream( | ||
connection.evaluate(parsedQuery.getTupleExpr(), parsedQuery.getDataset(), new MapBindingSet(), true))) { | ||
stream | ||
.map(Tuple::new) | ||
.forEach(right::addFirst); | ||
} | ||
|
||
} | ||
|
||
private static void updateQuery(ParsedQuery parsedQuery, List<BindingSet> newBindindingset) { | ||
try { | ||
parsedQuery.getTupleExpr() | ||
.visitChildren(new AbstractQueryModelVisitor<Exception>() { | ||
@Override | ||
public void meet(BindingSetAssignment node) { | ||
node.setBindingSets(newBindindingset); | ||
} | ||
}); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static List<BindingSet> buildBindingSets(ArrayDeque<Tuple> left, SailConnection connection, | ||
boolean skipBasedOnPreviousConnection) { | ||
return left.stream() | ||
.map(tuple -> tuple.line.get(0)) | ||
.map(v -> (Resource) v) | ||
.filter(r -> { | ||
if (!skipBasedOnPreviousConnection) { | ||
return true; | ||
} | ||
|
||
if (connection instanceof ShaclSailConnection) { | ||
return ((ShaclSailConnection) connection).getPreviousStateConnection() | ||
.hasStatement(r, null, null, true); | ||
} | ||
return true; | ||
|
||
}) | ||
.map(r -> new ListBindingSet(Collections.singletonList("a"), Collections.singletonList(r))) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
} |
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
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
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