Skip to content

Commit 9a6f361

Browse files
committed
GH-4894 revert code that is still in use by our users
1 parent 440dc0e commit 9a6f361

6 files changed

Lines changed: 196 additions & 15 deletions

File tree

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Eclipse RDF4J contributors.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Distribution License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/org/documents/edl-v10.php.
8+
*
9+
* SPDX-License-Identifier: BSD-3-Clause
10+
******************************************************************************/
11+
12+
package org.eclipse.rdf4j.common.iteration;
13+
14+
import java.util.NoSuchElementException;
15+
16+
/**
17+
* An iteration that delays the creation of the underlying iteration until it is being accessed. This is mainly useful
18+
* for situations where iteration creation adds considerable overhead but where the iteration may not actually be used,
19+
* or where a created iteration consumes scarce resources like JDBC-connections or memory. Subclasses must implement the
20+
* <var>createIteration</var> method, which is called once when the iteration is first needed.
21+
*/
22+
public abstract class ThreadSafeDelayedIteration<E> extends AbstractCloseableIteration<E> {
23+
24+
/*-----------*
25+
* Variables *
26+
*-----------*/
27+
28+
private volatile CloseableIteration<? extends E> iter;
29+
30+
/*--------------*
31+
* Constructors *
32+
*--------------*/
33+
34+
/**
35+
* Creates a new DelayedIteration.
36+
*/
37+
protected ThreadSafeDelayedIteration() {
38+
super();
39+
}
40+
41+
/*---------*
42+
* Methods *
43+
*---------*/
44+
45+
/**
46+
* Creates the iteration that should be iterated over. This method is called only once, when the iteration is first
47+
* needed.
48+
*/
49+
protected abstract CloseableIteration<? extends E> createIteration();
50+
51+
/**
52+
* Calls the <var>hasNext</var> method of the underlying iteration.
53+
*/
54+
@Override
55+
public boolean hasNext() {
56+
if (isClosed()) {
57+
return false;
58+
}
59+
CloseableIteration<? extends E> resultIter = iter;
60+
if (resultIter == null) {
61+
synchronized (this) {
62+
resultIter = iter;
63+
if (resultIter == null) {
64+
// Underlying iterator has not yet been initialized
65+
resultIter = iter = createIteration();
66+
}
67+
}
68+
}
69+
70+
return resultIter.hasNext();
71+
}
72+
73+
/**
74+
* Calls the <var>next</var> method of the underlying iteration.
75+
*/
76+
@Override
77+
public E next() {
78+
if (isClosed()) {
79+
throw new NoSuchElementException("Iteration has been closed");
80+
}
81+
CloseableIteration<? extends E> resultIter = iter;
82+
if (resultIter == null) {
83+
synchronized (this) {
84+
resultIter = iter;
85+
if (resultIter == null) {
86+
// Underlying iterator has not yet been initialized
87+
resultIter = iter = createIteration();
88+
}
89+
}
90+
}
91+
92+
return resultIter.next();
93+
}
94+
95+
/**
96+
* Calls the <var>remove</var> method of the underlying iteration.
97+
*/
98+
@Override
99+
public void remove() {
100+
if (isClosed()) {
101+
throw new IllegalStateException("The iteration has been closed.");
102+
}
103+
CloseableIteration<? extends E> resultIter = iter;
104+
if (resultIter == null) {
105+
throw new IllegalStateException("Underlying iteration was null");
106+
}
107+
108+
resultIter.remove();
109+
}
110+
111+
/**
112+
* Closes this iteration as well as the underlying iteration if it has already been created and happens to be a
113+
* {@link CloseableIteration}.
114+
*/
115+
@Override
116+
protected void handleClose() {
117+
if (iter != null) {
118+
iter.close();
119+
}
120+
}
121+
}

