Skip to content

Commit 195796c

Browse files
committed
moved code around
1 parent 933f772 commit 195796c

47 files changed

Lines changed: 566 additions & 730 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/queryalgebra/evaluation/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
<name>RDF4J: Query algebra - evaluation</name>
1111
<description>Evaluation strategy API and implementations for the query algebra model.</description>
1212
<dependencies>
13+
<dependency>
14+
<groupId>org.apache.datasketches</groupId>
15+
<artifactId>datasketches-java</artifactId>
16+
<version>9.0.0</version>
17+
</dependency>
1318
<dependency>
1419
<groupId>${project.groupId}</groupId>
1520
<artifactId>rdf4j-queryalgebra-model</artifactId>

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/base/JoinCostVector.java renamed to core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/sketch/JoinCostVector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* SPDX-License-Identifier: BSD-3-Clause
1010
*******************************************************************************/
1111
// Some portions generated by Codex
12-
package org.eclipse.rdf4j.sail.base;
12+
package org.eclipse.rdf4j.query.algebra.evaluation.sketch;
1313

1414
import java.util.Objects;
1515

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/base/JoinPlanningState.java renamed to core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/sketch/JoinPlanningState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*******************************************************************************/
1111
// Some portions generated by Codex
1212

13-
package org.eclipse.rdf4j.sail.base;
13+
package org.eclipse.rdf4j.query.algebra.evaluation.sketch;
1414

