- Record Components:
seed- the optional RNG seed for a reproducible sequence of draws; empty = non-deterministicweight- the optional per-face weight expression; empty = uniform drawsinput- the finite relation of faces to draw from; must not be nulllocation- the source location of this node; never null
- All Implemented Interfaces:
RelNode
input), ROLL emits an unbounded relation
with the same heading, where each output row is an independent uniform draw from
the faces. A six-row input is a six-sided die; each pull rolls it again.
It is the random-source sibling of the generator relations
(Naturals, Primes, Range) and the with-replacement
counterpart of the without-replacement random operators — SAMPLE n ROWS
(a subset) and ShuffleNode (a permutation). Compose λ (LIMIT) to
take a finite number of rolls: λ 3 (ROLL SEED 7 (Faces)).
Boundedness — the inversion of a blocking operator. ROLL's output is
totally unbounded regardless of input size, so it is the first non-leaf operator
that produces unboundedness; a blocking operator above it (τ, γ, SHUFFLE, …) is rejected the
same way it is over any endless generator. Its input, by contrast, must be
materialisable — the face set is buffered to be indexed — so an unbounded input
is itself a plan-time error.
Reproducibility: when seed is present the sequence of draws is
deterministic — the k-th emitted row is a function of the seed and k. Without a
seed, ThreadLocalRandom supplies fresh randomness each run, exactly as
unseeded SAMPLE and SHUFFLE do.
Weighted draws (a loaded die). When weight is present, each face
is drawn with probability proportional to that non-negative NUMBER
expression evaluated over the face's columns — ROLL BY w (Faces). A
zero-weight face is never drawn, a negative weight is an error, and an all-zero (or
empty) face set yields no rows, exactly as an empty ROLL does. Without it,
every face is equally likely.
Examples:
LIMIT 1 (ROLL (Die))— one random face (non-deterministic)LIMIT 3 (ROLL SEED 7 (Die))— three reproducible rollsLIMIT 3 (ROLL BY weight SEED 7 (Loot))— three weighted draws
-
Constructor Summary
ConstructorsConstructorDescriptionConvenience constructor for tests; usesSourceLocation.UNKNOWNand no seed or weight.RollNode(Optional<Long> seed, RelNode input, SourceLocation location) Convenience constructor for an unweighted roll — the pre-weighting shape.Creates an instance of aRollNoderecord class. -
Method Summary
Modifier and TypeMethodDescription<R> Raccept(RelNodeVisitor<R> visitor) 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.weight()Returns the value of theweightrecord component.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
-
RollNode
public RollNode(Optional<Long> seed, Optional<Operand> weight, RelNode input, SourceLocation location) Creates an instance of aRollNoderecord class. -
RollNode
Convenience constructor for tests; usesSourceLocation.UNKNOWNand no seed or weight. -
RollNode
Convenience constructor for an unweighted roll — the pre-weighting shape.
-
-
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. All components in this record class are compared withObjects::equals(Object,Object). -
seed
Returns the value of theseedrecord component.- Returns:
- the value of the
seedrecord component
-
weight
Returns the value of theweightrecord component.- Returns:
- the value of the
weightrecord component
-
input
Returns the value of theinputrecord component.- Returns:
- the value of the
inputrecord component
-
location
Returns the value of thelocationrecord component.
-