mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-19 16:20:50 +00:00
Merge pull request #69514 from aiven-sal/aiven-sal/showcolumns
Correctly handle tables' names with dots in SHOW COLUMNS and SHOW INDEX
This commit is contained in:
commit
e0c4a88f98
@ -1,6 +1,6 @@
|
|||||||
#include <Parsers/ParserShowColumnsQuery.h>
|
#include <Parsers/ParserShowColumnsQuery.h>
|
||||||
|
|
||||||
#include <Parsers/ASTIdentifier_fwd.h>
|
#include <Parsers/ASTIdentifier.h>
|
||||||
#include <Parsers/ASTLiteral.h>
|
#include <Parsers/ASTLiteral.h>
|
||||||
#include <Parsers/ASTShowColumnsQuery.h>
|
#include <Parsers/ASTShowColumnsQuery.h>
|
||||||
#include <Parsers/CommonParsers.h>
|
#include <Parsers/CommonParsers.h>
|
||||||
@ -18,7 +18,6 @@ bool ParserShowColumnsQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
|
|||||||
ASTPtr from1;
|
ASTPtr from1;
|
||||||
ASTPtr from2;
|
ASTPtr from2;
|
||||||
|
|
||||||
String from1_str;
|
|
||||||
String from2_str;
|
String from2_str;
|
||||||
|
|
||||||
auto query = std::make_shared<ASTShowColumnsQuery>();
|
auto query = std::make_shared<ASTShowColumnsQuery>();
|
||||||
@ -43,25 +42,18 @@ bool ParserShowColumnsQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
|
|||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
tryGetIdentifierNameInto(from1, from1_str);
|
const auto * table_id = from1->as<ASTIdentifier>();
|
||||||
|
if (!table_id)
|
||||||
bool abbreviated_form = from1_str.contains("."); // FROM database.table
|
return false;
|
||||||
if (abbreviated_form)
|
query->table = table_id->shortName();
|
||||||
{
|
if (table_id->compound())
|
||||||
std::vector<String> split;
|
query->database = table_id->name_parts[0];
|
||||||
boost::split(split, from1_str, boost::is_any_of("."));
|
|
||||||
query->database = split[0];
|
|
||||||
query->table = split[1];
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ParserKeyword(Keyword::FROM).ignore(pos, expected) || ParserKeyword(Keyword::IN).ignore(pos, expected))
|
if (ParserKeyword(Keyword::FROM).ignore(pos, expected) || ParserKeyword(Keyword::IN).ignore(pos, expected))
|
||||||
if (!ParserIdentifier().parse(pos, from2, expected))
|
if (!ParserIdentifier().parse(pos, from2, expected))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
tryGetIdentifierNameInto(from2, from2_str);
|
tryGetIdentifierNameInto(from2, from2_str);
|
||||||
|
|
||||||
query->table = from1_str;
|
|
||||||
query->database = from2_str;
|
query->database = from2_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include <Parsers/ParserShowIndexesQuery.h>
|
#include <Parsers/ParserShowIndexesQuery.h>
|
||||||
|
|
||||||
#include <Parsers/ASTIdentifier_fwd.h>
|
#include <Parsers/ASTIdentifier.h>
|
||||||
#include <Parsers/ASTLiteral.h>
|
#include <Parsers/ASTLiteral.h>
|
||||||
#include <Parsers/ASTShowIndexesQuery.h>
|
#include <Parsers/ASTShowIndexesQuery.h>
|
||||||
#include <Parsers/CommonParsers.h>
|
#include <Parsers/CommonParsers.h>
|
||||||
@ -17,7 +17,6 @@ bool ParserShowIndexesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
|
|||||||
ASTPtr from1;
|
ASTPtr from1;
|
||||||
ASTPtr from2;
|
ASTPtr from2;
|
||||||
|
|
||||||
String from1_str;
|
|
||||||
String from2_str;
|
String from2_str;
|
||||||
|
|
||||||
auto query = std::make_shared<ASTShowIndexesQuery>();
|
auto query = std::make_shared<ASTShowIndexesQuery>();
|
||||||
@ -39,25 +38,18 @@ bool ParserShowIndexesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
|
|||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
tryGetIdentifierNameInto(from1, from1_str);
|
const auto * table_id = from1->as<ASTIdentifier>();
|
||||||
|
if (!table_id)
|
||||||
bool abbreviated_form = from1_str.contains("."); // FROM database.table
|
return false;
|
||||||
if (abbreviated_form)
|
query->table = table_id->shortName();
|
||||||
{
|
if (table_id->compound())
|
||||||
std::vector<String> split;
|
query->database = table_id->name_parts[0];
|
||||||
boost::split(split, from1_str, boost::is_any_of("."));
|
|
||||||
query->database = split[0];
|
|
||||||
query->table = split[1];
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ParserKeyword(Keyword::FROM).ignore(pos, expected) || ParserKeyword(Keyword::IN).ignore(pos, expected))
|
if (ParserKeyword(Keyword::FROM).ignore(pos, expected) || ParserKeyword(Keyword::IN).ignore(pos, expected))
|
||||||
if (!ParserIdentifier().parse(pos, from2, expected))
|
if (!ParserIdentifier().parse(pos, from2, expected))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
tryGetIdentifierNameInto(from2, from2_str);
|
tryGetIdentifierNameInto(from2, from2_str);
|
||||||
|
|
||||||
query->table = from1_str;
|
|
||||||
query->database = from2_str;
|
query->database = from2_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,3 +45,7 @@ uint64 UInt64 NO PRI SOR \N
|
|||||||
int32 Int32 NO \N
|
int32 Int32 NO \N
|
||||||
str String NO \N
|
str String NO \N
|
||||||
uint64 UInt64 NO PRI SOR \N
|
uint64 UInt64 NO PRI SOR \N
|
||||||
|
--- SHOW COLUMNS FROM table with dots
|
||||||
|
int32 Nullable(Int32) YES \N
|
||||||
|
str String NO SOR \N
|
||||||
|
uint64 UInt64 NO PRI SOR \N
|
||||||
|
@ -90,3 +90,18 @@ SHOW COLUMNS FROM database_123456789abcde.tab;
|
|||||||
DROP DATABASE database_123456789abcde;
|
DROP DATABASE database_123456789abcde;
|
||||||
|
|
||||||
DROP TABLE tab;
|
DROP TABLE tab;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `tab.with.dots`;
|
||||||
|
CREATE TABLE `tab.with.dots`
|
||||||
|
(
|
||||||
|
`uint64` UInt64,
|
||||||
|
`int32` Nullable(Int32) COMMENT 'example comment',
|
||||||
|
`str` String,
|
||||||
|
INDEX idx str TYPE set(1000)
|
||||||
|
)
|
||||||
|
ENGINE = MergeTree
|
||||||
|
PRIMARY KEY (uint64)
|
||||||
|
ORDER BY (uint64, str);
|
||||||
|
SELECT '--- SHOW COLUMNS FROM table with dots';
|
||||||
|
SHOW COLUMNS FROM `tab.with.dots`;
|
||||||
|
DROP TABLE `tab.with.dots`;
|
||||||
|
@ -49,3 +49,10 @@ tbl 1 PRIMARY 1 a A 0 \N \N \N PRIMARY YES
|
|||||||
--- Short form
|
--- Short form
|
||||||
tbl 1 mmi_idx 1 \N 0 \N \N \N MINMAX YES b
|
tbl 1 mmi_idx 1 \N 0 \N \N \N MINMAX YES b
|
||||||
tbl 1 PRIMARY 1 a A 0 \N \N \N PRIMARY YES
|
tbl 1 PRIMARY 1 a A 0 \N \N \N PRIMARY YES
|
||||||
|
--- SHOW INDEX FROM table with dots
|
||||||
|
tab.with.dots 1 blf_idx 1 \N 0 \N \N \N BLOOM_FILTER YES d, b
|
||||||
|
tab.with.dots 1 mm1_idx 1 \N 0 \N \N \N MINMAX YES a, c, d
|
||||||
|
tab.with.dots 1 mm2_idx 1 \N 0 \N \N \N MINMAX YES c, d, e
|
||||||
|
tab.with.dots 1 PRIMARY 1 c A 0 \N \N \N PRIMARY YES
|
||||||
|
tab.with.dots 1 PRIMARY 2 a A 0 \N \N \N PRIMARY YES
|
||||||
|
tab.with.dots 1 set_idx 1 \N 0 \N \N \N SET YES e
|
||||||
|
@ -78,3 +78,22 @@ SHOW INDEX FROM database_123456789abcde.tbl;
|
|||||||
DROP DATABASE database_123456789abcde;
|
DROP DATABASE database_123456789abcde;
|
||||||
|
|
||||||
DROP TABLE tbl;
|
DROP TABLE tbl;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `tab.with.dots`;
|
||||||
|
CREATE TABLE `tab.with.dots`
|
||||||
|
(
|
||||||
|
a UInt64,
|
||||||
|
b UInt64,
|
||||||
|
c UInt64,
|
||||||
|
d UInt64,
|
||||||
|
e UInt64,
|
||||||
|
INDEX mm1_idx (a, c, d) TYPE minmax,
|
||||||
|
INDEX mm2_idx (c, d, e) TYPE minmax,
|
||||||
|
INDEX set_idx (e) TYPE set(100),
|
||||||
|
INDEX blf_idx (d, b) TYPE bloom_filter(0.8)
|
||||||
|
)
|
||||||
|
ENGINE = MergeTree
|
||||||
|
PRIMARY KEY (c, a);
|
||||||
|
SELECT '--- SHOW INDEX FROM table with dots';
|
||||||
|
SHOW INDEX FROM `tab.with.dots`;
|
||||||
|
DROP TABLE `tab.with.dots`;
|
||||||
|
Loading…
Reference in New Issue
Block a user