2019-07-31 15:36:10 +00:00
|
|
|
#include <Parsers/ASTExpressionList.h>
|
|
|
|
#include <Parsers/ParserCreateQuery.h>
|
2020-06-08 22:49:19 +00:00
|
|
|
#include <Parsers/parseQuery.h>
|
2019-07-31 15:36:10 +00:00
|
|
|
#include <Interpreters/InterpreterCreateQuery.h>
|
2020-02-10 15:50:12 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2022-08-16 09:51:52 +00:00
|
|
|
#include <Interpreters/parseColumnsListForTableFunction.h>
|
2019-07-31 15:36:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
ColumnsDescription parseColumnsListFromString(const std::string & structure, ContextPtr context)
|
2019-07-31 15:36:10 +00:00
|
|
|
{
|
2022-07-04 14:46:10 +00:00
|
|
|
ParserColumnDeclarationList parser(true, true);
|
2021-04-10 23:33:54 +00:00
|
|
|
const Settings & settings = context->getSettingsRef();
|
2019-07-31 15:36:10 +00:00
|
|
|
|
2020-06-08 22:49:19 +00:00
|
|
|
ASTPtr columns_list_raw = parseQuery(parser, structure, "columns declaration list", settings.max_query_size, settings.max_parser_depth);
|
2019-07-31 15:36:10 +00:00
|
|
|
|
|
|
|
auto * columns_list = dynamic_cast<ASTExpressionList *>(columns_list_raw.get());
|
|
|
|
if (!columns_list)
|
|
|
|
throw Exception("Could not cast AST to ASTExpressionList", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
|
2021-04-16 10:15:35 +00:00
|
|
|
return InterpreterCreateQuery::getColumnsDescription(*columns_list, context, false);
|
2019-07-31 15:36:10 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 13:29:33 +00:00
|
|
|
bool tryParseColumnsListFromString(const std::string & structure, ColumnsDescription & columns, ContextPtr context)
|
|
|
|
{
|
2022-07-04 14:46:10 +00:00
|
|
|
ParserColumnDeclarationList parser(true, true);
|
2022-01-26 13:29:33 +00:00
|
|
|
const Settings & settings = context->getSettingsRef();
|
|
|
|
|
|
|
|
String error;
|
|
|
|
const char * start = structure.data();
|
|
|
|
const char * end = structure.data() + structure.size();
|
2022-01-26 13:48:21 +00:00
|
|
|
ASTPtr columns_list_raw = tryParseQuery(parser, start, end, error, false, "columns declaration list", false, settings.max_query_size, settings.max_parser_depth);
|
2022-01-26 13:29:33 +00:00
|
|
|
if (!columns_list_raw)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto * columns_list = dynamic_cast<ASTExpressionList *>(columns_list_raw.get());
|
|
|
|
if (!columns_list)
|
|
|
|
return false;
|
|
|
|
|
2022-08-16 09:41:32 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
columns = InterpreterCreateQuery::getColumnsDescription(*columns_list, context, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2022-01-26 13:29:33 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 15:58:28 +00:00
|
|
|
}
|