ClickHouse/src/Parsers/ParserShowIndexesQuery.cpp

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

75 lines
2.0 KiB
C++
Raw Normal View History

2023-04-25 18:04:19 +00:00
#include <Parsers/ParserShowIndexesQuery.h>
#include <Parsers/ASTIdentifier_fwd.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTShowIndexesQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ExpressionElementParsers.h>
#include <Parsers/ExpressionListParsers.h>
2023-05-02 12:14:17 +00:00
#include <boost/algorithm/string.hpp>
2023-04-25 18:04:19 +00:00
namespace DB
{
bool ParserShowIndexesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
2023-05-02 12:14:17 +00:00
ASTPtr from1;
ASTPtr from2;
String from1_str;
String from2_str;
2023-04-25 18:04:19 +00:00
auto query = std::make_shared<ASTShowIndexesQuery>();
if (!ParserKeyword("SHOW").ignore(pos, expected))
return false;
if (ParserKeyword("EXTENDED").ignore(pos, expected))
query->extended = true;
if (!(ParserKeyword("INDEX").ignore(pos, expected) || ParserKeyword("INDEXES").ignore(pos, expected) || ParserKeyword("KEYS").ignore(pos, expected)))
return false;
if (ParserKeyword("FROM").ignore(pos, expected) || ParserKeyword("IN").ignore(pos, expected))
{
2023-05-02 12:14:17 +00:00
if (!ParserCompoundIdentifier().parse(pos, from1, expected))
2023-04-25 18:04:19 +00:00
return false;
}
else
return false;
2023-05-02 12:14:17 +00:00
tryGetIdentifierNameInto(from1, from1_str);
2023-04-25 18:04:19 +00:00
2023-05-02 12:14:17 +00:00
bool abbreviated_form = from1_str.contains("."); // FROM database.table
if (abbreviated_form)
{
std::vector<String> split;
boost::split(split, from1_str, boost::is_any_of("."));
query->database = split[0];
query->table = split[1];
}
else
{
2023-04-25 18:04:19 +00:00
if (ParserKeyword("FROM").ignore(pos, expected) || ParserKeyword("IN").ignore(pos, expected))
2023-05-02 12:14:17 +00:00
if (!ParserIdentifier().parse(pos, from2, expected))
2023-04-25 18:04:19 +00:00
return false;
2023-05-02 12:14:17 +00:00
tryGetIdentifierNameInto(from2, from2_str);
query->table = from1_str;
2023-05-02 13:16:15 +00:00
query->database = from2_str;
2023-05-02 12:14:17 +00:00
}
2023-04-25 18:04:19 +00:00
if (ParserKeyword("WHERE").ignore(pos, expected))
if (!ParserExpressionWithOptionalAlias(false).parse(pos, query->where_expression, expected))
return false;
node = query;
return true;
}
}