ClickHouse/dbms/src/TableFunctions/TableFunctionInput.cpp

53 lines
1.6 KiB
C++
Raw Normal View History

2019-05-28 18:27:00 +00:00
#include <TableFunctions/ITableFunction.h>
#include <TableFunctions/TableFunctionInput.h>
#include <TableFunctions/TableFunctionFactory.h>
2019-09-05 13:17:01 +00:00
#include <TableFunctions/parseColumnsListForTableFunction.h>
2019-05-28 18:27:00 +00:00
#include <Parsers/ASTFunction.h>
#include <Parsers/ASTLiteral.h>
#include <Common/Exception.h>
#include <Common/typeid_cast.h>
#include <Storages/StorageInput.h>
#include <DataTypes/DataTypeFactory.h>
#include <Interpreters/Context.h>
#include <Interpreters/evaluateConstantExpression.h>
#include <boost/algorithm/string.hpp>
2019-12-15 06:34:43 +00:00
#include "registerTableFunctions.h"
2019-05-28 18:27:00 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
}
StoragePtr TableFunctionInput::executeImpl(const ASTPtr & ast_function, const Context & context, const std::string & table_name) const
2019-05-28 18:27:00 +00:00
{
const auto * function = ast_function->as<ASTFunction>();
if (!function->arguments)
throw Exception("Table function '" + getName() + "' must have arguments", ErrorCodes::LOGICAL_ERROR);
auto args = function->arguments->children;
if (args.size() != 1)
throw Exception("Table function '" + getName() + "' requires exactly 1 argument: structure",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
String structure = evaluateConstantExpressionOrIdentifierAsLiteral(args[0], context)->as<ASTLiteral &>().value.safeGet<String>();
2019-09-05 13:17:01 +00:00
auto columns = parseColumnsListFromString(structure, context);
StoragePtr storage = StorageInput::create(table_name, columns);
2019-05-28 18:27:00 +00:00
storage->startup();
return storage;
}
void registerTableFunctionInput(TableFunctionFactory & factory)
{
factory.registerFunction<TableFunctionInput>();
}
}