1515
final class JoinPlanningState {
1616

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/base/ParetoFrontier.java renamed to core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/sketch/ParetoFrontier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* SPDX-License-Identifier: BSD-3-Clause
1010
*******************************************************************************/
1111
// Some portions generated by Codex
12-
package org.eclipse.rdf4j.sail.base;
12+
package org.eclipse.rdf4j.query.algebra.evaluation.sketch;
1313

1414
import java.util.ArrayList;
1515
import java.util.Comparator;

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/base/ParetoJoinMemoPlanner.java renamed to core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/sketch/ParetoJoinMemoPlanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*******************************************************************************/
1111
// Some portions generated by Codex
1212

13-
package org.eclipse.rdf4j.sail.base;
13+
package org.eclipse.rdf4j.query.algebra.evaluation.sketch;
1414

1515
import java.util.ArrayList;
1616
import java.util.Comparator;

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/base/SketchBasedJoinEstimator.java renamed to core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/sketch/SketchBasedJoinEstimator.java

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
******************************************************************************/
1111
// Some portions generated by Codex
1212

13-
package org.eclipse.rdf4j.sail.base;
13+
package org.eclipse.rdf4j.query.algebra.evaluation.sketch;
1414

1515
import java.io.IOException;
1616
import java.lang.foreign.MemorySegment;
@@ -56,7 +56,6 @@
5656
import org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketch;
5757
import org.eclipse.rdf4j.common.annotation.Experimental;
5858
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
59-
import org.eclipse.rdf4j.common.transaction.IsolationLevels;
6059
import org.eclipse.rdf4j.model.IRI;
6160
import org.eclipse.rdf4j.model.Resource;
6261
import org.eclipse.rdf4j.model.Statement;
@@ -95,7 +94,6 @@
9594
import org.eclipse.rdf4j.query.algebra.evaluation.util.QueryEvaluationUtil;
9695
import org.eclipse.rdf4j.query.algebra.helpers.AbstractSimpleQueryModelVisitor;
9796
import org.eclipse.rdf4j.query.algebra.helpers.collectors.VarNameCollector;
98-
import org.eclipse.rdf4j.sail.SailException;
9997
import org.slf4j.Logger;
10098
import org.slf4j.LoggerFactory;
10199

@@ -115,17 +113,18 @@
115113
* <h3>Configuration</h3>
116114
*
117115
* <p>
118-
* Applications should prefer {@link #SketchBasedJoinEstimator(SailStore, Config)} to set options programmatically. For
119-
* convenience, {@link #SketchBasedJoinEstimator(SailStore, int, long, long)} delegates to {@link Config#defaults()} and
120-
* will pick up system properties as well.
116+
* Applications should prefer {@link #SketchBasedJoinEstimator(SketchStatementSource, Config)} to set options
117+
* programmatically. For convenience, {@link #SketchBasedJoinEstimator(SketchStatementSource, int, long, long)}
118+
* delegates to {@link Config#defaults()} and will pick up system properties as well.
121119
* </p>
122120
*
123121
* <h4>System properties (overlay)</h4>
124122
* <p>
125123
* All options can be overridden at construction time by JVM system properties with prefix
126-
* {@code org.eclipse.rdf4j.sail.base.SketchBasedJoinEstimator.}. When present, the system property value takes
127-
* precedence over the corresponding value provided through {@link Config}. Supported keys (defaults shown in
128-
* {@link Config}):
124+
* {@code org.eclipse.rdf4j.query.algebra.evaluation.sketch.SketchBasedJoinEstimator.}. When present, the system
125+
* property value takes precedence over the corresponding value provided through {@link Config}. The legacy
126+
* {@code org.eclipse.rdf4j.sail.base.SketchBasedJoinEstimator.} prefix is also accepted as a fallback. Supported keys
127+
* (defaults shown in {@link Config}):
129128
* </p>
130129
* <ul>
131130
* <li>{@code nominalEntries} (int ≥ 4)</li>
@@ -159,9 +158,11 @@
159158
*
160159
* <pre>
161160
* {@code
162-
* System.setProperty("org.eclipse.rdf4j.sail.base.SketchBasedJoinEstimator.defaultContextString", "urn:ctx");
163-
* System.setProperty("org.eclipse.rdf4j.sail.base.SketchBasedJoinEstimator.refreshSleepMillis", "500");
164-
* var est = new SketchBasedJoinEstimator(store, Config.defaults().withNominalEntries(128));
161+
* System.setProperty(
162+
* "org.eclipse.rdf4j.query.algebra.evaluation.sketch.SketchBasedJoinEstimator.defaultContextString", "urn:ctx");
163+
* System.setProperty(
164+
* "org.eclipse.rdf4j.query.algebra.evaluation.sketch.SketchBasedJoinEstimator.refreshSleepMillis", "500");
165+
* var est = new SketchBasedJoinEstimator(source, Config.defaults().withNominalEntries(128));
165166
* }
166167
* </pre>
167168
*/
@@ -377,7 +378,7 @@ enum SketchPlannerPath {
377378
/* Configuration & high‑level state */
378379
/* ────────────────────────────────────────────────────────────── */
379380

380-
private final SailStore sailStore;
381+
private final SketchStatementSource statementSource;
381382
private final int nominalEntries; // ← bucket count for array indices
382383
private final int subjectBucketCount;
383384
private final int predicateBucketCount;
@@ -1326,8 +1327,9 @@ private boolean isEmpty() {
13261327
* Convenience constructor that uses {@link Config#defaults()} with the given basics. All options can still be
13271328
* overridden via system properties (see class‑level Javadoc).
13281329
*/
1329-
public SketchBasedJoinEstimator(SailStore sailStore, int nominalEntries, long throttleEveryN, long throttleMillis) {
1330-
this(sailStore, Config.defaults()
1330+
public SketchBasedJoinEstimator(SketchStatementSource statementSource, int nominalEntries, long throttleEveryN,
1331+
long throttleMillis) {
1332+
this(statementSource, Config.defaults()
13311333
.withNominalEntries(nominalEntries)
13321334
.withThrottleEveryN(throttleEveryN)
13331335
.withThrottleMillis(throttleMillis));
@@ -1338,11 +1340,11 @@ public SketchBasedJoinEstimator(SailStore sailStore, int nominalEntries, long th
13381340
*
13391341
* <p>
13401342
* Values from {@code cfg} are overlaid by system properties with prefix
1341-
* {@code org.eclipse.rdf4j.sail.base.SketchBasedJoinEstimator.}. If a property is set, it takes precedence. See
1342-
* class‑level Javadoc for the list of keys.
1343+
* {@code org.eclipse.rdf4j.query.algebra.evaluation.sketch.SketchBasedJoinEstimator.}. If a property is set, it
1344+
* takes precedence. See class‑level Javadoc for the list of keys.
13431345
* </p>
13441346
*/
1345-
public SketchBasedJoinEstimator(SailStore sailStore, Config cfg) {
1347+
public SketchBasedJoinEstimator(SketchStatementSource statementSource, Config cfg) {
13461348
Objects.requireNonNull(cfg, "cfg");
13471349

13481350
// Base from provided config
@@ -1456,7 +1458,7 @@ && propPresent("incrementalQueueEstimatedStatementBytes")) {
14561458
memoryMonitorCheckInterval = Math.max(1, memoryMonitorCheckInterval);
14571459
memoryMonitorEstimatedOperationBytes = Math.max(1L, memoryMonitorEstimatedOperationBytes);
14581460

1459-
this.sailStore = sailStore;
1461+
this.statementSource = Objects.requireNonNull(statementSource, "statementSource");
14601462
this.nominalEntries = maxBucketCount(sBuckets, pBuckets, oBuckets, cBuckets);
14611463
this.subjectBucketCount = sBuckets;
14621464
this.predicateBucketCount = pBuckets;
@@ -2082,9 +2084,7 @@ public synchronized long rebuild() {
20822084
"RdfJoinEstimator: Rebuilding sketches started: targetBuffer={}, targetSlot={}, previousCurrentSlot={}, rebuildRequestVersion={}",
20832085
targetBuffer, targetSlot, previousCurrentSlot, requestVersion);
20842086
try {
2085-
try (
2086-
SailDataset ds = sailStore.getExplicitSailSource().dataset(IsolationLevels.READ_COMMITTED);
2087-
CloseableIteration<? extends Statement> it = ds.getStatements(null, null, null)) {
2087+
try (CloseableIteration<? extends Statement> it = statementSource.getStatements(null, null, null)) {
20882088
IngestEvent[] rebuildBatch = new IngestEvent[Math.min(REBUILD_BATCH_SIZE, memoryMonitorCheckInterval)];
20892089
int rebuildBatchSize = 0;
20902090
int rebuildMemoryCheckCountdown = memoryMonitorCheckInterval;
@@ -2216,7 +2216,7 @@ public void addStatements(List<? extends Statement> statements) {
22162216
}
22172217

22182218
public void addStatement(Resource s, IRI p, Value o, Resource c) {
2219-
addStatement(sailStore.getValueFactory().createStatement(s, p, o, c));
2219+
addStatement(statementSource.getValueFactory().createStatement(s, p, o, c));
22202220
}
22212221

22222222
public void addStatement(Resource s, IRI p, Value o) {
@@ -6338,9 +6338,8 @@ private TuplePlanEstimate exactBoundStatementPatternPlan(StatementPattern patter
63386338

63396339
double rows = 0.0d;
63406340
Map<String, Set<Value>> distinctValues = new HashMap<>();
6341-
try (SailDataset dataset = sailStore.getExplicitSailSource().dataset(IsolationLevels.READ_COMMITTED);
6342-
CloseableIteration<? extends Statement> statements = dataset.getStatements(subject, predicate, object,
6343-
contexts)) {
6341+
try (CloseableIteration<? extends Statement> statements = statementSource.getStatements(subject, predicate,
6342+
object, contexts)) {
63446343
while (statements.hasNext()) {
63456344
Statement statement = statements.next();
63466345
if (!statementMatchesPatternVariableEqualities(pattern, statement)) {
@@ -6352,7 +6351,7 @@ private TuplePlanEstimate exactBoundStatementPatternPlan(StatementPattern patter
63526351
}
63536352
collectExactPatternVarValues(pattern, statement, distinctValues);
63546353
}
6355-
} catch (SailException e) {
6354+
} catch (SketchStatementSourceException e) {
63566355
logger.debug("Falling back from exact bound pattern lookup for {}", pattern, e);
63576356
return null;
63586357
}
@@ -6484,9 +6483,8 @@ private SharedVarScan scanSharedVarRows(StatementPattern pattern, Component shar
64846483
^ Double.doubleToLongBits(Math.max(1.0d, zeroIntersectionSkewRatio))
64856484
^ zeroIntersectionRowBudget));
64866485
long scannedRows = 0L;
6487-
try (SailDataset dataset = sailStore.getExplicitSailSource().dataset(IsolationLevels.READ_COMMITTED);
6488-
CloseableIteration<? extends Statement> statements = dataset.getStatements(subject, predicate, object,
6489-
contexts)) {
6486+
try (CloseableIteration<? extends Statement> statements = statementSource.getStatements(subject, predicate,
6487+
object, contexts)) {
64906488
while (statements.hasNext()) {
64916489
Statement statement = statements.next();
64926490
if (!statementMatchesPatternVariableEqualities(pattern, statement)) {
@@ -6516,7 +6514,7 @@ private SharedVarScan scanSharedVarRows(StatementPattern pattern, Component shar
65166514
}
65176515
}
65186516
}
6519-
} catch (SailException e) {
6517+
} catch (SketchStatementSourceException e) {
65206518
logger.debug("Falling back from exact shared-var scan for {}", pattern, e);
65216519
return null;
65226520
}
@@ -6540,16 +6538,15 @@ private Long exactBoundPatternRows(StatementPattern pattern, String sharedVarNam
65406538
}
65416539

65426540
long rows = 0L;
6543-
try (SailDataset dataset = sailStore.getExplicitSailSource().dataset(IsolationLevels.READ_COMMITTED);
6544-
CloseableIteration<? extends Statement> statements = dataset.getStatements(subject, predicate, object,
6545-
contexts)) {
6541+
try (CloseableIteration<? extends Statement> statements = statementSource.getStatements(subject, predicate,
6542+
object, contexts)) {
65466543
while (statements.hasNext()) {
65476544
Statement statement = statements.next();
65486545
if (statementMatchesPatternVariableEqualities(boundPattern, statement)) {
65496546
rows++;
65506547
}
65516548
}
6552-
} catch (SailException e) {
6549+
} catch (SketchStatementSourceException e) {
65536550
logger.debug("Falling back from exact bound probe for {} with {}={}", pattern, sharedVarName, sharedValue,
65546551
e);
65556552
return null;
@@ -9335,19 +9332,20 @@ private static void clearArray(AtomicReferenceArray<?> arr) {
93359332
/* System property helpers */
93369333
/* ────────────────────────────────────────────────────────────── */
93379334

9338-
private static final String PROP_PREFIX = "org.eclipse.rdf4j.sail.base.SketchBasedJoinEstimator.";
9335+
private static final String PROP_PREFIX = SketchBasedJoinEstimator.class.getName() + ".";
9336+
private static final String LEGACY_PROP_PREFIX = "org.eclipse.rdf4j.sail.base.SketchBasedJoinEstimator.";
93399337

93409338
private static String propString(String name, String def) {
9341-
String v = System.getProperty(PROP_PREFIX + name);
9339+
String v = propValue(name);
93429340
return v != null ? v : def;
93439341
}
93449342

93459343
private static boolean propPresent(String name) {
9346-
return System.getProperty(PROP_PREFIX + name) != null;
9344+
return propValue(name) != null;
93479345
}
93489346

93499347
private static int propInt(String name, int def) {
9350-
String v = System.getProperty(PROP_PREFIX + name);
9348+
String v = propValue(name);
93519349
if (v == null) {
93529350
return def;
93539351
}
@@ -9359,7 +9357,7 @@ private static int propInt(String name, int def) {
93599357
}
93609358

93619359
private static int propIntOrNegOne(String name, int def) {
9362-
String v = System.getProperty(PROP_PREFIX + name);
9360+
String v = propValue(name);
93639361
if (v == null) {
93649362
return def;
93659363
}
@@ -9371,7 +9369,7 @@ private static int propIntOrNegOne(String name, int def) {
93719369
}
93729370

93739371
private static long propLong(String name, long def) {
9374-
String v = System.getProperty(PROP_PREFIX + name);
9372+
String v = propValue(name);
93759373
if (v == null) {
93769374
return def;
93779375
}
@@ -9383,7 +9381,7 @@ private static long propLong(String name, long def) {
93839381
}
93849382

93859383
private static double propDouble(String name, double def) {
9386-
String v = System.getProperty(PROP_PREFIX + name);
9384+
String v = propValue(name);
93879385
if (v == null) {
93889386
return def;
93899387
}
@@ -9395,13 +9393,21 @@ private static double propDouble(String name, double def) {
93959393
}
93969394

93979395
private static boolean propBool(String name, boolean def) {
9398-
String v = System.getProperty(PROP_PREFIX + name);
9396+
String v = propValue(name);
93999397
if (v == null) {
94009398
return def;
94019399
}
94029400
return Boolean.parseBoolean(v.trim());
94039401
}
94049402

9403+
private static String propValue(String name) {
9404+
String value = System.getProperty(PROP_PREFIX + name);
9405+
if (value != null) {
9406+
return value;
9407+
}
9408+
return System.getProperty(LEGACY_PROP_PREFIX + name);
9409+
}
9410+
94059411
/* ────────────────────────────────────────────────────────────── */
94069412
/* Configuration (public) */
94079413
/* ────────────────────────────────────────────────────────────── */

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/base/SketchEstimatorMetadata.java renamed to core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/sketch/SketchEstimatorMetadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*******************************************************************************/
1111
// Some portions generated by Codex
1212

13-
package org.eclipse.rdf4j.sail.base;
13+
package org.eclipse.rdf4j.query.algebra.evaluation.sketch;
1414

1515
import java.io.DataInput;
1616
import java.io.DataOutput;

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/base/SketchEstimatorPersistenceStore.java renamed to core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/sketch/SketchEstimatorPersistenceStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*******************************************************************************/
1111
// Some portions generated by Codex
1212

13-
package org.eclipse.rdf4j.sail.base;
13+
package org.eclipse.rdf4j.query.algebra.evaluation.sketch;
1414

1515
import java.io.ByteArrayInputStream;
1616
import java.io.ByteArrayOutputStream;

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/base/SketchJoinOrderPlanner.java renamed to core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/sketch/SketchJoinOrderPlanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*******************************************************************************/
1111
// Some portions generated by Codex
1212

13-
package org.eclipse.rdf4j.sail.base;
13+
package org.eclipse.rdf4j.query.algebra.evaluation.sketch;
1414

1515
import java.util.AbstractSet;
1616
import java.util.ArrayDeque;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
13+
package org.eclipse.rdf4j.query.algebra.evaluation.sketch;
14+
15+
import org.eclipse.rdf4j.common.annotation.Experimental;
16+
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
17+
import org.eclipse.rdf4j.model.IRI;
18+
import org.eclipse.rdf4j.model.Resource;
19+
import org.eclipse.rdf4j.model.Statement;
20+
import org.eclipse.rdf4j.model.Value;
21+
import org.eclipse.rdf4j.model.ValueFactory;
22+
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
23+
24+
/**
25+
* Minimal statement access needed by {@link SketchBasedJoinEstimator}.
26+
*/
27+
@Experimental
28+
public interface SketchStatementSource {
29+
30+
CloseableIteration<? extends Statement> getStatements(Resource subject, IRI predicate, Value object,
31+
Resource... contexts);
32+
33+
default ValueFactory getValueFactory() {
34+
return SimpleValueFactory.getInstance();
35+
}
36+
}

0 commit comments

Comments
 (0)