Class GroupedPrefixGenerator<T>

java.lang.Object
io.bloviate.gen.AbstractDataGenerator<T>
io.bloviate.gen.GroupedPrefixGenerator<T>
Type Parameters:
T - the Java type produced by the wrapped generator
All Implemented Interfaces:
DataGenerator<T>, IndexedDataGenerator

public class GroupedPrefixGenerator<T> extends AbstractDataGenerator<T> implements IndexedDataGenerator
Populates a column only for the first prefixSize rows of each consecutive group of groupSize rows, emitting null for the remainder. For the n-th row (0-based) the position within its group is n % groupSize; positions below prefixSize delegate to a wrapped generator, the rest yield SQL NULL.

This is the streaming, O(1)-memory building block for a "sparse prefix column" — a value that exists only for a leading subset of each group. For example TPC-C's o_carrier_id, which is set for the delivered orders (the lower o_ids of each district) and NULL for the most recent, undelivered ones. It is schema-agnostic.

The wrapped generator is consulted only for prefix rows, so a stateless delegate is recommended. The values do not depend on the injected random source beyond whatever the delegate uses.

  • Method Details

    • generate

      public T generate()
      Description copied from interface: DataGenerator
      Generates a random value of type T.
      Specified by:
      generate in interface DataGenerator<T>
      Returns:
      a generated value, may be null if the generator supports nullable columns
    • seek

      public void seek(long rowIndex)
      Positions this generator so the next DataGenerator.generate() returns the value for the given absolute (0-based) row index.

      Setting the counter to rowIndex restores the null/non-null pattern exactly (it is a pure function of the absolute position). The wrapped delegate is consulted only on prefix rows, so it is advanced to the matching delegate-call index: a positional delegate is itself sought (byte-identical), while a plain random delegate is reseeded deterministically for the partition (its non-key values may differ from a sequential fill).

      Specified by:
      seek in interface IndexedDataGenerator
      Parameters:
      rowIndex - the absolute, 0-based row index to seek to; must be >= 0
    • set

      public void set(Connection connection, PreparedStatement statement, int parameterIndex, T value) throws SQLException
      Description copied from interface: DataGenerator
      Sets a specific value on a PreparedStatement parameter.
      Specified by:
      set in interface DataGenerator<T>
      Overrides:
      set in class AbstractDataGenerator<T>
      Parameters:
      connection - the database connection
      statement - the prepared statement to set the parameter on
      parameterIndex - the 1-based parameter index
      value - the value to set
      Throws:
      SQLException - if the database operation fails
    • get

      public T get(ResultSet resultSet, int columnIndex) throws SQLException
      Description copied from interface: DataGenerator
      Retrieves a value from a ResultSet column.
      Specified by:
      get in interface DataGenerator<T>
      Parameters:
      resultSet - the result set to read from
      columnIndex - the 1-based column index
      Returns:
      the value from the result set, properly cast to type T
      Throws:
      SQLException - if the database operation fails