Module com.darkcollective.relix.ast
Package com.darkcollective.relix.ast
Record Class ReservoirSampleNode
java.lang.Object
java.lang.Record
com.darkcollective.relix.ast.ReservoirSampleNode
- Record Components:
count- the exact number of rows to keep; non-negativeseed- the optional RNG seed for reproducible sampling; empty = non-deterministicinput- the relation to sample; must not be nulllocation- the source location of this node; never null
- All Implemented Interfaces:
RelNode
public record ReservoirSampleNode(long count, Optional<Long> seed, RelNode input, SourceLocation location)
extends Record
implements RelNode
Reservoir (fixed-count) sampling (SAMPLE … ROWS) — keeps exactly
count
rows of input, chosen uniformly at random without replacement.
Where SampleNode (SAMPLE 0.1) is a per-row coin flip whose
result size only averages p × |input|, this is the
count-based form: SAMPLE 100 ROWS (R) returns exactly 100 rows
(or all of them when the input has fewer than count). It is the
composable, algebraic form of the ORDER BY RANDOM() LIMIT n idiom — but
without the full sort.
Reproducibility: when seed is present the sampling is
deterministic — identical runs produce identical row selections via Vitter's
Algorithm R seeded with the given value. Without a seed, fresh randomness is
drawn each run.
Examples:
SAMPLE 100 ROWS (Events)— keeps a uniform 100-row sample (non-deterministic)SAMPLE 500 ROWS SEED 2026 (Events)— reproducible fixed-count sample
-
Constructor Summary
ConstructorsConstructorDescriptionReservoirSampleNode(long count, RelNode input) Convenience constructor for tests; usesSourceLocation.UNKNOWNand no seed.ReservoirSampleNode(long count, RelNode input, SourceLocation location) Convenience constructor without seed (non-deterministic); uses provided location.ReservoirSampleNode(long count, Optional<Long> seed, RelNode input, SourceLocation location) Creates an instance of aReservoirSampleNoderecord class. -
Method Summary
Modifier and TypeMethodDescription<R> Raccept(RelNodeVisitor<R> visitor) longcount()Returns the value of thecountrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.input()Returns the value of theinputrecord component.location()Returns the value of thelocationrecord component.seed()Returns the value of theseedrecord component.final StringtoString()Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.darkcollective.relix.ast.RelNode
children, mapChildren, materializationMode, prettyPrint
-
Constructor Details
-
ReservoirSampleNode
Creates an instance of aReservoirSampleNoderecord class. -
ReservoirSampleNode
Convenience constructor without seed (non-deterministic); uses provided location. -
ReservoirSampleNode
Convenience constructor for tests; usesSourceLocation.UNKNOWNand no seed.
-
-
Method Details
-
accept
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
count
public long count()Returns the value of thecountrecord component.- Returns:
- the value of the
countrecord component
-
seed
Returns the value of theseedrecord component.- Returns:
- the value of the
seedrecord component
-
input
Returns the value of theinputrecord component.- Returns:
- the value of the
inputrecord component
-
location
Returns the value of thelocationrecord component.
-