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());
|
2020-04-15 20:28:05 +00:00
|
|
|
IParser::Pos token_iterator(tokens, context.getSettingsRef().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);
|
|
|
|
|
2020-05-04 00:11:49 +00:00
|
|
|
return InterpreterCreateQuery::getColumnsDescription(*columns_list, context, !context.getSettingsRef().allow_suspicious_codecs);
|
2019-07-31 15:36:10 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 15:58:28 +00:00
|
|
|
}
|