mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32: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/DataTypeArray.h>
|
||||||
#include <DataTypes/DataTypeString.h>
|
#include <DataTypes/DataTypeString.h>
|
||||||
#include <DataTypes/DataTypeFixedString.h>
|
#include <DataTypes/DataTypeFixedString.h>
|
||||||
|
#include <DataTypes/NestedUtils.h>
|
||||||
#include <Columns/ColumnArray.h>
|
#include <Columns/ColumnArray.h>
|
||||||
#include <Columns/ColumnFixedString.h>
|
#include <Columns/ColumnFixedString.h>
|
||||||
#include <Columns/ColumnString.h>
|
#include <Columns/ColumnString.h>
|
||||||
@ -57,7 +58,12 @@ void fillBufferWithRandomData(char * __restrict data, size_t size, pcg64 & rng)
|
|||||||
|
|
||||||
|
|
||||||
ColumnPtr fillColumnWithRandomData(
|
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();
|
TypeIndex idx = type->getTypeId();
|
||||||
|
|
||||||
@ -340,14 +346,24 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
Chunk generate() override
|
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 columns;
|
||||||
columns.reserve(block_header.columns());
|
columns.reserve(names_and_types.size());
|
||||||
DataTypes types = block_header.getDataTypes();
|
|
||||||
|
|
||||||
for (const auto & type : types)
|
Block compact_block;
|
||||||
columns.emplace_back(fillColumnWithRandomData(type, block_size, max_array_length, max_string_length, rng, context));
|
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:
|
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