Skip to content

Commit 08892f5

Browse files
committed
new best
1 parent 71ab6b7 commit 08892f5

24 files changed

Lines changed: 1326 additions & 103 deletions

core/sail/lmdb/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@
151151
<groupId>com.google.guava</groupId>
152152
<artifactId>guava</artifactId>
153153
</dependency>
154+
<dependency>
155+
<groupId>org.codehaus.janino</groupId>
156+
<artifactId>janino</artifactId>
157+
<version>3.1.12</version>
158+
</dependency>
154159
<dependency>
155160
<groupId>${project.groupId}</groupId>
156161
<artifactId>rdf4j-sail-testsuite</artifactId>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 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+
// Some portions generated by Codex
12+
package org.eclipse.rdf4j.sail.lmdb;
13+
14+
import org.eclipse.rdf4j.common.iteration.LookAheadIteration;
15+
import org.eclipse.rdf4j.query.BindingSet;
16+
import org.eclipse.rdf4j.query.QueryEvaluationException;
17+
import org.eclipse.rdf4j.query.algebra.evaluation.impl.QueryEvaluationContext;
18+
19+
public abstract class AbstractLmdbCompiledLftjIteration extends LookAheadIteration<BindingSet> {
20+
21+
private final LmdbLftjPlan plan;
22+
private final LmdbLftjExecutionShape shape;
23+
private final LmdbLftjBindingState state;
24+
private final QueryEvaluationContext context;
25+
private final LmdbLftjMetrics metrics;
26+
private final LmdbPrefixFrontierProvider frontierProvider;
27+
28+
private BindingSet repeatedBinding;
29+
private long repeatedCount;
30+
31+
protected AbstractLmdbCompiledLftjIteration(LmdbLftjPlan plan, LmdbLftjExecutionShape shape,
32+
LmdbLftjBindingState state,
33+
QueryEvaluationContext context, LmdbQueryAccess queryAccess, LmdbLftjMetrics metrics) {
34+
this.plan = plan;
35+
this.shape = shape;
36+
this.state = state;
37+
this.context = context;
38+
this.metrics = metrics;
39+
this.frontierProvider = new LmdbPrefixFrontierProvider(queryAccess, state, metrics);
40+
}
41+
42+
@Override
43+
protected final BindingSet getNextElement() {
44+
if (repeatedCount > 0) {
45+
repeatedCount--;
46+
metrics.recordEmitted(1);
47+
return repeatedBinding;
48+
}
49+
50+
try {
51+
return computeNextElement();
52+
} catch (RuntimeException e) {
53+
throw new QueryEvaluationException("LMDB LFTJ compiled iteration failed", e);
54+
}
55+
}
56+
57+
@Override
58+
protected final void handleClose() {
59+
closeCursors();
60+
state.close();
61+
}
62+
63+
protected abstract BindingSet computeNextElement();
64+
65+
protected abstract void closeCursors();
66+
67+
protected final LmdbLftjBindingState state() {
68+
return state;
69+
}
70+
71+
protected final LmdbLftjMetrics metrics() {
72+
return metrics;
73+
}
74+
75+
protected final void recordCandidateScan() {
76+
metrics.recordCandidateScan();
77+
}
78+
79+
protected final boolean isFixed(int slot) {
80+
return state.isFixed(slot);
81+
}
82+
83+
protected final LmdbLftjCursor createCursor(int patternOrdinal) {
84+
return new LmdbCachedTrieCursor(plan.patternPlans().get(patternOrdinal), frontierProvider);
85+
}
86+
87+
protected final long countMatches(int patternOrdinal) {
88+
metrics.recordWitnessScan();
89+
return frontierProvider.countMatches(plan.patternPlans().get(patternOrdinal));
90+
}
91+
92+
protected final BindingSet emitCurrent(long multiplicity) {
93+
BindingSet result = state.materialize(context);
94+
repeatedBinding = result;
95+
repeatedCount = multiplicity - 1;
96+
metrics.recordEmitted(1);
97+
return result;
98+
}
99+
100+
protected final LmdbLftjExecutionShape shape() {
101+
return shape;
102+
}
103+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 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+
// Some portions generated by Codex
12+
package org.eclipse.rdf4j.sail.lmdb;
13+
14+
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
15+
import org.eclipse.rdf4j.query.BindingSet;
16+
import org.eclipse.rdf4j.query.algebra.evaluation.impl.QueryEvaluationContext;
17+
18+
public interface LmdbCompiledLftjFactory {
19+
20+
CloseableIteration<BindingSet> create(LmdbLftjPlan plan, LmdbLftjExecutionShape shape,
21+
LmdbLftjBindingState state, QueryEvaluationContext context, LmdbQueryAccess queryAccess,
22+
LmdbLftjMetrics metrics);
23+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ static final class RelationKey {
131131
this.predicateId = predicateId;
132132
}
133133

134+
String indexName() {
135+
return indexName;
136+
}
137+
138+
boolean includeInferred() {
139+
return includeInferred;
140+
}
141+
142+
long predicateId() {
143+
return predicateId;
144+
}
145+
134146
@Override
135147
public boolean equals(Object other) {
136148
if (!(other instanceof RelationKey)) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.eclipse.rdf4j.query.algebra.evaluation.impl.QueryEvaluationContext;
2121
import org.eclipse.rdf4j.sail.lmdb.model.LmdbValue;
2222

23-
final class LmdbLftjBindingState {
23+
public final class LmdbLftjBindingState {
2424

2525
private final LmdbLftjPlan plan;
2626
private final BindingSet inputBindings;
@@ -95,6 +95,10 @@ boolean isBound(int slot) {
9595
return assignedPresent[slot] || fixedPresent[slot];
9696
}
9797

98+
boolean isFixed(int slot) {
99+
return fixedPresent[slot];
100+
}
101+
98102
long value(String variableName) {
99103
return value(slot(variableName));
100104
}
@@ -110,7 +114,7 @@ void assign(String variableName, long value) {
110114
assign(slot(variableName), value);
111115
}
112116

113-
void assign(int slot, long value) {
117+
public void assign(int slot, long value) {
114118
assignedValues[slot] = value;
115119
assignedPresent[slot] = true;
116120
}
@@ -119,7 +123,7 @@ void clear(String variableName) {
119123
clear(slot(variableName));
120124
}
121125

122-
void clear(int slot) {
126+
public void clear(int slot) {
123127
assignedPresent[slot] = false;
124128
}
125129

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 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+
// Some portions generated by Codex
12+
package org.eclipse.rdf4j.sail.lmdb;
13+
14+
import java.util.LinkedHashMap;
15+
import java.util.Map;
16+
17+
final class LmdbLftjCodegenCache {
18+
19+
private static final int MAX_ENTRIES = 256;
20+
21+
private final Map<String, CacheEntry> entries = new LinkedHashMap<>(32, 0.75f, true) {
22+
@Override
23+
protected boolean removeEldestEntry(Map.Entry<String, CacheEntry> eldest) {
24+
return size() > MAX_ENTRIES;
25+
}
26+
};
27+
28+
synchronized CacheEntry get(String executionKey) {
29+
return entries.get(executionKey);
30+
}
31+
32+
synchronized void putSuccess(String executionKey, LmdbCompiledLftjFactory factory) {
33+
entries.put(executionKey, CacheEntry.success(factory));
34+
}
35+
36+
synchronized void putFailure(String executionKey, String message) {
37+
entries.put(executionKey, CacheEntry.failure(message));
38+
}
39+
40+
synchronized void clear() {
41+
entries.clear();
42+
}
43+
44+
static final class CacheEntry {
45+
private final LmdbCompiledLftjFactory factory;
46+
private final String failureMessage;
47+
48+
private CacheEntry(LmdbCompiledLftjFactory factory, String failureMessage) {
49+
this.factory = factory;
50+
this.failureMessage = failureMessage;
51+
}
52+
53+
static CacheEntry success(LmdbCompiledLftjFactory factory) {
54+
return new CacheEntry(factory, null);
55+
}
56+
57+
static CacheEntry failure(String failureMessage) {
58+
return new CacheEntry(null, failureMessage);
59+
}
60+
61+
boolean compiled() {
62+
return factory != null;
63+
}
64+
65+
LmdbCompiledLftjFactory factory() {
66+
return factory;
67+
}
68+
69+
String failureMessage() {
70+
return failureMessage;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)