core/model/src/main/java/org/eclipse/rdf4j/model/impl/GenericStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class GenericStatement<R extends Resource, I extends IRI, V extends Value
4848
* @param object The statement's object, must not be <var>null</var>.
4949
* @param context The statement's context, <var>null</var> to indicate no context is associated.
5050
*/
51-
protected GenericStatement(R subject, I predicate, V object, R context) {
51+
public GenericStatement(R subject, I predicate, V object, R context) {
5252
this.subject = Objects.requireNonNull(subject, "subject must not be null");
5353
this.predicate = Objects.requireNonNull(predicate, "predicate must not be null");
5454
this.object = Objects.requireNonNull(object, "object must not be null");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public class DefaultEvaluationStrategy implements EvaluationStrategy, FederatedS
212212

213213
private Supplier<CollectionFactory> collectionFactory = DefaultCollectionFactory::new;
214214

215-
static CloseableIteration<BindingSet> evaluate(TupleFunction func,
215+
protected static CloseableIteration<BindingSet> evaluate(TupleFunction func,
216216
final List<Var> resultVars, final BindingSet bindings, ValueFactory valueFactory, Value... argValues)
217217
throws QueryEvaluationException {
218218
final CloseableIteration<? extends List<? extends Value>> iter = func

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public QueryJoinOptimizer(EvaluationStatistics statistics, boolean trackResultSi
9696
*/
9797
@Override
9898
public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) {
99-
tupleExpr.visit(new JoinVisitor(statistics, trackResultSize, tripleSource));
99+
tupleExpr.visit(new JoinVisitor());
100100
}
101101

102102
/**
@@ -105,17 +105,12 @@ public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings)
105105
@SuppressWarnings("InnerClassMayBeStatic")
106106
protected class JoinVisitor extends AbstractSimpleQueryModelVisitor<RuntimeException> {
107107

108-
private final EvaluationStatistics statistics;
109-
private final TripleSource tripleSource;
110-
private final boolean trackResultSize;
111-
Set<String> boundVars = new HashSet<>();
108+
private Set<String> boundVars = new HashSet<>();
112109
private double currentHighestCost = 1;
113110

114-
private JoinVisitor(EvaluationStatistics statistics, boolean trackResultSize, TripleSource tripleSource) {
111+
protected JoinVisitor() {
115112
super(trackResultSize);
116-
this.statistics = statistics;
117-
this.tripleSource = tripleSource;
118-
this.trackResultSize = trackResultSize;
113+
119114
}
120115

121116
@Override
@@ -332,7 +327,7 @@ public void meet(Join node) {
332327

333328
private void optimizeInNewScope(List<TupleExpr> subSelects) {
334329
for (TupleExpr subSelect : subSelects) {
335-
subSelect.visit(new JoinVisitor(statistics, trackResultSize, tripleSource));
330+
subSelect.visit(new JoinVisitor());
336331
}
337332
}
338333

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ public interface TupleExpr extends QueryModelNode {
3939
TupleExpr clone();
4040

4141
@Experimental
42-
Set<Var> getSupportedOrders(AvailableStatementOrder tripleSource);
42+
default Set<Var> getSupportedOrders(AvailableStatementOrder tripleSource) {
43+
return Set.of();
44+
}
4345

4446
@Experimental
45-
void setOrder(Var var);
47+
default void setOrder(Var var) {
48+
throw new UnsupportedOperationException("Ordering is not supported for this TupleExpr");
49+
}
4650

4751
@Experimental
48-
Var getOrder();
52+
default Var getOrder() {
53+
throw new UnsupportedOperationException("Ordering is not supported for this TupleExpr");
54+
}
4955
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Eclipse RDF4J contributors.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Distribution License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/org/documents/edl-v10.php.
8+
*
9+
* SPDX-License-Identifier: BSD-3-Clause
10+
******************************************************************************/
11+
package org.eclipse.rdf4j.query.algebra.helpers.collectors;
12+
13+
import java.util.ArrayList;
14+
import java.util.Collections;
15+
import java.util.List;
16+
17+
import org.eclipse.rdf4j.query.algebra.Join;
18+
import org.eclipse.rdf4j.query.algebra.QueryModelNode;
19+
import org.eclipse.rdf4j.query.algebra.QueryModelVisitor;
20+
import org.eclipse.rdf4j.query.algebra.StatementPattern;
21+
import org.eclipse.rdf4j.query.algebra.helpers.AbstractQueryModelVisitor;
22+
23+
/**
24+
* Basic graph pattern collector.
25+
*/
26+
public class BGPCollector<X extends Exception> extends AbstractQueryModelVisitor<X> {
27+
28+
private final QueryModelVisitor<X> visitor;
29+
30+
private List<StatementPattern> statementPatterns;
31+
32+
public BGPCollector(QueryModelVisitor<X> visitor) {
33+
this.visitor = visitor;
34+
}
35+
36+
public List<StatementPattern> getStatementPatterns() {
37+
return (statementPatterns != null) ? statementPatterns : Collections.emptyList();
38+
}
39+
40+
@Override
41+
public void meet(Join node) throws X {
42+
// by-pass meetNode()
43+
node.visitChildren(this);
44+
}
45+
46+
@Override
47+
public void meet(StatementPattern sp) throws X {
48+
if (statementPatterns == null) {
49+
statementPatterns = new ArrayList<>();
50+
}
51+
statementPatterns.add(sp);
52+
}
53+
54+
@Override
55+
protected void meetNode(QueryModelNode node) throws X {
56+
// resume previous visitor
57+
node.visit(visitor);
58+
}
59+
}

0 commit comments

Comments
 (0)