mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-20 06:32:08 +00:00
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
#include <TableFunctions/ITableFunction.h>
|
|
#include <TableFunctions/TableFunctionNumbers.h>
|
|
#include <TableFunctions/TableFunctionFactory.h>
|
|
#include <Parsers/ASTFunction.h>
|
|
#include <Parsers/ASTLiteral.h>
|
|
#include <Common/Exception.h>
|
|
#include <Storages/System/StorageSystemNumbers.h>
|
|
#include <Interpreters/evaluateConstantExpression.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
}
|
|
|
|
|
|
StoragePtr TableFunctionNumbers::execute(const ASTPtr & ast_function, const Context & context) const
|
|
{
|
|
ASTs & args_func = typeid_cast<ASTFunction &>(*ast_function).children;
|
|
|
|
if (args_func.size() != 1)
|
|
throw Exception("Table function 'numbers' requires exactly one argument: amount of numbers.",
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
ASTs & args = typeid_cast<ASTExpressionList &>(*args_func.at(0)).children;
|
|
|
|
if (args.size() != 1)
|
|
throw Exception("Table function 'numbers' requires exactly one argument: amount of numbers.",
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
args[0] = evaluateConstantExpressionOrIdentidierAsLiteral(args[0], context);
|
|
|
|
UInt64 limit = static_cast<const ASTLiteral &>(*args[0]).value.safeGet<UInt64>();
|
|
|
|
auto res = StorageSystemNumbers::create(getName(), false, limit);
|
|
res->startup();
|
|
return res;
|
|
}
|
|
|
|
|
|
void registerTableFunctionNumbers(TableFunctionFactory & factory)
|
|
{
|
|
TableFunctionFactory::instance().registerFunction<TableFunctionNumbers>();
|
|
}
|
|
|
|
}
|