ClickHouse/src/Parsers/ParserCheckQuery.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
1.9 KiB
C++
Raw Normal View History

#include <Parsers/ParserCheckQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ExpressionElementParsers.h>
#include <Parsers/ASTCheckQuery.h>
2023-10-23 12:13:36 +00:00
#include <Parsers/ASTLiteral.h>
2019-07-03 13:17:19 +00:00
#include <Parsers/ParserPartition.h>
#include <Parsers/parseDatabaseAndTableName.h>
2014-08-05 10:52:06 +00:00
2016-11-20 12:43:20 +00:00
namespace DB
{
2014-08-05 10:52:06 +00:00
bool ParserCheckQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
2023-10-24 12:50:24 +00:00
{
ParserKeyword s_check_table("CHECK ALL TABLES");
if (s_check_table.ignore(pos, expected))
{
auto query = std::make_shared<ASTCheckAllTablesQuery>();
node = query;
return true;
}
return parseCheckTable(pos, node, expected);
}
bool ParserCheckQuery::parseCheckTable(Pos & pos, ASTPtr & node, Expected & expected)
2014-08-05 10:52:06 +00:00
{
ParserKeyword s_check_table("CHECK TABLE");
2019-07-03 13:17:19 +00:00
ParserKeyword s_partition("PARTITION");
2023-10-23 12:13:36 +00:00
ParserKeyword s_part("PART");
ParserToken s_dot(TokenType::Dot);
2014-08-05 10:52:06 +00:00
2019-07-03 13:17:19 +00:00
ParserPartition partition_parser;
2023-10-23 12:13:36 +00:00
ParserStringLiteral parser_string_literal;
2014-08-05 10:52:06 +00:00
if (!s_check_table.ignore(pos, expected))
2014-08-05 10:52:06 +00:00
return false;
2023-10-24 12:50:24 +00:00
auto query = std::make_shared<ASTCheckTableQuery>();
2014-08-05 10:52:06 +00:00
2021-11-16 08:58:28 +00:00
if (!parseDatabaseAndTableAsAST(pos, expected, query->database, query->table))
return false;
2014-08-05 10:52:06 +00:00
2019-07-03 13:17:19 +00:00
if (s_partition.ignore(pos, expected))
{
if (!partition_parser.parse(pos, query->partition, expected))
return false;
}
2023-10-23 12:13:36 +00:00
else if (s_part.ignore(pos, expected))
{
ASTPtr ast_part_name;
if (!parser_string_literal.parse(pos, ast_part_name, expected))
return false;
const auto * ast_literal = ast_part_name->as<ASTLiteral>();
if (!ast_literal || ast_literal->value.getType() != Field::Types::String)
return false;
query->part_name = ast_literal->value.get<const String &>();
}
2019-07-03 13:17:19 +00:00
if (query->database)
query->children.push_back(query->database);
if (query->table)
query->children.push_back(query->table);
2019-07-03 13:17:19 +00:00
node = query;
2014-08-05 10:52:06 +00:00
return true;
}
2016-11-20 12:43:20 +00:00
}