2019-01-17 10:09:51 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTFunction.h>
|
|
|
|
#include <Parsers/ASTIdentifier.h>
|
2018-12-25 18:45:08 +00:00
|
|
|
#include <Parsers/ASTIndexDeclaration.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTExpressionList.h>
|
|
|
|
#include <Parsers/ASTCreateQuery.h>
|
2019-03-23 22:45:28 +00:00
|
|
|
#include <Parsers/ASTSetQuery.h>
|
|
|
|
#include <Parsers/ASTSelectWithUnionQuery.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ExpressionListParsers.h>
|
|
|
|
#include <Parsers/ParserCreateQuery.h>
|
2018-02-25 00:50:53 +00:00
|
|
|
#include <Parsers/ParserSelectWithUnionQuery.h>
|
2017-09-18 14:18:29 +00:00
|
|
|
#include <Parsers/ParserSetQuery.h>
|
2011-08-18 18:48:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserNestedTable::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2013-07-11 17:35:56 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
ParserToken open(TokenType::OpeningRoundBracket);
|
|
|
|
ParserToken close(TokenType::ClosingRoundBracket);
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserIdentifier name_p;
|
|
|
|
ParserNameTypePairList columns_p;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr name;
|
|
|
|
ASTPtr columns;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-02 17:37:49 +00:00
|
|
|
/// For now `name == 'Nested'`, probably alternative nested data structures will appear
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!name_p.parse(pos, name, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!open.ignore(pos))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!columns_p.parse(pos, columns, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!close.ignore(pos))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2018-02-26 03:37:08 +00:00
|
|
|
auto func = std::make_shared<ASTFunction>();
|
2019-01-14 18:15:04 +00:00
|
|
|
getIdentifierName(name, func->name);
|
2017-04-01 07:20:54 +00:00
|
|
|
func->arguments = columns;
|
|
|
|
func->children.push_back(columns);
|
|
|
|
node = func;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2013-07-11 17:35:56 +00:00
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserIdentifierWithParameters::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2013-07-11 17:35:56 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserFunction function_or_array;
|
2017-07-10 03:28:12 +00:00
|
|
|
if (function_or_array.parse(pos, node, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserNestedTable nested;
|
2017-07-10 03:28:12 +00:00
|
|
|
if (nested.parse(pos, node, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2013-07-11 17:35:56 +00:00
|
|
|
}
|
2011-08-18 18:48:00 +00:00
|
|
|
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserIdentifierWithOptionalParameters::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2011-08-18 18:48:00 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserIdentifier non_parametric;
|
|
|
|
ParserIdentifierWithParameters parametric;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (parametric.parse(pos, node, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2011-08-18 18:48:00 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr ident;
|
2017-07-10 03:28:12 +00:00
|
|
|
if (non_parametric.parse(pos, ident, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2018-02-26 03:37:08 +00:00
|
|
|
auto func = std::make_shared<ASTFunction>();
|
2019-01-14 18:15:04 +00:00
|
|
|
getIdentifierName(ident, func->name);
|
2017-04-01 07:20:54 +00:00
|
|
|
node = func;
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-18 18:48:00 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2011-08-18 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserNameTypePairList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2013-07-11 17:35:56 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
return ParserList(std::make_unique<ParserNameTypePair>(), std::make_unique<ParserToken>(TokenType::Comma), false)
|
|
|
|
.parse(pos, node, expected);
|
2013-07-11 17:35:56 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserColumnDeclarationList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2014-09-24 14:44:57 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
return ParserList(std::make_unique<ParserColumnDeclaration>(), std::make_unique<ParserToken>(TokenType::Comma), false)
|
|
|
|
.parse(pos, node, expected);
|
2014-09-24 14:44:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-25 18:45:08 +00:00
|
|
|
bool ParserIndexDeclaration::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
|
|
|
ParserKeyword s_type("TYPE");
|
2019-01-02 16:04:44 +00:00
|
|
|
ParserKeyword s_granularity("GRANULARITY");
|
2018-12-25 18:45:08 +00:00
|
|
|
|
|
|
|
ParserIdentifier name_p;
|
|
|
|
ParserIdentifierWithOptionalParameters ident_with_optional_params_p;
|
2019-01-20 15:02:19 +00:00
|
|
|
ParserExpression expression_p;
|
2019-01-03 08:10:25 +00:00
|
|
|
ParserUnsignedInteger granularity_p;
|
2018-12-25 18:45:08 +00:00
|
|
|
|
|
|
|
ASTPtr name;
|
|
|
|
ASTPtr expr;
|
|
|
|
ASTPtr type;
|
2019-01-02 16:04:44 +00:00
|
|
|
ASTPtr granularity;
|
2018-12-25 18:45:08 +00:00
|
|
|
|
|
|
|
if (!name_p.parse(pos, name, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!expression_p.parse(pos, expr, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!s_type.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!ident_with_optional_params_p.parse(pos, type, expected))
|
|
|
|
return false;
|
|
|
|
|
2019-01-02 16:04:44 +00:00
|
|
|
if (!s_granularity.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!granularity_p.parse(pos, granularity, expected))
|
|
|
|
return false;
|
|
|
|
|
2018-12-25 18:45:08 +00:00
|
|
|
auto index = std::make_shared<ASTIndexDeclaration>();
|
2019-03-15 16:14:13 +00:00
|
|
|
index->name = name->as<ASTIdentifier &>().name;
|
|
|
|
index->granularity = granularity->as<ASTLiteral &>().value.get<UInt64>();
|
2018-12-25 18:45:08 +00:00
|
|
|
index->set(index->expr, expr);
|
|
|
|
index->set(index->type, type);
|
|
|
|
node = index;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-20 09:19:34 +00:00
|
|
|
|
|
|
|
bool ParserColumnAndIndexDeclaraion::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
|
|
|
ParserKeyword s_index("INDEX");
|
|
|
|
|
|
|
|
ParserIndexDeclaration index_p;
|
|
|
|
ParserColumnDeclaration column_p;
|
|
|
|
|
2019-01-20 15:02:19 +00:00
|
|
|
ASTPtr new_node = nullptr;
|
2019-01-20 09:19:34 +00:00
|
|
|
|
|
|
|
if (s_index.ignore(pos, expected))
|
|
|
|
{
|
2019-01-20 15:02:19 +00:00
|
|
|
if (!index_p.parse(pos, new_node, expected))
|
2019-01-20 09:19:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-20 15:02:19 +00:00
|
|
|
if (!column_p.parse(pos, new_node, expected))
|
2019-01-20 09:19:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-20 15:02:19 +00:00
|
|
|
node = new_node;
|
2019-01-20 09:19:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-08 11:04:25 +00:00
|
|
|
bool ParserIndexDeclarationList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
|
|
|
return ParserList(std::make_unique<ParserIndexDeclaration>(), std::make_unique<ParserToken>(TokenType::Comma), false)
|
|
|
|
.parse(pos, node, expected);
|
|
|
|
}
|
|
|
|
|
2013-07-11 17:35:56 +00:00
|
|
|
|
2019-01-20 09:33:29 +00:00
|
|
|
bool ParserColumnsOrIndicesDeclarationList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2019-01-20 09:19:34 +00:00
|
|
|
{
|
|
|
|
ASTPtr list;
|
|
|
|
if (!ParserList(std::make_unique<ParserColumnAndIndexDeclaraion>(), std::make_unique<ParserToken>(TokenType::Comma), false)
|
|
|
|
.parse(pos, list, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ASTPtr columns = std::make_shared<ASTExpressionList>();
|
|
|
|
ASTPtr indices = std::make_shared<ASTExpressionList>();
|
|
|
|
|
|
|
|
for (const auto & elem : list->children)
|
|
|
|
{
|
2019-03-11 13:22:51 +00:00
|
|
|
if (elem->as<ASTColumnDeclaration>())
|
2019-01-20 09:19:34 +00:00
|
|
|
columns->children.push_back(elem);
|
2019-03-11 13:22:51 +00:00
|
|
|
else if (elem->as<ASTIndexDeclaration>())
|
2019-01-20 09:19:34 +00:00
|
|
|
indices->children.push_back(elem);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto res = std::make_shared<ASTColumns>();
|
|
|
|
|
|
|
|
if (!columns->children.empty())
|
|
|
|
res->set(res->columns, columns);
|
|
|
|
if (!indices->children.empty())
|
|
|
|
res->set(res->indices, indices);
|
|
|
|
|
|
|
|
node = res;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-17 18:49:43 +00:00
|
|
|
bool ParserStorage::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2011-11-01 15:16:04 +00:00
|
|
|
{
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_engine("ENGINE");
|
2017-07-10 03:28:12 +00:00
|
|
|
ParserToken s_eq(TokenType::Equals);
|
2017-09-18 14:18:29 +00:00
|
|
|
ParserKeyword s_partition_by("PARTITION BY");
|
2018-10-10 18:24:11 +00:00
|
|
|
ParserKeyword s_primary_key("PRIMARY KEY");
|
2017-09-18 14:18:29 +00:00
|
|
|
ParserKeyword s_order_by("ORDER BY");
|
|
|
|
ParserKeyword s_sample_by("SAMPLE BY");
|
2019-04-15 09:30:45 +00:00
|
|
|
ParserKeyword s_ttl("TTL");
|
2017-09-18 14:18:29 +00:00
|
|
|
ParserKeyword s_settings("SETTINGS");
|
2011-11-01 15:16:04 +00:00
|
|
|
|
2017-09-17 18:49:43 +00:00
|
|
|
ParserIdentifierWithOptionalParameters ident_with_optional_params_p;
|
2017-09-18 14:18:29 +00:00
|
|
|
ParserExpression expression_p;
|
|
|
|
ParserSetQuery settings_p(/* parse_only_internals_ = */ true);
|
2011-11-01 15:16:04 +00:00
|
|
|
|
2017-09-17 18:49:43 +00:00
|
|
|
ASTPtr engine;
|
2017-09-18 14:18:29 +00:00
|
|
|
ASTPtr partition_by;
|
2018-10-10 18:24:11 +00:00
|
|
|
ASTPtr primary_key;
|
2017-09-18 14:18:29 +00:00
|
|
|
ASTPtr order_by;
|
|
|
|
ASTPtr sample_by;
|
2019-04-15 09:30:45 +00:00
|
|
|
ASTPtr ttl_table;
|
2017-09-18 14:18:29 +00:00
|
|
|
ASTPtr settings;
|
2017-09-17 18:49:43 +00:00
|
|
|
|
|
|
|
if (!s_engine.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
s_eq.ignore(pos, expected);
|
|
|
|
|
|
|
|
if (!ident_with_optional_params_p.parse(pos, engine, expected))
|
|
|
|
return false;
|
2011-11-01 15:16:04 +00:00
|
|
|
|
2017-09-18 14:18:29 +00:00
|
|
|
while (true)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-09-18 14:18:29 +00:00
|
|
|
if (!partition_by && s_partition_by.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (expression_p.parse(pos, partition_by, expected))
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-01 15:16:04 +00:00
|
|
|
|
2018-10-10 18:24:11 +00:00
|
|
|
if (!primary_key && s_primary_key.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (expression_p.parse(pos, primary_key, expected))
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-18 14:18:29 +00:00
|
|
|
if (!order_by && s_order_by.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (expression_p.parse(pos, order_by, expected))
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sample_by && s_sample_by.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (expression_p.parse(pos, sample_by, expected))
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-15 09:30:45 +00:00
|
|
|
if (!ttl_table && s_ttl.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (expression_p.parse(pos, ttl_table, expected))
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-18 14:18:29 +00:00
|
|
|
if (s_settings.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!settings_p.parse(pos, settings, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2011-11-01 15:16:04 +00:00
|
|
|
|
2018-02-26 03:37:08 +00:00
|
|
|
auto storage = std::make_shared<ASTStorage>();
|
2017-09-17 18:49:43 +00:00
|
|
|
storage->set(storage->engine, engine);
|
2017-09-18 14:18:29 +00:00
|
|
|
storage->set(storage->partition_by, partition_by);
|
2018-10-10 18:24:11 +00:00
|
|
|
storage->set(storage->primary_key, primary_key);
|
2017-09-18 14:18:29 +00:00
|
|
|
storage->set(storage->order_by, order_by);
|
|
|
|
storage->set(storage->sample_by, sample_by);
|
2019-04-15 09:30:45 +00:00
|
|
|
storage->set(storage->ttl_table, ttl_table);
|
2018-12-25 18:45:08 +00:00
|
|
|
|
2017-09-18 14:18:29 +00:00
|
|
|
storage->set(storage->settings, settings);
|
2017-09-17 18:49:43 +00:00
|
|
|
|
|
|
|
node = storage;
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2011-11-01 15:16:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserCreateQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2011-08-18 18:48:00 +00:00
|
|
|
{
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_create("CREATE");
|
|
|
|
ParserKeyword s_temporary("TEMPORARY");
|
|
|
|
ParserKeyword s_attach("ATTACH");
|
|
|
|
ParserKeyword s_table("TABLE");
|
|
|
|
ParserKeyword s_database("DATABASE");
|
|
|
|
ParserKeyword s_if_not_exists("IF NOT EXISTS");
|
|
|
|
ParserKeyword s_as("AS");
|
|
|
|
ParserKeyword s_view("VIEW");
|
|
|
|
ParserKeyword s_materialized("MATERIALIZED");
|
|
|
|
ParserKeyword s_populate("POPULATE");
|
2019-03-11 16:50:31 +00:00
|
|
|
ParserKeyword s_or_replace("OR REPLACE");
|
2017-07-10 03:28:12 +00:00
|
|
|
ParserToken s_dot(TokenType::Dot);
|
|
|
|
ParserToken s_lparen(TokenType::OpeningRoundBracket);
|
|
|
|
ParserToken s_rparen(TokenType::ClosingRoundBracket);
|
2017-09-17 18:49:43 +00:00
|
|
|
ParserStorage storage_p;
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserIdentifier name_p;
|
2019-01-20 11:03:21 +00:00
|
|
|
ParserColumnsOrIndicesDeclarationList columns_or_indices_p;
|
2018-02-25 00:50:53 +00:00
|
|
|
ParserSelectWithUnionQuery select_p;
|
2019-07-18 18:29:49 +00:00
|
|
|
ParserFunction table_function_p;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
ASTPtr database;
|
|
|
|
ASTPtr table;
|
2019-01-21 17:17:21 +00:00
|
|
|
ASTPtr columns_list;
|
2017-10-30 17:53:01 +00:00
|
|
|
ASTPtr to_database;
|
|
|
|
ASTPtr to_table;
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr storage;
|
|
|
|
ASTPtr as_database;
|
|
|
|
ASTPtr as_table;
|
2019-07-18 18:29:49 +00:00
|
|
|
ASTPtr as_table_function;
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr select;
|
2017-04-21 12:39:28 +00:00
|
|
|
String cluster_str;
|
2017-04-01 07:20:54 +00:00
|
|
|
bool attach = false;
|
|
|
|
bool if_not_exists = false;
|
|
|
|
bool is_view = false;
|
|
|
|
bool is_materialized_view = false;
|
|
|
|
bool is_populate = false;
|
|
|
|
bool is_temporary = false;
|
2019-03-11 16:50:31 +00:00
|
|
|
bool replace_view = false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!s_create.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_attach.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
attach = true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_temporary.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
is_temporary = true;
|
|
|
|
}
|
|
|
|
|
2017-10-25 19:52:32 +00:00
|
|
|
if (s_table.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_if_not_exists.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
if_not_exists = true;
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!name_p.parse(pos, table, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_dot.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
database = table;
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!name_p.parse(pos, table, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (ParserKeyword{"ON"}.ignore(pos, expected))
|
2017-04-13 13:42:29 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected))
|
2017-04-13 13:42:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-21 20:38:39 +00:00
|
|
|
// Shortcut for ATTACH a previously detached table
|
|
|
|
if (attach && (!pos.isValid() || pos.get().type == TokenType::Semicolon))
|
|
|
|
{
|
2018-02-26 03:37:08 +00:00
|
|
|
auto query = std::make_shared<ASTCreateQuery>();
|
2017-10-21 20:38:39 +00:00
|
|
|
node = query;
|
|
|
|
|
|
|
|
query->attach = attach;
|
|
|
|
query->if_not_exists = if_not_exists;
|
2018-09-03 14:06:00 +00:00
|
|
|
query->cluster = cluster_str;
|
2017-10-21 20:38:39 +00:00
|
|
|
|
2019-01-14 18:15:04 +00:00
|
|
|
getIdentifierName(database, query->database);
|
|
|
|
getIdentifierName(table, query->table);
|
2017-10-21 20:38:39 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-13 13:42:29 +00:00
|
|
|
/// List of columns.
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_lparen.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-01-21 17:17:21 +00:00
|
|
|
if (!columns_or_indices_p.parse(pos, columns_list, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!s_rparen.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
|
2017-09-17 18:49:43 +00:00
|
|
|
if (!storage_p.parse(pos, storage, expected) && !is_temporary)
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-17 18:49:43 +00:00
|
|
|
storage_p.parse(pos, storage, expected);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!s_as.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
|
2019-07-18 18:29:49 +00:00
|
|
|
if (!table_function_p.parse(pos, as_table_function, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-07-18 18:29:49 +00:00
|
|
|
if (!select_p.parse(pos, select, expected)) /// AS SELECT ...
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-07-18 18:29:49 +00:00
|
|
|
/// AS [db.]table
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!name_p.parse(pos, as_table, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
|
2019-07-18 18:29:49 +00:00
|
|
|
if (s_dot.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
as_database = as_table;
|
|
|
|
if (!name_p.parse(pos, as_table, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Optional - ENGINE can be specified.
|
|
|
|
if (!storage)
|
|
|
|
storage_p.parse(pos, storage, expected);
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-25 19:52:32 +00:00
|
|
|
else if (is_temporary)
|
|
|
|
return false;
|
|
|
|
else if (s_database.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (s_if_not_exists.ignore(pos, expected))
|
|
|
|
if_not_exists = true;
|
|
|
|
|
|
|
|
if (!name_p.parse(pos, database, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (ParserKeyword{"ON"}.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
storage_p.parse(pos, storage, expected);
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/// VIEW or MATERIALIZED VIEW
|
2019-03-11 16:50:31 +00:00
|
|
|
if (s_or_replace.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
replace_view = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!replace_view && s_materialized.ignore(pos, expected))
|
2017-06-29 22:00:51 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
is_materialized_view = true;
|
2017-06-29 22:00:51 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
else
|
|
|
|
is_view = true;
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!s_view.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
|
2019-03-11 16:50:31 +00:00
|
|
|
if (!replace_view && s_if_not_exists.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
if_not_exists = true;
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!name_p.parse(pos, table, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2017-06-29 22:00:51 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_dot.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
database = table;
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!name_p.parse(pos, table, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2017-08-02 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ParserKeyword{"ON"}.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected))
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2017-10-21 20:08:49 +00:00
|
|
|
// TO [db.]table
|
|
|
|
if (ParserKeyword{"TO"}.ignore(pos, expected))
|
|
|
|
{
|
2017-10-30 17:53:01 +00:00
|
|
|
if (!name_p.parse(pos, to_table, expected))
|
2017-10-21 20:08:49 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (s_dot.ignore(pos, expected))
|
|
|
|
{
|
2017-10-30 17:53:01 +00:00
|
|
|
to_database = to_table;
|
|
|
|
if (!name_p.parse(pos, to_table, expected))
|
2017-10-21 20:08:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-02 17:37:49 +00:00
|
|
|
/// Optional - a list of columns can be specified. It must fully comply with SELECT.
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_lparen.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-01-21 17:17:21 +00:00
|
|
|
if (!columns_or_indices_p.parse(pos, columns_list, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!s_rparen.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-27 20:21:27 +00:00
|
|
|
if (is_materialized_view && !to_table)
|
2017-10-25 19:52:32 +00:00
|
|
|
{
|
|
|
|
/// Internal ENGINE for MATERIALIZED VIEW must be specified.
|
|
|
|
if (!storage_p.parse(pos, storage, expected))
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-10-25 19:52:32 +00:00
|
|
|
if (s_populate.ignore(pos, expected))
|
|
|
|
is_populate = true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// AS SELECT ...
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!s_as.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2017-08-18 20:56:19 +00:00
|
|
|
|
|
|
|
if (!select_p.parse(pos, select, expected))
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-26 03:37:08 +00:00
|
|
|
auto query = std::make_shared<ASTCreateQuery>();
|
2017-04-01 07:20:54 +00:00
|
|
|
node = query;
|
|
|
|
|
2019-07-18 18:29:49 +00:00
|
|
|
if (as_table_function)
|
|
|
|
query->as_table_function = as_table_function;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
query->attach = attach;
|
|
|
|
query->if_not_exists = if_not_exists;
|
|
|
|
query->is_view = is_view;
|
|
|
|
query->is_materialized_view = is_materialized_view;
|
|
|
|
query->is_populate = is_populate;
|
2018-10-18 15:03:14 +00:00
|
|
|
query->temporary = is_temporary;
|
2019-03-11 16:50:31 +00:00
|
|
|
query->replace_view = replace_view;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-01-14 18:15:04 +00:00
|
|
|
getIdentifierName(database, query->database);
|
|
|
|
getIdentifierName(table, query->table);
|
2017-04-21 12:39:28 +00:00
|
|
|
query->cluster = cluster_str;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-01-14 18:15:04 +00:00
|
|
|
getIdentifierName(to_database, query->to_database);
|
|
|
|
getIdentifierName(to_table, query->to_table);
|
2017-10-30 17:53:01 +00:00
|
|
|
|
2019-01-21 17:17:21 +00:00
|
|
|
query->set(query->columns_list, columns_list);
|
2017-09-17 18:49:43 +00:00
|
|
|
query->set(query->storage, storage);
|
2019-01-14 18:15:04 +00:00
|
|
|
|
|
|
|
getIdentifierName(as_database, query->as_database);
|
|
|
|
getIdentifierName(as_table, query->as_table);
|
2017-09-17 18:49:43 +00:00
|
|
|
query->set(query->select, select);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
return true;
|
2011-08-18 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|