mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-13 01:41:59 +00:00
51 lines
1.8 KiB
C++
51 lines
1.8 KiB
C++
#include <Interpreters/Context.h>
|
|
#include <Parsers/ASTLiteral.h>
|
|
#include <Parsers/ASTFunction.h>
|
|
#include <Storages/StorageNull.h>
|
|
#include <TableFunctions/parseColumnsListForTableFunction.h>
|
|
#include <TableFunctions/ITableFunction.h>
|
|
#include <TableFunctions/TableFunctionFactory.h>
|
|
#include <TableFunctions/TableFunctionNull.h>
|
|
#include <Interpreters/evaluateConstantExpression.h>
|
|
#include "registerTableFunctions.h"
|
|
|
|
|
|
namespace DB
|
|
{
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
}
|
|
|
|
void TableFunctionNull::parseArguments(const ASTPtr & ast_function, ContextPtr context)
|
|
{
|
|
const auto * function = ast_function->as<ASTFunction>();
|
|
if (!function || !function->arguments)
|
|
throw Exception("Table function '" + getName() + "' requires 'structure'.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
const auto & arguments = function->arguments->children;
|
|
if (arguments.size() != 1)
|
|
throw Exception("Table function '" + getName() + "' requires 'structure'.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
structure = evaluateConstantExpressionOrIdentifierAsLiteral(arguments[0], context)->as<ASTLiteral>()->value.safeGet<String>();
|
|
}
|
|
|
|
ColumnsDescription TableFunctionNull::getActualTableStructure(ContextPtr context) const
|
|
{
|
|
return parseColumnsListFromString(structure, context);
|
|
}
|
|
|
|
StoragePtr TableFunctionNull::executeImpl(const ASTPtr & /*ast_function*/, ContextPtr context, const std::string & table_name, ColumnsDescription /*cached_columns*/) const
|
|
{
|
|
auto columns = getActualTableStructure(context);
|
|
auto res = StorageNull::create(StorageID(getDatabaseName(), table_name), columns, ConstraintsDescription(), String{});
|
|
res->startup();
|
|
return res;
|
|
}
|
|
|
|
void registerTableFunctionNull(TableFunctionFactory & factory)
|
|
{
|
|
factory.registerFunction<TableFunctionNull>();
|
|
}
|
|
}
|