1#include <Parsers/ASTExpressionList.h>
2#include <Parsers/ParserCreateQuery.h>
3#include <Interpreters/InterpreterCreateQuery.h>
4#include <TableFunctions/parseColumnsListForTableFunction.h>
5
6
7namespace DB
8{
9
10namespace ErrorCodes
11{
12 extern const int SYNTAX_ERROR;
13}
14
15ColumnsDescription parseColumnsListFromString(const std::string & structure, const Context & context)
16{
17 Expected expected;
18
19 Tokens tokens(structure.c_str(), structure.c_str() + structure.size());
20 IParser::Pos token_iterator(tokens);
21
22 ParserColumnDeclarationList parser;
23 ASTPtr columns_list_raw;
24
25 if (!parser.parse(token_iterator, columns_list_raw, expected))
26 throw Exception("Cannot parse columns declaration list.", ErrorCodes::SYNTAX_ERROR);
27
28 auto * columns_list = dynamic_cast<ASTExpressionList *>(columns_list_raw.get());
29 if (!columns_list)
30 throw Exception("Could not cast AST to ASTExpressionList", ErrorCodes::LOGICAL_ERROR);
31
32 return InterpreterCreateQuery::getColumnsDescription(*columns_list, context);
33}
34
35}
36