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
1515import java .io .IOException ;
1616import java .lang .foreign .MemorySegment ;
5656import org .apache .datasketches .tuple .arrayofdoubles .ArrayOfDoublesUpdatableSketch ;
5757import org .eclipse .rdf4j .common .annotation .Experimental ;
5858import org .eclipse .rdf4j .common .iteration .CloseableIteration ;
59- import org .eclipse .rdf4j .common .transaction .IsolationLevels ;
6059import org .eclipse .rdf4j .model .IRI ;
6160import org .eclipse .rdf4j .model .Resource ;
6261import org .eclipse .rdf4j .model .Statement ;
9594import org .eclipse .rdf4j .query .algebra .evaluation .util .QueryEvaluationUtil ;
9695import org .eclipse .rdf4j .query .algebra .helpers .AbstractSimpleQueryModelVisitor ;
9796import org .eclipse .rdf4j .query .algebra .helpers .collectors .VarNameCollector ;
98- import org .eclipse .rdf4j .sail .SailException ;
9997import org .slf4j .Logger ;
10098import org .slf4j .LoggerFactory ;
10199
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>
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 /* ────────────────────────────────────────────────────────────── */
0 commit comments