Skip to content

Commit 4ad6a3f

Browse files
committed
working on new ID based join iterator
1 parent bf39508 commit 4ad6a3f

4 files changed

Lines changed: 57 additions & 9 deletions

File tree

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/IdBindingInfo.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.eclipse.rdf4j.query.algebra.evaluation.ArrayBindingSet;
2727
import org.eclipse.rdf4j.query.algebra.evaluation.impl.QueryEvaluationContext;
2828
import org.eclipse.rdf4j.sail.lmdb.join.LmdbIdJoinIterator;
29+
import org.eclipse.rdf4j.sail.lmdb.join.LmdbIdJoinSettings;
2930
import org.eclipse.rdf4j.sail.lmdb.model.LmdbValue;
3031

3132
/**
@@ -126,7 +127,7 @@ public boolean applyRecord(long[] record, MutableBindingSet target, ValueStore v
126127
// Fallback: resolve and compare
127128
Value candidate;
128129
try {
129-
candidate = valueStore.getLazyValue(id);
130+
candidate = LmdbIdJoinSettings.resolveValue(valueStore, id);
130131
} catch (IOException ex) {
131132
throw new QueryEvaluationException(ex);
132133
}
@@ -136,7 +137,7 @@ public boolean applyRecord(long[] record, MutableBindingSet target, ValueStore v
136137
} else {
137138
Value candidate;
138139
try {
139-
candidate = valueStore.getLazyValue(id);
140+
candidate = LmdbIdJoinSettings.resolveValue(valueStore, id);
140141
} catch (IOException ex) {
141142
throw new QueryEvaluationException(ex);
142143
}
@@ -174,7 +175,7 @@ public boolean applyRecord(long[] record, MutableBindingSet target, ValueStore v
174175
// Fallback: resolve candidate and compare
175176
Value candidate;
176177
try {
177-
candidate = valueStore.getLazyValue(id);
178+
candidate = LmdbIdJoinSettings.resolveValue(valueStore, id);
178179
} catch (IOException ex) {
179180
throw new QueryEvaluationException(ex);
180181
}
@@ -185,7 +186,7 @@ public boolean applyRecord(long[] record, MutableBindingSet target, ValueStore v
185186
// No existing value: resolve once and set via direct setter
186187
Value candidate;
187188
try {
188-
candidate = valueStore.getLazyValue(id);
189+
candidate = LmdbIdJoinSettings.resolveValue(valueStore, id);
189190
} catch (IOException ex) {
190191
throw new QueryEvaluationException(ex);
191192
}
@@ -221,7 +222,7 @@ public boolean applyRecord(long[] record, MutableBindingSet target, ValueStore v
221222
}
222223
Value candidate;
223224
try {
224-
candidate = valueStore.getLazyValue(id);
225+
candidate = LmdbIdJoinSettings.resolveValue(valueStore, id);
225226
} catch (IOException ex) {
226227
throw new QueryEvaluationException(ex);
227228
}

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/join/LmdbIdFinalBindingSetIteration.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.io.IOException;
1414
import java.util.ArrayList;
1515
import java.util.Collections;
16-
import java.util.HashMap;
1716
import java.util.List;
1817
import java.util.Map;
1918
import java.util.function.BiConsumer;
@@ -41,7 +40,6 @@ final class LmdbIdFinalBindingSetIteration extends LookAheadIteration<BindingSet
4140
private final ValueStore valueStore;
4241
private final Map<String, Long> constantBindings;
4342
private List<ConstEntry> constantEntries;
44-
private Map<String, BiConsumer<Value, MutableBindingSet>> constantSetters;
4543

4644
LmdbIdFinalBindingSetIteration(RecordIterator input, IdBindingInfo info, QueryEvaluationContext context,
4745
BindingSet initial, ValueStore valueStore, Map<String, Long> constantBindings) {
@@ -79,7 +77,7 @@ protected BindingSet getNextElement() throws QueryEvaluationException {
7977
}
8078
if (!ce.valueResolved) {
8179
try {
82-
ce.value = valueStore.getLazyValue(ce.id);
80+
ce.value = LmdbIdJoinSettings.resolveValue(valueStore, ce.id);
8381
} catch (IOException e) {
8482
throw new QueryEvaluationException(e);
8583
}

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/join/LmdbIdJoinIterator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private Value resolveValue(long id, int position, ValueStore valueStore) throws
211211
return null;
212212
}
213213
try {
214-
return valueStore.getLazyValue(id);
214+
return LmdbIdJoinSettings.resolveValue(valueStore, id);
215215
} catch (IOException e) {
216216
throw new QueryEvaluationException(e);
217217
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 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.sail.lmdb.join;
12+
13+
import java.io.IOException;
14+
15+
import org.eclipse.rdf4j.model.Value;
16+
import org.eclipse.rdf4j.sail.lmdb.ValueStore;
17+
import org.eclipse.rdf4j.sail.lmdb.model.LmdbValue;
18+
19+
/**
20+
* Centralizes runtime switches for LMDB ID-based joins.
21+
*/
22+
public final class LmdbIdJoinSettings {
23+
24+
private static final String LAZY_MATERIALIZATION_PROPERTY = "rdf4j.lmdb.idJoin.lazyMaterialization";
25+
26+
private LmdbIdJoinSettings() {
27+
// no instances
28+
}
29+
30+
public static boolean lazyMaterializationEnabled() {
31+
String value = System.getProperty(LAZY_MATERIALIZATION_PROPERTY);
32+
if (value == null) {
33+
return true;
34+
}
35+
return !("false".equalsIgnoreCase(value) || "0".equals(value) || "off".equalsIgnoreCase(value));
36+
}
37+
38+
public static LmdbValue resolveLmdbValue(ValueStore valueStore, long id) throws IOException {
39+
LmdbValue value = valueStore.getLazyValue(id);
40+
if (value != null && !lazyMaterializationEnabled()) {
41+
value.init();
42+
}
43+
return value;
44+
}
45+
46+
public static Value resolveValue(ValueStore valueStore, long id) throws IOException {
47+
return resolveLmdbValue(valueStore, id);
48+
}
49+
}

0 commit comments

Comments
 (0)