DataGen SQL Connector

Scan Source: Bounded Scan Source: UnBounded

The DataGen connector allows for creating tables based on in-memory data generation. This is useful when developing queries locally without access to external systems such as Kafka. Tables can include Computed Column syntax which allows for flexible record generation.

The DataGen connector is built-in, no additional dependencies are required.

Usage

By default, a DataGen table will create an unbounded number of rows with a random value for each column. Additionally, a total number of rows can be specified, resulting in a bounded table.

The DataGen connector can generate data that conforms to its defined schema, It should be noted that it handles length-constrained fields as follows:

  • For fixed-length data types (char/binary), the field length can only be defined by the schema, and does not support customization.
  • For variable-length data types (varchar/varbinary), the field length is initially defined by the schema, and the customized length cannot be greater than the schema definition.
  • For super-long fields (string/bytes), the default length is 100, but can be set to a length less than 2^31.

There also exists a sequence generator, where users specify a sequence of start and end values. If any column in a table is a sequence type, the table will be bounded and end with the first sequence completes.

Time types are always the local machines current system time.

  1. CREATE TABLE Orders (
  2. order_number BIGINT,
  3. price DECIMAL(32,2),
  4. buyer ROW<first_name STRING, last_name STRING>,
  5. order_time TIMESTAMP(3)
  6. ) WITH (
  7. 'connector' = 'datagen'
  8. )

Often, the data generator connector is used in conjunction with the LIKE clause to mock out physical tables.

  1. CREATE TABLE Orders (
  2. order_number BIGINT,
  3. price DECIMAL(32,2),
  4. buyer ROW<first_name STRING, last_name STRING>,
  5. order_time TIMESTAMP(3)
  6. ) WITH (...)
  7. -- create a bounded mock table
  8. CREATE TEMPORARY TABLE GenOrders
  9. WITH (
  10. 'connector' = 'datagen',
  11. 'number-of-rows' = '10'
  12. )
  13. LIKE Orders (EXCLUDING ALL)

Furthermore, for variable sized types, varchar/string/varbinary/bytes, you can specify whether to enable variable-length data generation.

  1. CREATE TABLE Orders (
  2. order_number BIGINT,
  3. price DECIMAL(32,2),
  4. buyer ROW<first_name STRING, last_name STRING>,
  5. order_time TIMESTAMP(3),
  6. seller VARCHAR(150)
  7. ) WITH (
  8. 'connector' = 'datagen',
  9. 'fields.seller.var-len' = 'true'
  10. )

Types

TypeSupported GeneratorsNotes
BOOLEANrandom
CHARrandom / sequence
VARCHARrandom / sequence
BINARYrandom / sequence
VARBINARYrandom / sequence
STRINGrandom / sequence
DECIMALrandom / sequence
TINYINTrandom / sequence
SMALLINTrandom / sequence
INTrandom / sequence
BIGINTrandom / sequence
FLOATrandom / sequence
DOUBLErandom / sequence
DATErandomAlways resolves to the current date of the local machine.
TIMErandomAlways resolves to the current time of the local machine.
TIMESTAMPrandomResolves a past timestamp relative to the current timestamp of the local machine. The max past can be specified by the ‘max-past’ option.
TIMESTAMP_LTZrandomResolves a past timestamp relative to the current timestamp of the local machine. The max past can be specified by the ‘max-past’ option.
INTERVAL YEAR TO MONTHrandom
INTERVAL DAY TO MONTHrandom
ROWrandomGenerates a row with random subfields.
ARRAYrandomGenerates an array with random entries.
MAPrandomGenerates a map with random entries.
MULTISETrandomGenerates a multiset with random entries.

Connector Options

OptionRequiredDefaultTypeDescription
connector
required(none)StringSpecify what connector to use, here should be ‘datagen’.
rows-per-second
optional10000LongRows per second to control the emit rate.
number-of-rows
optional(none)LongThe total number of rows to emit. By default, the table is unbounded.
scan.parallelism
optional(none)IntegerDefines the parallelism of the source. If not set, the global default parallelism is used.
fields.#.kind
optionalrandomStringGenerator of this ‘#’ field. Can be ‘sequence’ or ‘random’.
fields.#.min
optional(Minimum value of type)(Type of field)Minimum value of random generator, work for numeric types.
fields.#.max
optional(Maximum value of type)(Type of field)Maximum value of random generator, work for numeric types.
fields.#.max-past
optional0DurationMaximum past of timestamp random generator, only works for timestamp types.
fields.#.length
optional100IntegerSize or length of the collection for generating varchar/varbinary/string/bytes/array/map/multiset types. Please notice that for variable-length fields (varchar/varbinary), the default length is defined by the schema and cannot be set to a length greater than it. for super-long fields (string/bytes), the default length is 100 and can be set to a length less than 2^31. for constructed fields (array/map/multiset), the default number of elements is 3 and can be customized.
fields.#.var-len
optionalfalseBooleanWhether to generate a variable-length data, please notice that it should only be used for variable-length types (varchar, string, varbinary, bytes).
fields.#.start
optional(none)(Type of field)Start value of sequence generator.
fields.#.end
optional(none)(Type of field)End value of sequence generator.
fields.#.null-rate
optional(none)(Type of field)The proportion of null values.