Record Class RollNode

java.lang.Object
java.lang.Record
com.darkcollective.relix.ast.RollNode
Record Components:
seed - the optional RNG seed for a reproducible sequence of draws; empty = non-deterministic
weight - the optional per-face weight expression; empty = uniform draws
input - the finite relation of faces to draw from; must not be null
location - the source location of this node; never null
All Implemented Interfaces:
RelNode

public record RollNode(Optional<Long> seed, Optional<Operand> weight, RelNode input, SourceLocation location) extends Record implements RelNode
Endless uniform draw with replacement (ROLL) — a die roll. Given a finite relation of "faces" (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 rolls
  • LIMIT 3 (ROLL BY weight SEED 7 (Loot)) — three weighted draws
  • Constructor Details

    • RollNode

      public RollNode(Optional<Long> seed, Optional<Operand> weight, RelNode input, SourceLocation location)
      Creates an instance of a RollNode record class.
      Parameters:
      seed - the value for the seed record component
      weight - the value for the weight record component
      input - the value for the input record component
      location - the value for the location record component
    • RollNode

      public RollNode(RelNode input)
      Convenience constructor for tests; uses SourceLocation.UNKNOWN and no seed or weight.
    • RollNode

      public RollNode(Optional<Long> seed, RelNode input, SourceLocation location)
      Convenience constructor for an unweighted roll — the pre-weighting shape.
  • Method Details

    • accept

      public <R> R accept(RelNodeVisitor<R> visitor)
      Specified by:
      accept in interface RelNode
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • seed

      public Optional<Long> seed()
      Returns the value of the seed record component.
      Returns:
      the value of the seed record component
    • weight

      public Optional<Operand> weight()
      Returns the value of the weight record component.
      Returns:
      the value of the weight record component
    • input

      public RelNode input()
      Returns the value of the input record component.
      Returns:
      the value of the input record component
    • location

      public SourceLocation location()
      Returns the value of the location record component.
      Specified by:
      location in interface RelNode
      Returns:
      the value of the location record component