Skip to content

Commit 8580bfe

Browse files
committed
GH-4819 code cleanup and add javadocs
1 parent a8fb86a commit 8580bfe

11 files changed

Lines changed: 108 additions & 22 deletions

File tree

core/common/iterator/src/main/java/org/eclipse/rdf4j/common/iteration/DualUnionIteration.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Comparator;
1515
import java.util.NoSuchElementException;
1616

17+
import org.eclipse.rdf4j.common.annotation.Experimental;
1718
import org.eclipse.rdf4j.common.order.StatementOrder;
1819
import org.eclipse.rdf4j.model.Value;
1920

@@ -40,6 +41,7 @@ private DualUnionIteration(CloseableIteration<? extends E> iteration1,
4041
this.cmp = null;
4142
}
4243

44+
@Experimental
4345
public DualUnionIteration(StatementOrder statementOrder, Comparator<Value> cmp,
4446
CloseableIteration<? extends E> iteration1, CloseableIteration<? extends E> iteration2) {
4547
this.iteration1 = iteration1;
@@ -51,7 +53,7 @@ public DualUnionIteration(StatementOrder statementOrder, Comparator<Value> cmp,
5153
throw new UnsupportedOperationException("Not implemented yet");
5254
}
5355

54-
public static <E, X extends Exception> CloseableIteration<? extends E> getWildcardInstance(
56+
public static <E> CloseableIteration<? extends E> getWildcardInstance(
5557
CloseableIteration<? extends E> leftIteration, CloseableIteration<? extends E> rightIteration) {
5658

5759
if (rightIteration instanceof EmptyIteration) {
@@ -63,7 +65,8 @@ public static <E, X extends Exception> CloseableIteration<? extends E> getWildca
6365
}
6466
}
6567

66-
public static <E, X extends Exception> CloseableIteration<? extends E> getWildcardInstance(StatementOrder order,
68+
@Experimental
69+
public static <E> CloseableIteration<? extends E> getWildcardInstance(StatementOrder order,
6770
Comparator<Value> cmp,
6871
CloseableIteration<? extends E> leftIteration, CloseableIteration<? extends E> rightIteration) {
6972

@@ -84,7 +87,7 @@ public static <E, X extends Exception> CloseableIteration<? extends E> getWildca
8487
}
8588
}
8689

87-
public static <E, X extends Exception> CloseableIteration<E> getInstance(CloseableIteration<E> leftIteration,
90+
public static <E> CloseableIteration<E> getInstance(CloseableIteration<E> leftIteration,
8891
CloseableIteration<E> rightIteration) {
8992

9093
if (rightIteration instanceof EmptyIteration) {

core/common/order/src/main/java/org/eclipse/rdf4j/common/order/AvailableStatementOrder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
import java.util.Set;
1515

16+
import org.eclipse.rdf4j.common.annotation.Experimental;
1617
import org.eclipse.rdf4j.model.IRI;
1718
import org.eclipse.rdf4j.model.Resource;
1819
import org.eclipse.rdf4j.model.Value;
1920

21+
@Experimental
2022
public interface AvailableStatementOrder {
2123

24+
@Experimental
2225
Set<StatementOrder> getSupportedOrders(Resource subj, IRI pred, Value obj, Resource... contexts);
2326
}

core/common/order/src/main/java/org/eclipse/rdf4j/common/order/StatementOrder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313

1414
import java.util.Comparator;
1515

16+
import org.eclipse.rdf4j.common.annotation.Experimental;
1617
import org.eclipse.rdf4j.model.Statement;
1718
import org.eclipse.rdf4j.model.Value;
1819

20+
@Experimental
1921
public enum StatementOrder {
2022

2123
S,
2224
P,
2325
O,
2426
C;
2527

28+
@Experimental
2629
public Comparator<Statement> getComparator(Comparator<Value> comparator) {
2730
switch (this) {
2831
case S:

core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/RDFStarTripleSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface RDFStarTripleSource extends TripleSource {
2323
* indicate wildcards.
2424
*
2525
* @param subj A Resource specifying the triple's subject, or <var>null</var> for a wildcard.
26-
* @param pred A URI specifying the triple's predicate, or <var>null</var> for a wildcard.
26+
* @param pred A IRI specifying the triple's predicate, or <var>null</var> for a wildcard.
2727
* @param obj A Value specifying the triple's object, or <var>null</var> for a wildcard.
2828
* @return An iterator over the relevant triples.
2929
* @throws QueryEvaluationException If the rdf star triple source failed to get the statements.

core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/TripleSource.java

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.EnumSet;
1515
import java.util.Set;
1616

17+
import org.eclipse.rdf4j.common.annotation.Experimental;
1718
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
1819
import org.eclipse.rdf4j.common.iteration.EmptyIteration;
1920
import org.eclipse.rdf4j.common.order.AvailableStatementOrder;
@@ -33,15 +34,14 @@
3334
public interface TripleSource extends AvailableStatementOrder {
3435

3536
EmptyIteration<? extends Statement> EMPTY_ITERATION = new EmptyIteration<>();
36-
EmptyIteration<? extends Triple> EMPTY_TRIPLE_ITERATION = new EmptyIteration<>();
3737

3838
/**
3939
* Gets all statements that have a specific subject, predicate and/or object. All three parameters may be null to
4040
* indicate wildcards. Optionally a (set of) context(s) may be specified in which case the result will be restricted
4141
* to statements matching one or more of the specified contexts.
4242
*
4343
* @param subj A Resource specifying the subject, or <var>null</var> for a wildcard.
44-
* @param pred A URI specifying the predicate, or <var>null</var> for a wildcard.
44+
* @param pred A IRI specifying the predicate, or <var>null</var> for a wildcard.
4545
* @param obj A Value specifying the object, or <var>null</var> for a wildcard.
4646
* @param contexts The context(s) to get the statements from. Note that this parameter is a vararg and as such is
4747
* optional. If no contexts are supplied the method operates on the entire repository.
@@ -55,34 +55,70 @@ CloseableIteration<? extends Statement> getStatements(Resource subj, IRI pred,
5555
* Gets all statements that have a specific subject, predicate and/or object. All three parameters may be null to
5656
* indicate wildcards. Optionally a (set of) context(s) may be specified in which case the result will be restricted
5757
* to statements matching one or more of the specified contexts.
58+
* <p>
59+
* Statements are returned in the order specified by the <var>statementOrder</var> parameter. Use
60+
* {@link #getSupportedOrders(Resource, IRI, Value, Resource...)} to first retrieve the statement orders supported
61+
* by this store for this statement pattern.
62+
* <p>
63+
* Note that this method is experimental and may be changed or removed without notice.
5864
*
65+
* @param order The order in which the statements should be returned.
5966
* @param subj A Resource specifying the subject, or <var>null</var> for a wildcard.
60-
* @param pred A URI specifying the predicate, or <var>null</var> for a wildcard.
67+
* @param pred A IRI specifying the predicate, or <var>null</var> for a wildcard.
6168
* @param obj A Value specifying the object, or <var>null</var> for a wildcard.
6269
* @param contexts The context(s) to get the statements from. Note that this parameter is a vararg and as such is
6370
* optional. If no contexts are supplied the method operates on the entire repository.
64-
* @return An iterator over the relevant statements.
71+
* @return An ordered iterator over the relevant statements.
6572
* @throws QueryEvaluationException If the triple source failed to get the statements.
6673
*/
74+
@Experimental
6775
default CloseableIteration<? extends Statement> getStatements(StatementOrder order, Resource subj, IRI pred,
6876
Value obj, Resource... contexts) throws QueryEvaluationException {
6977
throw new UnsupportedOperationException(
7078
"StatementOrder is not supported by this TripleSource: " + this.getClass().getName());
7179
}
7280

73-
default Set<StatementOrder> getSupportedOrders(Resource subj, IRI pred,
74-
Value obj, Resource... contexts) throws QueryEvaluationException {
81+
/**
82+
* The underlying store may support some, but not all, statement orders based on the statement pattern. This method
83+
* can be used to determine which orders are supported for a given statement pattern. The supported orders can be
84+
* used to retrieve statements in a specific order using
85+
* {@link #getStatements(StatementOrder, Resource, IRI, Value, Resource...)} .
86+
* <p>
87+
* Note that this method is experimental and may be changed or removed without notice.
88+
*
89+
* @param subj A Resource specifying the subject, or <var>null</var> for a wildcard.
90+
* @param pred A IRI specifying the predicate, or <var>null</var> for a wildcard.
91+
* @param obj A Value specifying the object, or <var>null</var> for a wildcard.
92+
* @param contexts The context(s) to get the data from. Note that this parameter is a vararg and as such is
93+
* optional. If no contexts are specified the method operates on the entire repository. A
94+
* <var>null</var> value can be used to match context-less statements.
95+
* @return a set of supported statement orders
96+
*/
97+
@Experimental
98+
default Set<StatementOrder> getSupportedOrders(Resource subj, IRI pred, Value obj, Resource... contexts) {
7599
return Set.of();
76100
}
77101

78102
/**
79-
* Gets a ValueFactory object that can be used to create URI-, blank node- and literal objects.
103+
* Different underlying datastructures may have different ways of ordering statements. On-disk stores typically use
104+
* a long to represent a value and only stores the actual value in a dictionary, in this case the order would be the
105+
* order that values where inserted into the dictionary. Stores that instead store values in SPARQL-order can return
106+
* an instance of {@link org.eclipse.rdf4j.query.algebra.evaluation.util.ValueComparator} which may allow for
107+
* further optimizations.
108+
* <p>
109+
* Note that this method is experimental and may be changed or removed without notice.
80110
*
81-
* @return a ValueFactory object for this TripleSource.
111+
* @return a comparator that matches the order of values in the store
82112
*/
83-
ValueFactory getValueFactory();
84-
113+
@Experimental
85114
default Comparator<Value> getComparator() {
86115
return null;
87116
}
117+
118+
/**
119+
* Gets a ValueFactory object that can be used to create IRI-, blank node- and literal objects.
120+
*
121+
* @return a ValueFactory object for this TripleSource.
122+
*/
123+
ValueFactory getValueFactory();
88124
}

core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/impl/EvaluationStatistics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void meet(ArbitraryLengthPath node) {
129129
@Override
130130
public void meet(Service node) {
131131
if (!node.getServiceRef().hasValue()) {
132-
// the URI is not available, may be computed in the course of the
132+
// the IRI is not available, may be computed in the course of the
133133
// query
134134
// => use high cost to order the SERVICE node late in the query plan
135135
cardinality = UNBOUND_SERVICE_CARDINALITY;

core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/util/ValueComparator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public int compare(Value o1, Value o2) {
6363
boolean iri1 = o1.isIRI();
6464
boolean iri2 = o2.isIRI();
6565
if (iri1 && iri2) {
66-
return compareURIs((IRI) o1, (IRI) o2);
66+
return compareIRIs((IRI) o1, (IRI) o2);
6767
}
6868
if (iri1) {
6969
return -1;
@@ -101,8 +101,8 @@ private int compareBNodes(BNode leftBNode, BNode rightBNode) {
101101
return leftBNode.getID().compareTo(rightBNode.getID());
102102
}
103103

104-
private int compareURIs(IRI leftURI, IRI rightURI) {
105-
return leftURI.toString().compareTo(rightURI.toString());
104+
private int compareIRIs(IRI leftIRI, IRI rightIRI) {
105+
return leftIRI.toString().compareTo(rightIRI.toString());
106106
}
107107

108108
private int compareLiterals(Literal leftLit, Literal rightLit) {
@@ -211,7 +211,7 @@ private int compareDatatypes(CoreDatatype.XSD leftDatatype, CoreDatatype.XSD rig
211211
}
212212

213213
// incompatible or unordered datatype
214-
return compareURIs(leftDatatypeIRI, rightDatatypeIRI);
214+
return compareIRIs(leftDatatypeIRI, rightDatatypeIRI);
215215

216216
}
217217

core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/TupleExpr.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.util.Set;
1414

15+
import org.eclipse.rdf4j.common.annotation.Experimental;
1516
import org.eclipse.rdf4j.common.order.AvailableStatementOrder;
1617

1718
/**
@@ -37,9 +38,12 @@ public interface TupleExpr extends QueryModelNode {
3738
@Override
3839
TupleExpr clone();
3940

41+
@Experimental
4042
Set<Var> getSupportedOrders(AvailableStatementOrder tripleSource);
4143

44+
@Experimental
4245
void setOrder(Var var);
4346

47+
@Experimental
4448
Var getOrder();
4549
}

core/repository/contextaware/src/main/java/org/eclipse/rdf4j/repository/contextaware/ContextAwareConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public void exportStatements(Resource subj, IRI pred, Value obj, boolean include
458458
* optionally restricted to the specified set of named contexts.
459459
*
460460
* @param subj A Resource specifying the subject, or <var>null</var> for a wildcard.
461-
* @param pred A URI specifying the predicate, or <var>null</var> for a wildcard.
461+
* @param pred A IRI specifying the predicate, or <var>null</var> for a wildcard.
462462
* @param obj A Value specifying the object, or <var>null</var> for a wildcard.
463463
* @return The statements matching the specified pattern. The result object is a {@link RepositoryResult} object, a
464464
* lazy Iterator-like object containing {@link Statement}s and optionally throwing a
@@ -511,7 +511,7 @@ public boolean hasStatement(Statement st, boolean includeInferred, Resource... c
511511
* the specified contexts.
512512
*
513513
* @param subj A Resource specifying the subject, or <var>null</var> for a wildcard.
514-
* @param pred A URI specifying the predicate, or <var>null</var> for a wildcard.
514+
* @param pred A IRI specifying the predicate, or <var>null</var> for a wildcard.
515515
* @param obj A Value specifying the object, or <var>null</var> for a wildcard.
516516
* @return true If a matching statement is in the repository in the specified context, false otherwise.
517517
* @see #getReadContexts()

core/sail/api/src/main/java/org/eclipse/rdf4j/sail/SailConnection.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ CloseableIteration<? extends Statement> getStatements(Resource subj, IRI pred, V
125125
* Gets all statements from the specified contexts that have a specific subject, predicate and/or object. All three
126126
* parameters may be null to indicate wildcards. The <var>includeInferred</var> parameter can be used to control
127127
* which statements are fetched: all statements or only the statements that have been added explicitly.
128+
* <p>
129+
* Statements are returned in the order specified by the <var>statementOrder</var> parameter. Use
130+
* {@link #getSupportedOrders(Resource, IRI, Value, Resource...)} to first retrieve the statement orders supported
131+
* by this store for this statement pattern.
132+
* <p>
133+
* Note that this method is experimental and may be changed or removed without notice.
134+
*
128135
*
129136
* @param statementOrder The order that the statements should be returned in.
130137
* @param subj A Resource specifying the subject, or <var>null</var> for a wildcard.
@@ -139,6 +146,7 @@ CloseableIteration<? extends Statement> getStatements(Resource subj, IRI pred, V
139146
* @throws SailException If the Sail object encountered an error or unexpected situation internally.
140147
* @throws IllegalStateException If the connection has been closed.
141148
*/
149+
@Experimental
142150
default CloseableIteration<? extends Statement> getStatements(StatementOrder statementOrder, Resource subj,
143151
IRI pred, Value obj,
144152
boolean includeInferred, Resource... contexts) throws SailException {
@@ -468,10 +476,39 @@ default Explanation explain(Explanation.Level level, TupleExpr tupleExpr, Datase
468476
throw new UnsupportedOperationException();
469477
}
470478

479+
/**
480+
* The underlying store may support some, but not all, statement orders based on the statement pattern. This method
481+
* can be used to determine which orders are supported for a given statement pattern. The supported orders can be
482+
* used to retrieve statements in a specific order using
483+
* {@link #getStatements(StatementOrder, Resource, IRI, Value, boolean, Resource...)}.
484+
* <p>
485+
* Note that this method is experimental and may be changed or removed without notice.
486+
*
487+
* @param subj A Resource specifying the subject, or <var>null</var> for a wildcard.
488+
* @param pred A URI specifying the predicate, or <var>null</var> for a wildcard.
489+
* @param obj A Value specifying the object, or <var>null</var> for a wildcard.
490+
* @param contexts The context(s) to get the data from. Note that this parameter is a vararg and as such is
491+
* optional. If no contexts are specified the method operates on the entire repository. A
492+
* <var>null</var> value can be used to match context-less statements.
493+
* @return a set of supported statement orders
494+
*/
495+
@Experimental
471496
default Set<StatementOrder> getSupportedOrders(Resource subj, IRI pred, Value obj, Resource... contexts) {
472497
return Set.of();
473498
}
474499

500+
/**
501+
* Different underlying datastructures may have different ways of ordering statements. On-disk stores typically use
502+
* a long to represent a value and only stores the actual value in a dictionary, in this case the order would be the
503+
* order that values where inserted into the dictionary. Stores that instead store values in SPARQL-order can return
504+
* an instance of {@link org.eclipse.rdf4j.query.algebra.evaluation.util.ValueComparator} which may allow for
505+
* further optimizations.
506+
* <p>
507+
* Note that this method is experimental and may be changed or removed without notice.
508+
*
509+
* @return a comparator that matches the order of values in the store
510+
*/
511+
@Experimental
475512
default Comparator<Value> getComparator() {
476513
return null;
477514
}

0 commit comments

Comments
 (0)