Skip to content

Commit

Permalink
Halyard v5.0 (RDF4J v5).
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Hale authored and pulquero committed Jul 9, 2024
1 parent c96af92 commit e234cbe
Show file tree
Hide file tree
Showing 111 changed files with 1,629 additions and 1,754 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.pulquero.halyard</groupId>
<artifactId>halyard</artifactId>
<version>4.10</version>
<version>5.0</version>
</parent>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public interface ExtendedTripleSource extends TripleSource {
default boolean hasStatement(Resource subj, IRI pred, Value obj, Resource... contexts) throws QueryEvaluationException {
try (CloseableIteration<? extends Statement, QueryEvaluationException> iter = getStatements(subj, pred, obj, contexts)) {
try (CloseableIteration<? extends Statement> iter = getStatements(subj, pred, obj, contexts)) {
return iter.hasNext();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import org.eclipse.rdf4j.query.algebra.evaluation.function.TupleFunction;

public interface ExtendedTupleFunction extends TupleFunction {
CloseableIteration<? extends List<? extends Value>, QueryEvaluationException> evaluate(
CloseableIteration<? extends List<? extends Value>> evaluate(
TripleSource tripleSource, Value... args) throws QueryEvaluationException;

@Override
default CloseableIteration<? extends List<? extends Value>, QueryEvaluationException> evaluate(ValueFactory vf,
default CloseableIteration<? extends List<? extends Value>> evaluate(ValueFactory vf,
Value... args) throws QueryEvaluationException {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package com.msd.gin.halyard.sail;

import java.util.function.Consumer;

import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.Dataset;
import org.eclipse.rdf4j.query.QueryEvaluationException;
import org.eclipse.rdf4j.query.algebra.TupleExpr;
import org.eclipse.rdf4j.sail.SailConnection;

public interface BindingSetConsumerSailConnection extends SailConnection {
default void evaluate(Consumer<BindingSet> handler, final TupleExpr tupleExpr, final Dataset dataset, final BindingSet bindings, final boolean includeInferred) {
report(evaluate(tupleExpr, dataset, bindings, includeInferred), handler);
}

static void report(CloseableIteration<? extends BindingSet, QueryEvaluationException> iter, Consumer<BindingSet> handler) {
while (iter.hasNext()) {
handler.accept(iter.next());
}
}
}
package com.msd.gin.halyard.sail;

import java.util.function.Consumer;

import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.Dataset;
import org.eclipse.rdf4j.query.algebra.TupleExpr;
import org.eclipse.rdf4j.sail.SailConnection;

public interface BindingSetConsumerSailConnection extends SailConnection {
default void evaluate(Consumer<BindingSet> handler, final TupleExpr tupleExpr, final Dataset dataset, final BindingSet bindings, final boolean includeInferred) {
report(evaluate(tupleExpr, dataset, bindings, includeInferred), handler);
}

static void report(CloseableIteration<? extends BindingSet> iter, Consumer<BindingSet> handler) {
while (iter.hasNext()) {
handler.accept(iter.next());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
package com.msd.gin.halyard.sail;

import com.msd.gin.halyard.query.BindingSetPipe;

import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.Dataset;
import org.eclipse.rdf4j.query.QueryEvaluationException;
import org.eclipse.rdf4j.query.algebra.TupleExpr;
import org.eclipse.rdf4j.sail.SailConnection;

public interface BindingSetPipeSailConnection extends SailConnection {
default void evaluate(BindingSetPipe pipe, final TupleExpr tupleExpr, final Dataset dataset, final BindingSet bindings, final boolean includeInferred) {
report(evaluate(tupleExpr, dataset, bindings, includeInferred), pipe);
pipe.close();
}

/**
* NB: does not close the pipe so you can report multiple iterations to the same pipe.
* @param iter iteration of binding sets to push to the pipe
* @param pipe the pipe to push to
* @return true if the pipe can accept more binding sets
*/
static boolean report(CloseableIteration<? extends BindingSet, QueryEvaluationException> iter, BindingSetPipe pipe) {
while (iter.hasNext()) {
if (!pipe.push(iter.next())) {
return false;
}
}
return true;
}
}
package com.msd.gin.halyard.sail;

import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.Dataset;
import org.eclipse.rdf4j.query.algebra.TupleExpr;
import org.eclipse.rdf4j.sail.SailConnection;

import com.msd.gin.halyard.query.BindingSetPipe;

public interface BindingSetPipeSailConnection extends SailConnection {
default void evaluate(BindingSetPipe pipe, final TupleExpr tupleExpr, final Dataset dataset, final BindingSet bindings, final boolean includeInferred) {
report(evaluate(tupleExpr, dataset, bindings, includeInferred), pipe);
pipe.close();
}

/**
* NB: does not close the pipe so you can report multiple iterations to the same pipe.
* @param iter iteration of binding sets to push to the pipe
* @param pipe the pipe to push to
* @return true if the pipe can accept more binding sets
*/
static boolean report(CloseableIteration<? extends BindingSet> iter, BindingSetPipe pipe) {
while (iter.hasNext()) {
if (!pipe.push(iter.next())) {
return false;
}
}
return true;
}
}
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.pulquero.halyard</groupId>
<artifactId>halyard</artifactId>
<version>4.10</version>
<version>5.0</version>
</parent>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.msd.gin.halyard.common;

import java.util.Objects;

import javax.annotation.Nullable;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.impl.ContextStatement;
import org.eclipse.rdf4j.model.impl.SimpleStatement;
import org.eclipse.rdf4j.model.base.AbstractStatement;

public class TimestampedValueFactory extends IdValueFactory {
private static final long serialVersionUID = -9091778283847281070L;

public TimestampedValueFactory(@Nullable RDFFactory rdfFactory) {
super(rdfFactory);
}
Expand All @@ -25,12 +28,37 @@ public Statement createStatement(Resource subject, IRI predicate, Value object,
}


static final class TimestampedStatement extends SimpleStatement implements Timestamped {
static final class TimestampedStatement extends AbstractStatement implements Timestamped {
private static final long serialVersionUID = -3767773807995225622L;
private final Resource subject;
private final IRI predicate;
private final Value object;
private long ts;

TimestampedStatement(Resource subject, IRI predicate, Value object) {
super(subject, predicate, object);
this.subject = Objects.requireNonNull(subject);
this.predicate = Objects.requireNonNull(predicate);
this.object = Objects.requireNonNull(object);
}

@Override
public Resource getSubject() {
return subject;
}

@Override
public IRI getPredicate() {
return predicate;
}

@Override
public Value getObject() {
return object;
}

@Override
public Resource getContext() {
return null;
}

@Override
Expand All @@ -48,12 +76,39 @@ public String toString() {
}
}

static final class TimestampedContextStatement extends ContextStatement implements Timestamped {
static final class TimestampedContextStatement extends AbstractStatement implements Timestamped {
private static final long serialVersionUID = 6631073994472700544L;
private final Resource subject;
private final IRI predicate;
private final Value object;
private final Resource context;
private long ts;

TimestampedContextStatement(Resource subject, IRI predicate, Value object, Resource context) {
super(subject, predicate, object, context);
this.subject = Objects.requireNonNull(subject);
this.predicate = Objects.requireNonNull(predicate);
this.object = Objects.requireNonNull(object);
this.context = context;
}

@Override
public Resource getSubject() {
return subject;
}

@Override
public IRI getPredicate() {
return predicate;
}

@Override
public Value getObject() {
return object;
}

@Override
public Resource getContext() {
return context;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.pulquero.halyard</groupId>
<artifactId>halyard</artifactId>
<version>4.10</version>
<version>5.0</version>
</parent>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public final class HALYARD implements Vocabulary {
public final static IRI GET_FUNCTION = SVF.createIRI(NAMESPACE, "get");
public final static IRI SLICE_FUNCTION = SVF.createIRI(NAMESPACE, "slice");
public final static IRI FROM_TUPLE = SVF.createIRI(NAMESPACE, "fromTuple");
public final static IRI LIKE_FUNCTION = SVF.createIRI(NAMESPACE, "like");

public final static IRI MAX_WITH_FUNCTION = SVF.createIRI(NAMESPACE, "maxWith");
public final static IRI MIN_WITH_FUNCTION = SVF.createIRI(NAMESPACE, "minWith");
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.pulquero.halyard</groupId>
<artifactId>halyard</artifactId>
<version>4.10</version>
<version>5.0</version>
<packaging>pom</packaging>
<organization><name>halyard</name></organization>
<name>Halyard-star</name>
Expand All @@ -31,7 +31,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<rdf4j.version>4.3.11</rdf4j.version>
<rdf4j.version>5.0.0</rdf4j.version>
<hbase.version>2.5.5</hbase.version>
<hbase-connectors.version>1.0.0</hbase-connectors.version>
<hadoop.version>3.3.6</hadoop.version>
Expand Down
2 changes: 1 addition & 1 deletion queryalgebra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.pulquero.halyard</groupId>
<artifactId>halyard</artifactId>
<version>4.10</version>
<version>5.0</version>
</parent>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package com.msd.gin.halyard.query.algebra.evaluation;

import com.msd.gin.halyard.query.algebra.evaluation.QueryPreparer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -73,7 +71,7 @@ public Update prepare(ParsedUpdate u) {
return new UpdateImpl(u);
}

protected abstract CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluate(TupleExpr tupleExpr,
protected abstract CloseableIteration<? extends BindingSet> evaluate(TupleExpr tupleExpr,
Dataset dataset, BindingSet bindings, boolean includeInferred, int maxExecutionTime)
throws QueryEvaluationException;

Expand All @@ -96,8 +94,8 @@ public ParsedBooleanQuery getParsedQuery() {

@Override
public boolean evaluate() throws QueryEvaluationException {
CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter1 = null;
CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter2 = null;
CloseableIteration<? extends BindingSet> bindingsIter1 = null;
CloseableIteration<? extends BindingSet> bindingsIter2 = null;
try {
ParsedBooleanQuery parsedBooleanQuery = getParsedQuery();
TupleExpr tupleExpr = parsedBooleanQuery.getTupleExpr();
Expand Down Expand Up @@ -144,8 +142,8 @@ public ParsedTupleQuery getParsedQuery() {

@Override
public TupleQueryResult evaluate() throws QueryEvaluationException {
CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter1 = null;
CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter2 = null;
CloseableIteration<? extends BindingSet> bindingsIter1 = null;
CloseableIteration<? extends BindingSet> bindingsIter2 = null;
IteratingTupleQueryResult result = null;
boolean allGood = false;
try {
Expand Down Expand Up @@ -203,10 +201,10 @@ public ParsedGraphQuery getParsedQuery() {

@Override
public GraphQueryResult evaluate() throws QueryEvaluationException {
CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter1 = null;
CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter2 = null;
CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter3 = null;
CloseableIteration<? extends Statement, QueryEvaluationException> stIter = null;
CloseableIteration<? extends BindingSet> bindingsIter1 = null;
CloseableIteration<? extends BindingSet> bindingsIter2 = null;
CloseableIteration<? extends BindingSet> bindingsIter3 = null;
CloseableIteration<? extends Statement> stIter = null;
IteratingGraphQueryResult result = null;

boolean allGood = false;
Expand All @@ -216,7 +214,7 @@ public GraphQueryResult evaluate() throws QueryEvaluationException {
getIncludeInferred(), getMaxExecutionTime());

// Filters out all partial and invalid matches
bindingsIter2 = new FilterIteration<BindingSet, QueryEvaluationException>(bindingsIter1) {
bindingsIter2 = new FilterIteration<BindingSet>(bindingsIter1) {

@Override
protected boolean accept(BindingSet bindingSet) {
Expand All @@ -226,12 +224,16 @@ protected boolean accept(BindingSet bindingSet) {
&& bindingSet.getValue("predicate") instanceof IRI
&& (context == null || context instanceof Resource);
}

@Override
protected void handleClose() {
}
};

bindingsIter3 = enforceMaxQueryTime(bindingsIter2);

// Convert the BindingSet objects to actual RDF statements
stIter = new ConvertingIteration<BindingSet, Statement, QueryEvaluationException>(bindingsIter3) {
stIter = new ConvertingIteration<BindingSet, Statement>(bindingsIter3) {

private final ValueFactory vf = getValueFactory();

Expand Down
Loading

0 comments on commit e234cbe

Please sign in to comment.