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. For variable sized types, char/varchar/string/array/map/multiset, the length can be specified. Additionally, a total number of rows can be specified, resulting in a bounded table.

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 conjuction 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)

Types

TypeSupported GeneratorsNotes
BOOLEANrandom
CHARrandom / sequence
VARCHARrandom / 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.
TIMESTAMPrandomAlways resolves to the current timestamp of the local machine.
TIMESTAMP WITH LOCAL TIMEZONErandomAlways resolves to the current timestamp of the local machine.
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.
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.#.length
optional100IntegerSize or length of the collection for generating char/varchar/string/array/map/multiset types.
fields.#.start
optional(none)(Type of field)Start value of sequence generator.
fields.#.end
optional(none)(Type of field)End value of sequence generator.