diff --git a/dbms/src/DataTypes/DataTypeNumberBase.cpp b/dbms/src/DataTypes/DataTypeNumberBase.cpp index 90356817730..ce01269bc4d 100644 --- a/dbms/src/DataTypes/DataTypeNumberBase.cpp +++ b/dbms/src/DataTypes/DataTypeNumberBase.cpp @@ -257,7 +257,7 @@ template class DataTypeNumberBase; template class DataTypeNumberBase; template class DataTypeNumberBase; template class DataTypeNumberBase; -template class DataTypeNumberBase; +template class DataTypeNumberBase; // used only in UUID template class DataTypeNumberBase; template class DataTypeNumberBase; template class DataTypeNumberBase; diff --git a/dbms/src/TableFunctions/TableFunctionRandom.cpp b/dbms/src/TableFunctions/TableFunctionRandom.cpp index 1391ecdc74b..d70c8a73c63 100644 --- a/dbms/src/TableFunctions/TableFunctionRandom.cpp +++ b/dbms/src/TableFunctions/TableFunctionRandom.cpp @@ -4,8 +4,17 @@ #include #include #include +#include +#include #include #include +#include +#include +#include +#include +#include +#include +#include #include @@ -34,222 +43,355 @@ namespace ErrorCodes extern const int LOGICAL_ERROR; } -MutableColumnPtr createColumnWithRandomData(DataTypePtr type, UInt64 limit) +void fillColumnWithRandomData(IColumn & column, DataTypePtr type, UInt64 limit, + UInt64 max_array_length, UInt64 max_string_length, UInt64 random_seed) { TypeIndex idx = type->getTypeId(); - MutableColumnPtr column = type->createColumn(); + if (!random_seed) + random_seed = randomSeed(); + (void) max_string_length; switch (idx) { case TypeIndex::Nothing: - for (UInt64 i = 0; i < limit; ++i) - { - column->insertDefault(); - } throw Exception("Random Generator not implemented for type 'Nothing'.", ErrorCodes::NOT_IMPLEMENTED); case TypeIndex::UInt8: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { - pcg32 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } + data[i] = static_cast(generator()); } break; + } case TypeIndex::UInt16: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { - pcg32 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } + data[i] = static_cast(generator()); } break; + } case TypeIndex::UInt32: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { - pcg32 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } + data[i] = static_cast(generator()); } break; + } case TypeIndex::UInt64: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg64 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { - pcg64 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } + data[i] = static_cast(generator()); } break; + } case TypeIndex::UInt128: - throw Exception("Random Generator not implemented for type 'UInt128'.", ErrorCodes::NOT_IMPLEMENTED); + throw Exception("There is no DataType 'UInt128' support.", ErrorCodes::NOT_IMPLEMENTED); case TypeIndex::Int8: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { - pcg32 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } + data[i] = static_cast(generator()); } break; + } case TypeIndex::Int16: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { - pcg32 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } + data[i] = static_cast(generator()); } break; + } case TypeIndex::Int32: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { - pcg32 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } + data[i] = static_cast(generator()); } break; + } case TypeIndex::Int64: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg64 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { - pcg64 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } + data[i] = static_cast(generator()); } break; + } case TypeIndex::Int128: - throw Exception("Random Generator not implemented for type '" + String(TypeName::get()) + "'.", ErrorCodes::NOT_IMPLEMENTED); + throw Exception("There is no DataType 'Int128' support.", ErrorCodes::NOT_IMPLEMENTED); case TypeIndex::Float32: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + double d = 1.0; + for (UInt64 i = 0; i < limit; ++i) { - pcg32 generator(randomSeed()); - double d; - for (UInt64 i = 0; i < limit; ++i) - { - d = std::numeric_limits::max(); - column->insert( (d / pcg32::max()) * generator() ); - } + d = std::numeric_limits::max(); + data[i] = (d / pcg32::max()) * generator(); } break; + } case TypeIndex::Float64: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg64 generator(random_seed); + double d = 1.0; + for (UInt64 i = 0; i < limit; ++i) { - pcg64 generator(randomSeed()); - double d; - for (UInt64 i = 0; i < limit; ++i) - { - d = std::numeric_limits::max(); - column->insert( (d / pcg64::max()) * generator() ); - } + d = std::numeric_limits::max(); + data[i] = (d / pcg64::max()) * generator(); } break; + } case TypeIndex::Date: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { - pcg32 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } + data[i] = static_cast(generator()); } break; + } case TypeIndex::DateTime: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { - pcg32 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } + data[i] = static_cast(generator()); } break; + } case TypeIndex::DateTime64: + { + UInt32 scale; + if (auto * ptype = typeid_cast(type.get())) + scale = ptype->getScale(); + else + throw Exception("Static cast to DataTypeDateTime64 failed ", ErrorCodes::BAD_TYPE_OF_FIELD); + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { - UInt32 scale; - if (auto * ptype = typeid_cast(type.get())) - scale = ptype->getScale(); - else - throw Exception("Static cast to DataTypeDateTime64 failed ", ErrorCodes::BAD_TYPE_OF_FIELD); - pcg32 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - UInt32 fractional = static_cast(generator()) % intExp10(scale); - UInt32 whole = static_cast(generator()); - DateTime64 dt = DecimalUtils::decimalFromComponents(whole, fractional, scale); - column->insert(DecimalField(dt, scale)); - } + UInt32 fractional = static_cast(generator()) % intExp10(scale); + UInt32 whole = static_cast(generator()); + DateTime64 dt = DecimalUtils::decimalFromComponents(whole, fractional, scale); + data[i] = dt; } break; + } case TypeIndex::String: - throw Exception("Random Generator not implemented for type '" + String(TypeName::get()) + "'.", ErrorCodes::NOT_IMPLEMENTED); - case TypeIndex::FixedString: - throw Exception("Random Generator not implemented for type 'FixedString'.", ErrorCodes::NOT_IMPLEMENTED); - case TypeIndex::Enum8: - throw Exception("Random Generator not implemented for type 'Enum8'.", ErrorCodes::NOT_IMPLEMENTED); - case TypeIndex::Enum16: - throw Exception("Random Generator not implemented for type 'Enum16'.", ErrorCodes::NOT_IMPLEMENTED); - case TypeIndex::Decimal32: - { - pcg32 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } - } - break; - case TypeIndex::Decimal64: - { - pcg64 generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(static_cast(generator())); - } - } - break; - case TypeIndex::Decimal128: - throw Exception("Random Generator not implemented for type 'Decimal128'.", ErrorCodes::NOT_IMPLEMENTED); -/* - { - UInt32 scale = 0; - if (auto * ptype = typeid_cast *>(type.get())) - scale = ptype->getScale(); - else - throw Exception("Static cast to Decimal128 failed ", ErrorCodes::BAD_TYPE_OF_FIELD); + { + auto & column_string = typeid_cast(column); + auto & offsets = column_string.getOffsets(); + auto & chars = column_string.getChars(); - pcg128_once_insecure generator(randomSeed()); - for (UInt64 i = 0; i < limit; ++i) - { - column->insert(DecimalField(static_cast(generator()), scale)); - } - } - break; -*/ - case TypeIndex::UUID: + UInt64 offset = 0; { - pcg128_once_insecure generator(randomSeed()); + pcg32 generator(random_seed); + offsets.resize(limit); for (UInt64 i = 0; i < limit; ++i) { - column->insert(static_cast(generator())); + offset += 1 + static_cast(generator()) % max_string_length; + offsets[i] = offset - 1; + } + chars.resize(offset); + for (UInt64 i = 0; i < offset; ++i) { + chars[i] = 32 + generator() % 95; + } + // add terminating zero char + for (auto & i : offsets) + { + chars[i] = 0; } } break; + } + case TypeIndex::FixedString: + { + auto & column_string = typeid_cast(column); + size_t len = column_string.sizeOfValueIfFixed(); + auto & chars = column_string.getChars(); + + UInt64 num_chars = static_cast(len) * limit; + { + pcg32 generator(random_seed); + chars.resize(num_chars); + for (UInt64 i = 0; i < num_chars; ++i) { + chars[i] = static_cast(generator()); + } + } + break; + } + case TypeIndex::Enum8: + { + auto values = typeid_cast *>(type.get())->getValues(); + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + + UInt8 size = values.size(); + UInt8 off; + for (UInt64 i = 0; i < limit; ++i) + { + off = static_cast(generator()) % size; + data[i] = values[off].second; + } + break; + } + case TypeIndex::Enum16: + { + auto values = typeid_cast *>(type.get())->getValues(); + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + + UInt16 size = values.size(); + UInt8 off; + for (UInt64 i = 0; i < limit; ++i) + { + off = static_cast(generator()) % size; + data[i] = values[off].second; + } + break; + } + case TypeIndex::Decimal32: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg32 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) + { + data[i] = static_cast(generator()); + } + break; + } + case TypeIndex::Decimal64: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg64 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) + { + data[i] = static_cast(generator()); + } + break; + } + case TypeIndex::Decimal128: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg64 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) + { + Int128 x = static_cast(generator()) << 64 | static_cast(generator()); + data[i] = x; + } + } + break; + case TypeIndex::UUID: + { + auto & data = typeid_cast &>(column).getData(); + data.resize(limit); + pcg64 generator(random_seed); + for (UInt64 i = 0; i < limit; ++i) { + auto x = UInt128(generator(), generator()); + data[i] = x; + } + } + break; case TypeIndex::Array: - throw Exception("Random Generator not implemented for type 'Array'.", ErrorCodes::NOT_IMPLEMENTED); + { + auto & column_array = typeid_cast(column); + auto nested_type = typeid_cast(type.get())->getNestedType(); + + auto & offsets = column_array.getOffsets(); + IColumn & data = column_array.getData(); + + UInt64 offset = 0; + { + pcg32 generator(random_seed); + offsets.resize(limit); + for (UInt64 i = 0; i < limit; ++i) { + offset += static_cast(generator()) % max_array_length; + offsets[i] = offset; + } + } + fillColumnWithRandomData(data, nested_type, offset, max_array_length, max_string_length, random_seed); + break; + } case TypeIndex::Tuple: - throw Exception("Random Generator not implemented for type 'Tuple'.", ErrorCodes::NOT_IMPLEMENTED); + { + auto &column_tuple = typeid_cast(column); + auto elements = typeid_cast(type.get())->getElements(); + + for (size_t i = 0; i < column_tuple.tupleSize(); ++i) + { + fillColumnWithRandomData(column_tuple.getColumn(i), elements[i], limit, max_array_length, max_string_length, random_seed); + } + break; + } case TypeIndex::Set: - throw Exception("Random Generator not implemented for type 'Set'.", ErrorCodes::NOT_IMPLEMENTED); + throw Exception("Type 'Set' can not be stored in a table.", ErrorCodes::LOGICAL_ERROR); case TypeIndex::Interval: throw Exception("Type 'Interval' can not be stored in a table.", ErrorCodes::LOGICAL_ERROR); case TypeIndex::Nullable: - throw Exception("Random Generator not implemented for type 'Nullable'.", ErrorCodes::NOT_IMPLEMENTED); + { + auto & column_nullable = typeid_cast(column); + auto nested_type = typeid_cast(type.get())->getNestedType(); + + auto & null_map = column_nullable.getNullMapData(); + IColumn & nested_column = column_nullable.getNestedColumn(); + + fillColumnWithRandomData(nested_column, nested_type, limit, max_array_length, max_string_length, random_seed); + + pcg32 generator(random_seed); + null_map.resize(limit); + for (UInt64 i = 0; i < limit; ++i) { + null_map[i] = generator() < 1024; + } + break; + } case TypeIndex::Function: - throw Exception("Random Generator not implemented for type 'Function'.", ErrorCodes::NOT_IMPLEMENTED); + throw Exception("Type 'Funclion' can not be stored in a table.", ErrorCodes::LOGICAL_ERROR); case TypeIndex::AggregateFunction: throw Exception("Random Generator not implemented for type 'AggregateFunction'.", ErrorCodes::NOT_IMPLEMENTED); case TypeIndex::LowCardinality: throw Exception("Random Generator not implemented for type 'LowCardinality'.", ErrorCodes::NOT_IMPLEMENTED); } - return column; } StoragePtr TableFunctionRandom::executeImpl(const ASTPtr & ast_function, const Context & context, const std::string & table_name) const @@ -261,30 +403,48 @@ StoragePtr TableFunctionRandom::executeImpl(const ASTPtr & ast_function, const C ASTs & args = args_func.at(0)->children; - if (args.size() > 2) - throw Exception("Table function '" + getName() + "' requires one or two arguments: structure (and limit).", + if (args.size() > 5) + throw Exception("Table function '" + getName() + "' requires at most five arguments: "\ + " structure, limit, max_array_length, max_string_length, random_seed.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); /// Parsing first argument as table structure and creating a sample block std::string structure = args[0]->as().value.safeGet(); UInt64 limit = 1; + UInt64 max_array_length = 10; + UInt64 max_string_length = 10; + UInt64 random_seed = 0; // zero for random + /// Parsing second argument if present - if (args.size() == 2) + if (args.size() >= 2) limit = args[1]->as().value.safeGet(); if (!limit) throw Exception("Table function '" + getName() + "' limit should not be 0.", ErrorCodes::BAD_ARGUMENTS); + if (args.size() >= 3) + max_array_length = args[1]->as().value.safeGet(); + + if (args.size() >= 4) + max_string_length = args[1]->as().value.safeGet(); + + if (args.size() == 5) + random_seed = args[1]->as().value.safeGet(); + ColumnsDescription columns = parseColumnsListFromString(structure, context); Block res_block; for (const auto & name_type : columns.getOrdinary()) { - MutableColumnPtr column = createColumnWithRandomData(name_type.type, limit); + MutableColumnPtr column = name_type.type->createColumn(); res_block.insert({std::move(column), name_type.type, name_type.name}); } + for (auto & ctn : res_block.getColumnsWithTypeAndName()) + { + fillColumnWithRandomData(ctn.column->assumeMutableRef(), ctn.type, limit, max_array_length, max_string_length, random_seed); + } auto res = StorageValues::create(StorageID(getDatabaseName(), table_name), columns, res_block); res->startup(); return res; diff --git a/dbms/tests/queries/0_stateless/01072_random_table_function.reference b/dbms/tests/queries/0_stateless/01072_random_table_function.reference new file mode 100644 index 00000000000..93ea1861756 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01072_random_table_function.reference @@ -0,0 +1,207 @@ +Enum8(\'hello\' = 1, \'world\' = 5) +world +hello +world +hello +hello +hello +world +hello +hello +hello +Array(Nullable(Enum8(\'hello\' = 1, \'world\' = 5))) +['world','hello','world','hello','hello','hello','world','hello','hello'] +['hello','world','world','hello','world','world'] +['hello','world','hello','hello','world','world','world'] +['world','world','world','world','world','world','hello','hello'] +['world','hello'] +['hello','hello'] +['world'] +['hello','hello'] +['hello','hello'] +['hello','world','hello','hello','world','world','world','world'] +Nullable(Enum16(\'o\' = -200, \'h\' = 1, \'w\' = 5)) +o +w +w +w +h +w +h +h +w +o +UInt64 Int64 UInt32 Int32 UInt16 Int16 UInt8 Int8 +2254772619926532955 2254772619926532955 1234817989 1234817989 54213 -11323 197 -59 +9120028858397505560 9120028858397505560 1171957426 1171957426 42674 -22862 178 -78 +4555697903102013946 4555697903102013946 275100647 275100647 46055 -19481 231 -25 +5784362079052877875 5784362079052877875 1033685688 1033685688 51896 -13640 184 -72 +11035971995277520997 -7410772078432030619 180895192 180895192 15832 15832 216 -40 +7901646768096461004 7901646768096461004 135557292 135557292 28844 28844 172 -84 +6733841386518201279 6733841386518201279 716914271 716914271 15967 15967 95 95 +7736560050027905187 7736560050027905187 1012211222 1012211222 7702 7702 22 22 +2199287578947862030 2199287578947862030 2185722662 -2109244634 31526 31526 38 38 +3019483913099890467 3019483913099890467 2647224658 -1647742638 29010 29010 82 82 +Date DateTime DateTime(\'Europe/Moscow\') +2106-02-07 2009-02-16 23:59:49 2009-02-16 23:59:49 +2086-11-02 2007-02-20 10:43:46 2007-02-20 10:43:46 +2096-02-04 1978-09-20 03:50:47 1978-09-20 03:50:47 +2106-02-07 2002-10-04 02:54:48 2002-10-04 02:54:48 +2013-05-07 1975-09-25 19:39:52 1975-09-25 19:39:52 +2048-12-21 1974-04-19 01:48:12 1974-04-19 01:48:12 +2013-09-19 1992-09-19 18:51:11 1992-09-19 18:51:11 +1991-02-02 2002-01-28 12:47:02 2002-01-28 12:47:02 +2056-04-25 2039-04-06 20:11:02 2039-04-06 20:11:02 +2049-06-05 2053-11-20 07:10:58 2053-11-20 07:10:58 +DateTime64(3) DateTime64(6) DateTime64(6, \'Europe/Moscow\') +2007-02-20 10:43:46.989 2007-02-20 10:43:46.817989 2007-02-20 10:43:46.817989 +2002-10-04 02:54:48.647 2002-10-04 02:54:48.100647 2002-10-04 02:54:48.100647 +1974-04-19 01:48:12.192 1974-04-19 01:48:12.895192 1974-04-19 01:48:12.895192 +2002-01-28 12:47:02.271 2002-01-28 12:47:02.914271 2002-01-28 12:47:02.914271 +2053-11-20 07:10:58.662 2053-11-20 07:10:58.722662 2053-11-20 07:10:58.722662 +1986-04-08 19:07:15.849 1986-04-08 19:07:15.510849 1986-04-08 19:07:15.510849 +2081-03-06 04:00:55.914 2081-03-06 04:00:55.448914 2081-03-06 04:00:55.448914 +1979-01-20 20:39:20.939 1979-01-20 20:39:20.162939 1979-01-20 20:39:20.162939 +2063-07-18 01:46:10.215 2063-07-18 01:46:10.908215 2063-07-18 01:46:10.908215 +1996-11-02 14:35:41.110 1996-11-02 14:35:41.183110 1996-11-02 14:35:41.183110 +Float32 Float64 +9.783235e37 2.1973467205491123e307 +9.285203e37 8.887754501811354e307 +2.1795718e37 4.4396706606805647e307 +8.1897013e37 5.637042481600483e307 +1.4331993e37 1.07549012514996e308 +1.0739954e37 7.700402896226395e307 +5.67998e37 6.562339881458101e307 +8.019563e37 7.539520705557441e307 +1.7317079e38 2.143274805821858e307 +2.0973474e38 2.9425818885529257e307 +Decimal32(4) Decimal64(8) Decimal64(8) +123481.7989 22547726199.26532955 4159321346419233104838.6879832895010840 +117195.7426 91200288583.97505560 8403779329565810688767.7049545291714611 +27510.0647 45556979031.02013946 -13670461591942827725055.0250490776469300 +103368.5688 57843620790.52877875 12421744869005473959544.2499747955622051 +18089.5192 -74107720784.32030619 4056969511333950153663.4915186231430947 +13555.7292 79016467680.96461004 -8819413736166121578589.4583420666183888 +71691.4271 67338413865.18201279 13058329479868658041313.8432372419860363 +101221.1222 77365600500.27905187 -4693380431928321782727.0243506636623202 +-210924.4634 21992875789.47862030 13765369952377767241248.9441272127848016 +-164774.2638 30194839130.99890467 -13890064946313418575619.0315227826809939 +UUID +1f4a8fc0-63ff-735b-7e90-d9ed3e183818 +3f39171b-1263-31fa-5046-2ea9fe2fd033 +9927a60f-01ac-f065-6da8-49def100c0cc +5d736910-493d-c3bf-6b5d-c8601d6440a3 +1e857066-961d-be0e-29e7-5c9efd534f23 +bda66d4f-737b-3622-b60f-aa27fe38ff30 +623d6d82-4422-2885-297f-7b2fec54178b +dcb0e0ca-3a43-5f2e-556e-7945df65729e +678f2360-36ac-d439-8d6d-f92295887e50 +9780b53e-dc0f-4a21-bdb3-9798af1913ad +Tuple(Int32, Int64) +(1234817989,2254772619926532955) +(1171957426,9120028858397505560) +(275100647,4555697903102013946) +(1033685688,5784362079052877875) +(180895192,-7410772078432030619) +(135557292,7901646768096461004) +(716914271,6733841386518201279) +(1012211222,7736560050027905187) +(-2109244634,2199287578947862030) +(-1647742638,3019483913099890467) +Array(Int8) +[-59,-78,-25,-72,-40,-84,95,22,38] +[82,65,35,-110,-57,-69] +[72,119,-78,-58,13,39,-71] +[81,107,-11,-63,-59,69,-80,-122] +[87,-76] +[22,-84] +[-45] +[-40,84] +[-104,-86] +[-36,123,44,60,5,25,-5,-127] +Array(Nullable(Int32)) +[1234817989,1171957426,275100647,1033685688,180895192,135557292,716914271,1012211222,-2109244634] +[-1647742638,319510849,513356835,-1966518382,-786518841,269162939] +[285701960,1943908215,-1343029326,1474183110,846934541,1007818023,-1664171079] +[195050577,371018347,734173429,2001591233,-1812297275,1172704837,-728923984,774864518] +[-462583209,-1520633676] +[-638906858,1986832300] +[378774483] +[-1399152424,-953863084] +[733724312,-23652950] +[371735004,462118779,148602156,-1055384004,-1041274619,247762201,522289659,822210177] +Array(Nullable(UUID)) +['1f4a8fc0-63ff-735b-7e90-d9ed3e183818','3f39171b-1263-31fa-5046-2ea9fe2fd033','9927a60f-01ac-f065-6da8-49def100c0cc','5d736910-493d-c3bf-6b5d-c8601d6440a3','1e857066-961d-be0e-29e7-5c9efd534f23','bda66d4f-737b-3622-b60f-aa27fe38ff30','623d6d82-4422-2885-297f-7b2fec54178b','dcb0e0ca-3a43-5f2e-556e-7945df65729e','678f2360-36ac-d439-8d6d-f92295887e50'] +['9780b53e-dc0f-4a21-bdb3-9798af1913ad','c79810de-3635-d333-5ca1-7a81ab302b25','1c756bca-4438-3f17-a766-c8bcbe3ba400','d9072738-ac93-7ed6-167b-3c3c66d35a18','b1e8dec2-de29-3c9f-aaf2-f78fd92df3ce','9cd25f9f-3c0d-f43d-5a46-0194f0be04dd'] +['10a4718d-ab8c-49c6-c785-66ccf112f7d5','02ac2bf5-5634-a5a8-9a18-05ce8d1fb583','8037a13d-2004-08f2-f831-fa2387f5c29a','a99c4373-1121-2691-ecbb-216adbd748c7','ef0986ff-5031-0353-2f21-1de3ea53af08','778064a7-653b-ef7b-c77b-4d769b12b917','a1607e6f-691a-0ff0-b0b3-e454dae7bef7'] +['71c1b47a-c0eb-42b5-eecd-18dc585284fd','72bbf272-9ec5-09ec-f339-b5dac55c037b','26e5bce5-43f7-59b0-84c6-ef509f4c45eb','305fcbff-c366-2033-a8c5-d648f236e754','3a0d329f-f897-84e9-9e87-9501a713e63d','54bda20c-d5cd-a08a-c078-3c4fd81f4f55','43f549d1-3e5b-d5bf-ed32-b4850648bdc8','7eb6ac4f-06e0-ff48-6330-3c7afa5f2644'] +['17b9a4a5-fef8-a3f9-5af4-3b6e67ca62c9','3f524d8e-320d-00dc-c210-e199206550db'] +['005c592e-5081-9f3d-1fcb-5a9e82f39f97','29cf228d-b325-4a34-3eff-e80494a79260'] +['6c08b54b-8cf8-b96d-f087-8b54f5e72d0e'] +['7122e162-ab8b-a84a-6b71-c0846cf0204d','51c1de1a-24c7-18d6-39ed-e9023205610c'] +['f09d6779-1106-d667-e7c9-9a0cad544afe','62060fec-ee13-7c66-5da4-02c8f4d50dc9'] +['df1d0d54-d639-9c9b-2070-622fc9d82203','f23ef5b9-3797-9b0e-b8ac-67ea31b99c3e','e48afe73-9e22-7439-afed-d53b6ea204f4','d7f1ab47-4928-7623-283e-fb3f16aebeba','ea270407-d32f-a407-add2-3ae2d1113ccb','c43e9fff-2980-a1d1-f1bb-ff94d3cffbc2','a0cd54e6-0a2d-07ec-88ad-4f5d29c15b06','5e93413f-2eb9-5363-17ab-e2215b8b19e0'] +Tuple(Int32, Array(Int64)) +(1234817989,[2254772619926532955,9120028858397505560,4555697903102013946,5784362079052877875,-7410772078432030619,7901646768096461004,6733841386518201279,7736560050027905187,2199287578947862030]) +(1171957426,[3019483913099890467,-4781013766399904222,-5327852745410412752,7078934595552553093,2990244123355912075,-2544286630298820818]) +(275100647,[6155991081669718686,7462222003717329977,-8255668614967296432,-7529819295378879967,-4777308097681484883,-4064480117123591373,6674750820081216293]) +(1033685688,[2050663721809231639,-6384194708780112896,-2808232718275215658,1619954721090656792,-5627002805867168609,-6128563945701772338,-7146544521171569603,6504888450989032669]) +(180895192,[1199208254069819846,-4069733657855461419]) +(135557292,[192577216783361448,-7343112807738526333]) +(716914271,[-9207713629233477390]) +(1012211222,[-562393447932771686,-6225026423445182831]) +(-2109244634,[-1388479317275096889,-1222297392734207149]) +(-1647742638,[3396028458740199176,8610993157653131131,-4072576266223306473,-6818310818869145616,-5713972449102020873,8197031236106666677,-1239306987803343619,8267468115072584172]) +FixedString(4) +Ų +ج_ +&RA# +ǻH +w\r +\'Qk +E +W + +T +String +String +String +String +String +String +String +String +String +String +)/VC)%f9 +\0ih|;B +\0J"Z,kd +\0m"m]$35 +\00 +\0( +\0 +\0g +\0> +\0XjbW:s< +Nullable(String) +)/VC)%f9 +\0ih|;B +\0J"Z,kd +\0m"m]$35 +\00 +\0( +\0 +\0g +\0> +\0XjbW:s< +Array(String) +['(|ZVAg2F','\0GXjbW','\0<^guT(','\0y M$lZ0','\03','\0p','\0','\0i','\0P'] +['\0"}YRG%B','\0T3(E^> p','\0JTaj','\0)*3','\0k%=p','\0Yub$81`X'] +['','\0\\p]|]','\05','\0k$C/pnA'] +['\0ryz{*p',''] +['\07`mjt*G',''] +['\0~g'] +['\0k','\0 '] +['\0F','\0&h diff --git a/docs/ja/query_language/table_functions/generate.md b/docs/ja/query_language/table_functions/generate.md new file mode 120000 index 00000000000..de0b0a41754 --- /dev/null +++ b/docs/ja/query_language/table_functions/generate.md @@ -0,0 +1 @@ +en/query_language/table_functions/generate.md \ No newline at end of file diff --git a/docs/ru/query_language/table_functions/generate.md b/docs/ru/query_language/table_functions/generate.md new file mode 100644 index 00000000000..11d7f7073a9 --- /dev/null +++ b/docs/ru/query_language/table_functions/generate.md @@ -0,0 +1,37 @@ +# generate + +Генерирует случайные данные с заданной схемой. +Позволяет заполнять тестовые таблицы данными. +Поддерживает все типы данных, которые могут храниться в таблице, за исключением LowCardinality, AggregateFunction. + +```sql +generate('name TypeName[, name TypeName]...', 'limit'[, 'max_array_length'[, 'max_string_length'[, 'random_seed']]]); +``` + +**Входные параметры** +- `name` — название соответствующего столбца. +- `TypeName` — тип соответствующего столбца. +- `limit` — количество строк для генерации. +- `max_array_length` — максимальная длина массива для всех сгенерированных массивов. По умолчанию `10`. +- `max_string_length` — максимальная длина строки для всех генерируемых строк. По умолчанию `10`. +- `random_seed` — укажите состояние генератора случайных чисел вручную, чтобы получить стабильные результаты. По умолчанию `0` - генератор инициализируется случайным состоянием. + +**Возвращаемое значение** + +Объект таблицы с запрошенной схемой. + +## Пример + + +```sql +SELECT * FROM generate('a Array(Int8), d Decimal32(4), c Tuple(DateTime64(3), UUID)', 3, 2, 10, 1); +``` +```text +┌─a────────┬────────────d─┬─c──────────────────────────────────────────────────────────────────┐ +│ [77] │ -124167.6723 │ ('2061-04-17 21:59:44.573','3f72f405-ec3e-13c8-44ca-66ef335f7835') │ +│ [32,110] │ -141397.7312 │ ('1979-02-09 03:43:48.526','982486d1-5a5d-a308-e525-7bd8b80ffa73') │ +│ [68] │ -67417.0770 │ ('2080-03-12 14:17:31.269','110425e5-413f-10a6-05ba-fa6b3e929f15') │ +└──────────┴──────────────┴────────────────────────────────────────────────────────────────────┘ +``` + +[Оригинальная статья](https://clickhouse.tech/docs/ru/query_language/table_functions/generate/) diff --git a/docs/zh/query_language/table_functions/generate.md b/docs/zh/query_language/table_functions/generate.md new file mode 120000 index 00000000000..de0b0a41754 --- /dev/null +++ b/docs/zh/query_language/table_functions/generate.md @@ -0,0 +1 @@ +en/query_language/table_functions/generate.md \ No newline at end of file