Allow SHOW COLUMNS to work with tables that contain dots in the name

This commit is contained in:
Salvatore Mesoraca 2024-09-11 14:37:24 +02:00
parent 7a3d69b626
commit 075a85f15c

View File

@ -1,6 +1,6 @@
#include <Parsers/ParserShowColumnsQuery.h>
#include <Parsers/ASTIdentifier_fwd.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTShowColumnsQuery.h>
#include <Parsers/CommonParsers.h>
@ -18,7 +18,6 @@ bool ParserShowColumnsQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
ASTPtr from1;
ASTPtr from2;
String from1_str;
String from2_str;
auto query = std::make_shared<ASTShowColumnsQuery>();
@ -43,25 +42,18 @@ bool ParserShowColumnsQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
else
return false;
tryGetIdentifierNameInto(from1, from1_str);
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];
}
const auto * table_id = from1->as<ASTIdentifier>();
if (!table_id)
return false;
query->table = table_id->shortName();
if (table_id->compound())
query->database = table_id->name_parts[0];
else
{
if (ParserKeyword(Keyword::FROM).ignore(pos, expected) || ParserKeyword(Keyword::IN).ignore(pos, expected))
if (!ParserIdentifier().parse(pos, from2, expected))
return false;
tryGetIdentifierNameInto(from2, from2_str);
query->table = from1_str;
query->database = from2_str;
}