mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #11467 from hexiaoting/showcreate
Add "SHOW CLUSTER(s)" queries support
This commit is contained in:
commit
1777bd0273
@ -33,6 +33,32 @@ String InterpreterShowTablesQuery::getRewrittenQuery()
|
||||
if (query.databases)
|
||||
return "SELECT name FROM system.databases";
|
||||
|
||||
/// SHOW CLUSTER/CLUSTERS
|
||||
if (query.clusters)
|
||||
{
|
||||
std::stringstream rewritten_query;
|
||||
rewritten_query << "SELECT DISTINCT cluster FROM system.clusters";
|
||||
|
||||
if (!query.like.empty())
|
||||
{
|
||||
rewritten_query << " WHERE cluster " << (query.not_like ? "NOT " : "") << "LIKE " << std::quoted(query.like, '\'');
|
||||
}
|
||||
|
||||
if (query.limit_length)
|
||||
rewritten_query << " LIMIT " << query.limit_length;
|
||||
|
||||
return rewritten_query.str();
|
||||
}
|
||||
else if (query.cluster)
|
||||
{
|
||||
std::stringstream rewritten_query;
|
||||
rewritten_query << "SELECT * FROM system.clusters";
|
||||
|
||||
rewritten_query << " WHERE cluster = " << std::quoted(query.cluster_str, '\'');
|
||||
|
||||
return rewritten_query.str();
|
||||
}
|
||||
|
||||
if (query.temporary && !query.from.empty())
|
||||
throw Exception("The `FROM` and `TEMPORARY` cannot be used together in `SHOW TABLES`", ErrorCodes::SYNTAX_ERROR);
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include <Parsers/ASTShowTablesQuery.h>
|
||||
#include <Common/quoteString.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
@ -20,6 +19,24 @@ void ASTShowTablesQuery::formatQueryImpl(const FormatSettings & settings, Format
|
||||
{
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW DATABASES" << (settings.hilite ? hilite_none : "");
|
||||
}
|
||||
else if (clusters)
|
||||
{
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW CLUSTERS" << (settings.hilite ? hilite_none : "");
|
||||
if (!like.empty())
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << (not_like ? " NOT" : "") << " LIKE " << (settings.hilite ? hilite_none : "")
|
||||
<< std::quoted(like, '\'');
|
||||
|
||||
if (limit_length)
|
||||
{
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << " LIMIT " << (settings.hilite ? hilite_none : "");
|
||||
limit_length->formatImpl(settings, state, frame);
|
||||
}
|
||||
}
|
||||
else if (cluster)
|
||||
{
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW CLUSTER" << (settings.hilite ? hilite_none : "");
|
||||
settings.ostr << " " << backQuoteIfNeed(cluster_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW " << (temporary ? "TEMPORARY " : "") <<
|
||||
|
@ -9,14 +9,17 @@ namespace DB
|
||||
{
|
||||
|
||||
|
||||
/** Query SHOW TABLES or SHOW DATABASES
|
||||
/** Query SHOW TABLES or SHOW DATABASES or SHOW CLUSTERS
|
||||
*/
|
||||
class ASTShowTablesQuery : public ASTQueryWithOutput
|
||||
{
|
||||
public:
|
||||
bool databases{false};
|
||||
bool clusters{false};
|
||||
bool cluster{false};
|
||||
bool dictionaries{false};
|
||||
bool temporary{false};
|
||||
String cluster_str;
|
||||
String from;
|
||||
String like;
|
||||
bool not_like{false};
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <Parsers/ParserShowTablesQuery.h>
|
||||
#include <Parsers/ExpressionElementParsers.h>
|
||||
#include <Parsers/ExpressionListParsers.h>
|
||||
#include <Parsers/parseIdentifierOrStringLiteral.h>
|
||||
|
||||
#include <Common/typeid_cast.h>
|
||||
|
||||
@ -20,6 +21,8 @@ bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
|
||||
ParserKeyword s_temporary("TEMPORARY");
|
||||
ParserKeyword s_tables("TABLES");
|
||||
ParserKeyword s_databases("DATABASES");
|
||||
ParserKeyword s_clusters("CLUSTERS");
|
||||
ParserKeyword s_cluster("CLUSTER");
|
||||
ParserKeyword s_dictionaries("DICTIONARIES");
|
||||
ParserKeyword s_from("FROM");
|
||||
ParserKeyword s_in("IN");
|
||||
@ -43,6 +46,36 @@ bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
|
||||
{
|
||||
query->databases = true;
|
||||
}
|
||||
else if (s_clusters.ignore(pos))
|
||||
{
|
||||
query->clusters = true;
|
||||
|
||||
if (s_not.ignore(pos, expected))
|
||||
query->not_like = true;
|
||||
|
||||
if (s_like.ignore(pos, expected))
|
||||
{
|
||||
if (!like_p.parse(pos, like, expected))
|
||||
return false;
|
||||
}
|
||||
else if (query->not_like)
|
||||
return false;
|
||||
if (s_limit.ignore(pos, expected))
|
||||
{
|
||||
if (!exp_elem.parse(pos, query->limit_length, expected))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (s_cluster.ignore(pos))
|
||||
{
|
||||
query->cluster = true;
|
||||
|
||||
String cluster_str;
|
||||
if (!parseIdentifierOrStringLiteral(pos, expected, cluster_str))
|
||||
return false;
|
||||
|
||||
query->cluster_str = std::move(cluster_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_temporary.ignore(pos))
|
||||
|
@ -14,7 +14,7 @@ namespace DB
|
||||
class ParserShowTablesQuery : public IParserBase
|
||||
{
|
||||
protected:
|
||||
const char * getName() const override { return "SHOW [TEMPORARY] TABLES|DATABASES [[NOT] LIKE 'str'] [LIMIT expr]"; }
|
||||
const char * getName() const override { return "SHOW [TEMPORARY] TABLES|DATABASES|CLUSTERS|CLUSTER 'name' [[NOT] LIKE 'str'] [LIMIT expr]"; }
|
||||
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
||||
};
|
||||
|
||||
|
8
tests/queries/0_stateless/01293_show_clusters.reference
Normal file
8
tests/queries/0_stateless/01293_show_clusters.reference
Normal file
@ -0,0 +1,8 @@
|
||||
test_cluster_two_shards
|
||||
test_cluster_two_shards_different_databases
|
||||
test_cluster_two_shards_localhost
|
||||
test_shard_localhost
|
||||
test_shard_localhost_secure
|
||||
test_unavailable_shard
|
||||
test_cluster_two_shards
|
||||
test_shard_localhost 1 1 1 localhost ::1 9000 1 default 0 0
|
3
tests/queries/0_stateless/01293_show_clusters.sql
Normal file
3
tests/queries/0_stateless/01293_show_clusters.sql
Normal file
@ -0,0 +1,3 @@
|
||||
show clusters;
|
||||
show clusters like 'test%' limit 1;
|
||||
show cluster 'test_shard_localhost';
|
Loading…
Reference in New Issue
Block a user