2019-07-31 15:36:10 +00:00
|
|
|
#include <Parsers/ASTExpressionList.h>
|
|
|
|
#include <Parsers/ParserCreateQuery.h>
|
|
|
|
#include <Interpreters/InterpreterCreateQuery.h>
|
2020-02-10 15:50:12 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2019-07-31 15:36:10 +00:00
|
|
|
#include <TableFunctions/parseColumnsListForTableFunction.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2020-02-25 18:02:41 +00:00
|
|
|
extern const int LOGICAL_ERROR;
|
2019-07-31 15:36:10 +00:00
|
|
|
extern const int SYNTAX_ERROR;
|
|
|
|
}
|
|
|
|
|
2019-08-01 01:53:38 +00:00
|
|
|
ColumnsDescription parseColumnsListFromString(const std::string & structure, const Context & context)
|
2019-07-31 15:36:10 +00:00
|
|
|
{
|
|
|
|
Expected expected;
|
|
|
|
|
|
|
|
Tokens tokens(structure.c_str(), structure.c_str() + structure.size());
|
2019-08-10 16:38:25 +00:00
|
|
|
IParser::Pos token_iterator(tokens);
|
2020-01-14 11:11:01 +00:00
|
|
|
const Settings & settings = context.getSettingsRef();
|
|
|
|
token_iterator.max_depth = settings.max_parser_depth;
|
2019-07-31 15:36:10 +00:00
|
|
|
|
|
|
|
ParserColumnDeclarationList parser;
|
|
|
|
ASTPtr columns_list_raw;
|
|
|
|
|
|
|
|
if (!parser.parse(token_iterator, columns_list_raw, expected))
|
|
|
|
throw Exception("Cannot parse columns declaration list.", ErrorCodes::SYNTAX_ERROR);
|
|
|
|
|
|
|
|
auto * columns_list = dynamic_cast<ASTExpressionList *>(columns_list_raw.get());
|
|
|
|
if (!columns_list)
|
|
|
|
throw Exception("Could not cast AST to ASTExpressionList", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
|
2019-08-01 01:53:38 +00:00
|
|
|
return InterpreterCreateQuery::getColumnsDescription(*columns_list, context);
|
2019-07-31 15:36:10 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 15:58:28 +00:00
|
|
|
}
|