2012-07-31 19:08:49 +00:00
|
|
|
#include <DB/Parsers/ASTIdentifier.h>
|
|
|
|
#include <DB/Parsers/ASTOptimizeQuery.h>
|
|
|
|
|
|
|
|
#include <DB/Parsers/CommonParsers.h>
|
|
|
|
#include <DB/Parsers/ParserOptimizeQuery.h>
|
2016-05-16 18:43:38 +00:00
|
|
|
#include <DB/Parsers/ASTLiteral.h>
|
2012-07-31 19:08:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
bool ParserOptimizeQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
|
2012-07-31 19:08:49 +00:00
|
|
|
{
|
|
|
|
Pos begin = pos;
|
|
|
|
|
|
|
|
ParserWhiteSpaceOrComments ws;
|
|
|
|
ParserString s_optimize("OPTIMIZE", true, true);
|
|
|
|
ParserString s_table("TABLE", true, true);
|
2016-05-16 18:43:38 +00:00
|
|
|
ParserString s_partition("PARTITION", true, true);
|
|
|
|
ParserString s_final("FINAL", true, true);
|
2012-07-31 19:08:49 +00:00
|
|
|
ParserString s_dot(".");
|
|
|
|
ParserIdentifier name_p;
|
2016-05-16 18:43:38 +00:00
|
|
|
ParserLiteral partition_p;
|
2012-07-31 19:08:49 +00:00
|
|
|
|
|
|
|
ASTPtr database;
|
|
|
|
ASTPtr table;
|
2016-05-16 18:43:38 +00:00
|
|
|
ASTPtr partition;
|
|
|
|
bool final = false;
|
2012-07-31 19:08:49 +00:00
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!s_optimize.ignore(pos, end, max_parsed_pos, expected))
|
2012-07-31 19:08:49 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!s_table.ignore(pos, end, max_parsed_pos, expected))
|
2012-07-31 19:08:49 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!name_p.parse(pos, end, table, max_parsed_pos, expected))
|
2012-07-31 19:08:49 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (s_dot.ignore(pos, end, max_parsed_pos, expected))
|
2012-07-31 19:08:49 +00:00
|
|
|
{
|
|
|
|
database = table;
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!name_p.parse(pos, end, table, max_parsed_pos, expected))
|
2012-07-31 19:08:49 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2016-05-16 18:43:38 +00:00
|
|
|
if (s_partition.ignore(pos, end, max_parsed_pos, expected))
|
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (!partition_p.parse(pos, end, partition, max_parsed_pos, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (s_final.ignore(pos, end, max_parsed_pos, expected))
|
|
|
|
final = true;
|
|
|
|
|
2016-05-28 15:42:22 +00:00
|
|
|
auto query = std::make_shared<ASTOptimizeQuery>(StringRange(begin, pos));
|
2012-07-31 19:08:49 +00:00
|
|
|
node = query;
|
|
|
|
|
|
|
|
if (database)
|
2016-05-16 18:43:38 +00:00
|
|
|
query->database = typeid_cast<const ASTIdentifier &>(*database).name;
|
2012-07-31 19:08:49 +00:00
|
|
|
if (table)
|
2016-05-16 18:43:38 +00:00
|
|
|
query->table = typeid_cast<const ASTIdentifier &>(*table).name;
|
|
|
|
if (partition)
|
|
|
|
query->partition = apply_visitor(FieldVisitorToString(), typeid_cast<const ASTLiteral &>(*partition).value);
|
|
|
|
query->final = final;
|
2012-07-31 19:08:49 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|