Skip to content

Commit b7a2976

Browse files
GH-4899 Add more documentation and throw errors if things are not used as they are supposed to
Signed-off-by: Jerven Bolleman <jerven.bolleman@sib.swiss>
1 parent 8ee693e commit b7a2976

1 file changed

Lines changed: 39 additions & 4 deletions

File tree

  • core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/iterator

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

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class PathIteration extends LookAheadIteration<BindingSet> {
4444
private static final String START = "$start_from_path_iteration";
4545

4646
/**
47-
*
47+
* Required as we can't prepare the queries yet.
4848
*/
4949
private final EvaluationStrategy strategy;
5050

@@ -81,8 +81,16 @@ public class PathIteration extends LookAheadIteration<BindingSet> {
8181
private final Set<String> namedIntermediateJoins = new HashSet<>();
8282

8383
private final CollectionFactory collectionFactory;
84+
/**
85+
* Instead of depending on hash codes not colliding we instead make sure that each element is unique per iteration.
86+
* Which is why this is a static volatile field. As more than one path iteration can be present in the same query.
87+
*/
8488
private static volatile int PATH_ITERATOR_ID_GENERATOR = 0;
8589

90+
/**
91+
* Using the ++ to increment the volatile shared id generator, the id in this iterator must remain constant during
92+
* execution.
93+
*/
8694
private final int pathIteratorId = PATH_ITERATOR_ID_GENERATOR++;
8795
private final String endVarName = "END_" + JOINVAR_PREFIX + pathIteratorId;
8896

@@ -117,6 +125,12 @@ public PathIteration(EvaluationStrategy strategy, Scope scope, Var startVar,
117125
createIteration();
118126
}
119127

128+
/**
129+
* Used to turn a method call into a direct field access
130+
*
131+
* @param s the name of the variable to see if it is in the bindingset
132+
* @return the value of the start or end or if asked for a different field a null.
133+
*/
120134
private static final BiConsumer<Value, MutableBindingSet> getSet(String s) {
121135
switch (s) {
122136
case START:
@@ -125,29 +139,46 @@ private static final BiConsumer<Value, MutableBindingSet> getSet(String s) {
125139
return (v, vp) -> ((ValuePair) vp).endValue = v;
126140
default:
127141
return (v, vp) -> {
142+
throw new IllegalStateException("A value is being asked to be set where we never expected one");
128143
};
129144
}
130145
}
131146

147+
/**
148+
* Used to turn a method call into a direct field access
149+
*
150+
* @param s the name of the variable to see if it is in the bindingset
151+
* @return the value of the start or end, if asked for a different field throw an illegalstate exception
152+
*/
132153
private static final Function<BindingSet, Value> getGet(String s) {
133154
switch (s) {
134155
case START:
135156
return (vp) -> ((ValuePair) vp).startValue;
136157
case END:
137158
return (vp) -> ((ValuePair) vp).endValue;
138159
default:
139-
return (vp) -> null;
160+
return (vp) -> {
161+
throw new IllegalStateException("A value is being asked to be set where we never expected one");
162+
};
140163
}
141164
};
142165

166+
/**
167+
* Used to turn a method call into a direct field access
168+
*
169+
* @param s the name of the variable to see if it is in the bindingset
170+
* @return true if start or end is not null, if asked for a different field throw an illegalstate exception
171+
*/
143172
private static final Predicate<BindingSet> getHas(String s) {
144173
switch (s) {
145174
case START:
146175
return (vp) -> ((ValuePair) vp).startValue != null;
147176
case END:
148177
return (vp) -> ((ValuePair) vp).endValue != null;
149178
default:
150-
return (vp) -> false;
179+
return (vp) -> {
180+
throw new IllegalStateException("A value is being asked to be set where we never expected one");
181+
};
151182
}
152183
};
153184

@@ -397,6 +428,10 @@ protected boolean isUnbound(Var var, BindingSet bindings) {
397428
}
398429
}
399430

431+
/**
432+
* A specialized BingingSet that can only hold the start and end values of a Path. Minimizing unneeded memory use,
433+
* and allows specialization in the sets required to answer this part of a query.
434+
*/
400435
protected static class ValuePair implements MutableBindingSet {
401436
private static final long serialVersionUID = 1L;
402437

@@ -556,7 +591,7 @@ public void setBinding(Binding binding) {
556591
}
557592
}
558593

559-
class VarReplacer extends AbstractQueryModelVisitor<QueryEvaluationException> {
594+
private class VarReplacer extends AbstractQueryModelVisitor<QueryEvaluationException> {
560595

561596
private final Var toBeReplaced;
562597

0 commit comments

Comments
 (0)