1. Home
  2. Knowledge Base
  3. ClickHouse
  4. How to generate random data for ClickHouse tables?
  1. Home
  2. Knowledge Base
  3. ClickHouse DBA
  4. How to generate random data for ClickHouse tables?
  1. Home
  2. Knowledge Base
  3. ClickHouse Performance
  4. How to generate random data for ClickHouse tables?

How to generate random data for ClickHouse tables?

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;
Was this article helpful?

Related Articles

CHISTADATA IS COMMITTED TO OPEN SOURCE SOFTWARE AND BUILDING HIGH PERFORMANCE COLUMNSTORES

In the spirit of freedom, independence and innovation. ChistaDATA Corporation is not affiliated with ClickHouse Corporation 

Need Support?

Can't find the answer you're looking for?
Contact Support

ChistaDATA Inc. Knowledge base is licensed under the Apache License, Version 2.0 (the “License”)

Copyright 2022 ChistaDATA Inc

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.