When performing tests, you may need to generate a large amount of test data for your tables to understand ClickHouse performance under pressure. The generateRandom() method in ClickHouse allows you to easily create and populate data into tables of any structure. The number of records is as given by the LIMIT value.
Use generateRandom()
generateRandom() function creates random data using the provided schema. Allows data to be loaded into test tables. Except for LowCardinality and AggregateFunction, it supports all data types that may be stored in a table. It consists of with 5 arguments exactly, and these are name, TypeName, max_array_length, max_string_length, random_seed
This will produce 1000 random records for a three-column table as existing with UUID, DateTime, and Text columns.
SELECT * FROM generateRandom('a UUID,b DateTime,c Text') LIMIT 1000;
Instead of using an alias, we can also provide the any data type.
SELECT * FROM generateRandom('ID Int64') LIMIT 1000;
Shorten/Lengthen value is possible.
You may also set the maximum string length for a column. For example, the context column will have until 2048 length values in below. We entered the NULL value for the UUID column to let alone.
SELECT * FROM generateRandom('a UUID, b DateTime, c Text', NULL, 2048) LIMIT 1000;
Also, we can specify column types below. We will have up to 2 length for ID and 500 length for Text column data.
SELECT * FROM generateRandom('ID Int64,test_context Text',2,500) LIMIT 1000;
Let us conduct a stress test with random data.
This will insert 100m rows into the specified structure.
INSERT INTO test_stress SELECT * FROM generateRandom('ID Int64, test_until_2k Text',1,2048) LIMIT 100000000;