mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Support Nested types in "generateRandom"
This commit is contained in:
parent
a517111259
commit
8ad89a82d4
@ -14,6 +14,7 @@
|
||||
#include <DataTypes/DataTypeArray.h>
|
||||
#include <DataTypes/DataTypeString.h>
|
||||
#include <DataTypes/DataTypeFixedString.h>
|
||||
#include <DataTypes/NestedUtils.h>
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnFixedString.h>
|
||||
#include <Columns/ColumnString.h>
|
||||
@ -57,7 +58,12 @@ void fillBufferWithRandomData(char * __restrict data, size_t size, pcg64 & rng)
|
||||
|
||||
|
||||
ColumnPtr fillColumnWithRandomData(
|
||||
const DataTypePtr type, UInt64 limit, UInt64 max_array_length, UInt64 max_string_length, pcg64 & rng, const Context & context)
|
||||
const DataTypePtr type,
|
||||
UInt64 limit,
|
||||
UInt64 max_array_length,
|
||||
UInt64 max_string_length,
|
||||
pcg64 & rng,
|
||||
const Context & context)
|
||||
{
|
||||
TypeIndex idx = type->getTypeId();
|
||||
|
||||
@ -340,14 +346,24 @@ public:
|
||||
protected:
|
||||
Chunk generate() override
|
||||
{
|
||||
/// To support Nested types, we will collect them to single Array of Tuple.
|
||||
auto names_and_types = Nested::collect(block_header.getNamesAndTypesList());
|
||||
|
||||
Columns columns;
|
||||
columns.reserve(block_header.columns());
|
||||
DataTypes types = block_header.getDataTypes();
|
||||
columns.reserve(names_and_types.size());
|
||||
|
||||
for (const auto & type : types)
|
||||
columns.emplace_back(fillColumnWithRandomData(type, block_size, max_array_length, max_string_length, rng, context));
|
||||
Block compact_block;
|
||||
for (const auto & elem : names_and_types)
|
||||
{
|
||||
compact_block.insert(
|
||||
{
|
||||
fillColumnWithRandomData(elem.type, block_size, max_array_length, max_string_length, rng, context),
|
||||
elem.type,
|
||||
elem.name
|
||||
});
|
||||
}
|
||||
|
||||
return {std::move(columns), block_size};
|
||||
return {Nested::flatten(compact_block).getColumns(), block_size};
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -0,0 +1,2 @@
|
||||
100 12366141706519416319
|
||||
109 2990700419202507835
|
@ -0,0 +1,8 @@
|
||||
DROP TABLE IF EXISTS mass_table_312;
|
||||
CREATE TABLE mass_table_312 (d Date DEFAULT '2000-01-01', x UInt64, n Nested(a String, b String)) ENGINE = MergeTree(d, x, 1);
|
||||
INSERT INTO mass_table_312 SELECT * FROM generateRandom('`d` Date,`x` UInt64,`n.a` Array(String),`n.b` Array(String)', 1, 10, 2) LIMIT 100;
|
||||
|
||||
SELECT count(), sum(cityHash64(*)) FROM mass_table_312;
|
||||
SELECT count(), sum(cityHash64(*)) FROM mass_table_312 ARRAY JOIN n;
|
||||
|
||||
DROP TABLE mass_table_312;
|
Loading…
Reference in New Issue
Block a user