2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ParserOptimizeQuery.h>
|
2017-09-06 20:34:26 +00:00
|
|
|
#include <Parsers/ParserPartition.h>
|
|
|
|
#include <Parsers/CommonParsers.h>
|
|
|
|
|
|
|
|
#include <Parsers/ASTOptimizeQuery.h>
|
|
|
|
#include <Parsers/ASTIdentifier.h>
|
2012-07-31 19:08:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserOptimizeQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2012-07-31 19:08:49 +00:00
|
|
|
{
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_optimize_table("OPTIMIZE TABLE");
|
|
|
|
ParserKeyword s_partition("PARTITION");
|
|
|
|
ParserKeyword s_final("FINAL");
|
|
|
|
ParserKeyword s_deduplicate("DEDUPLICATE");
|
2017-07-10 03:28:12 +00:00
|
|
|
ParserToken s_dot(TokenType::Dot);
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserIdentifier name_p;
|
2017-09-06 20:34:26 +00:00
|
|
|
ParserPartition partition_p;
|
2012-07-31 19:08:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr database;
|
|
|
|
ASTPtr table;
|
|
|
|
ASTPtr partition;
|
|
|
|
bool final = false;
|
2017-04-13 13:13:08 +00:00
|
|
|
bool deduplicate = false;
|
2018-07-20 05:46:48 +00:00
|
|
|
String cluster_str;
|
2012-07-31 19:08:49 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!s_optimize_table.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2012-07-31 19:08:49 +00:00
|
|
|
|
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;
|
2012-07-31 19:08:49 +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;
|
|
|
|
}
|
2012-07-31 19:08:49 +00:00
|
|
|
|
2018-07-20 05:46:48 +00:00
|
|
|
if (ParserKeyword{"ON"}.ignore(pos, expected) && !ASTQueryWithOnCluster::parse(pos, cluster_str, expected))
|
|
|
|
return false;
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_partition.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!partition_p.parse(pos, partition, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 18:43:38 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_final.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
final = true;
|
2016-05-16 18:43:38 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_deduplicate.ignore(pos, expected))
|
2017-04-13 13:13:08 +00:00
|
|
|
deduplicate = true;
|
|
|
|
|
2018-02-26 03:37:08 +00:00
|
|
|
auto query = std::make_shared<ASTOptimizeQuery>();
|
2017-04-01 07:20:54 +00:00
|
|
|
node = query;
|
2012-07-31 19:08:49 +00:00
|
|
|
|
2019-08-08 20:27:12 +00:00
|
|
|
tryGetIdentifierNameInto(database, query->database);
|
|
|
|
tryGetIdentifierNameInto(table, query->table);
|
2018-07-20 05:46:48 +00:00
|
|
|
|
|
|
|
query->cluster = cluster_str;
|
2020-12-04 02:15:44 +00:00
|
|
|
if ((query->partition = partition))
|
|
|
|
query->children.push_back(partition);
|
2017-04-01 07:20:54 +00:00
|
|
|
query->final = final;
|
2017-04-13 13:13:08 +00:00
|
|
|
query->deduplicate = deduplicate;
|
2012-07-31 19:08:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2012-07-31 19:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|