#include #include #include #include #include #include #include #include #include #include "registerTableFunctions.h" namespace DB { namespace ErrorCodes { extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; } template ColumnsDescription TableFunctionZeros::getActualTableStructure(ContextPtr /*context*/) const { /// NOTE: https://bugs.llvm.org/show_bug.cgi?id=47418 return ColumnsDescription{{{"zero", std::make_shared()}}}; } template StoragePtr TableFunctionZeros::executeImpl(const ASTPtr & ast_function, ContextPtr context, const std::string & table_name, ColumnsDescription /*cached_columns*/) const { if (const auto * function = ast_function->as()) { auto arguments = function->arguments->children; if (arguments.size() != 1) throw Exception("Table function '" + getName() + "' requires 'length'.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); UInt64 length = evaluateArgument(context, arguments[0]); auto res = std::make_shared(StorageID(getDatabaseName(), table_name), multithreaded, length); res->startup(); return res; } throw Exception("Table function '" + getName() + "' requires 'limit'.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); } void registerTableFunctionZeros(TableFunctionFactory & factory) { factory.registerFunction>({R"( Generates a stream of zeros (a table with one column 'zero' of type 'UInt8') of specified size. This table function is used in performance tests, where you want to spend as little time as possible to data generation while testing some other parts of queries. In contrast to the `zeros_mt`, this table function is using single thread for data generation. Example: [example:1] This query will test the speed of `randomPrintableASCII` function using single thread. See also the `system.zeros` table. )", {{"1", "SELECT count() FROM zeros(100000000) WHERE NOT ignore(randomPrintableASCII(10))"}} }); factory.registerFunction>({R"( Generates a stream of zeros (a table with one column 'zero' of type 'UInt8') of specified size. This table function is used in performance tests, where you want to spend as little time as possible to data generation while testing some other parts of queries. In contrast to the `zeros`, this table function is using multiple threads for data generation, according to the `max_threads` setting. Example: [example:1] This query will test the speed of `randomPrintableASCII` function using multiple threads. See also the `system.zeros` table. )", {{"1", "SELECT count() FROM zeros_mt(1000000000) WHERE NOT ignore(randomPrintableASCII(10))"}} }); } template UInt64 TableFunctionZeros::evaluateArgument(ContextPtr context, ASTPtr & argument) const { return checkAndGetLiteralArgument(evaluateConstantExpressionOrIdentifierAsLiteral(argument, context), "length"); } }