Class ZipfianIntegerGenerator

java.lang.Object
io.bloviate.gen.AbstractDataGenerator<Integer>
io.bloviate.gen.ZipfianIntegerGenerator
All Implemented Interfaces:
DataGenerator<Integer>

public class ZipfianIntegerGenerator extends AbstractDataGenerator<Integer>
Generates integers from a Zipfian (power-law) distribution over size consecutive values starting at start: rank k (1-based) has probability proportional to 1 / k^exponent, so the lowest values are by far the most frequent and the tail is long and thin. This is the shape of "popularity" columns — a few hot keys, many rare ones (referenced products, authors, tags) — that uniform random generation never reproduces.

A cumulative table of size doubles is precomputed once, so keep size modest (thousands to low millions). exponent defaults to 1.0 (classic Zipf); higher values concentrate mass even harder on the head.

Since:
2.11.0
  • Method Details

    • generate

      public Integer generate()
      Description copied from interface: DataGenerator
      Generates a random value of type T.
      Returns:
      a generated value, may be null if the generator supports nullable columns
    • set

      public void set(Connection connection, PreparedStatement statement, int parameterIndex, Integer value) throws SQLException
      Description copied from interface: DataGenerator
      Sets a specific value on a PreparedStatement parameter.
      Specified by:
      set in interface DataGenerator<Integer>
      Overrides:
      set in class AbstractDataGenerator<Integer>
      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 Integer get(ResultSet resultSet, int columnIndex) throws SQLException
      Description copied from interface: DataGenerator
      Retrieves a value from a ResultSet column.
      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