mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Add LIMIT clause to SHOW queries
This commit is contained in:
parent
79a206b092
commit
98050c108f
@ -1,5 +1,6 @@
|
||||
#include <IO/ReadBufferFromString.h>
|
||||
#include <Parsers/ASTShowTablesQuery.h>
|
||||
#include <Parsers/formatAST.h>
|
||||
#include <Interpreters/Context.h>
|
||||
#include <Interpreters/executeQuery.h>
|
||||
#include <Interpreters/InterpreterShowTablesQuery.h>
|
||||
@ -53,6 +54,9 @@ String InterpreterShowTablesQuery::getRewrittenQuery()
|
||||
if (!query.like.empty())
|
||||
rewritten_query << " AND name " << (query.not_like ? "NOT " : "") << "LIKE " << std::quoted(query.like, '\'');
|
||||
|
||||
if (query.limit_length)
|
||||
rewritten_query << " LIMIT " << query.limit_length;
|
||||
|
||||
return rewritten_query.str();
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ ASTPtr ASTShowTablesQuery::clone() const
|
||||
return res;
|
||||
}
|
||||
|
||||
void ASTShowTablesQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
|
||||
void ASTShowTablesQuery::formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
||||
{
|
||||
if (databases)
|
||||
{
|
||||
@ -30,6 +30,12 @@ void ASTShowTablesQuery::formatQueryImpl(const FormatSettings & settings, Format
|
||||
if (!like.empty())
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << " 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ public:
|
||||
String from;
|
||||
String like;
|
||||
bool not_like{false};
|
||||
ASTPtr limit_length;
|
||||
|
||||
/** Get the text that identifies this element. */
|
||||
String getID(char) const override { return "ShowTables"; }
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <Parsers/CommonParsers.h>
|
||||
#include <Parsers/ParserShowTablesQuery.h>
|
||||
#include <Parsers/ExpressionElementParsers.h>
|
||||
#include <Parsers/ExpressionListParsers.h>
|
||||
|
||||
#include <Common/typeid_cast.h>
|
||||
|
||||
@ -22,8 +23,10 @@ bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
|
||||
ParserKeyword s_from("FROM");
|
||||
ParserKeyword s_not("NOT");
|
||||
ParserKeyword s_like("LIKE");
|
||||
ParserKeyword s_limit("LIMIT");
|
||||
ParserStringLiteral like_p;
|
||||
ParserIdentifier name_p;
|
||||
ParserExpressionWithOptionalAlias limit_p(false);
|
||||
|
||||
ASTPtr like;
|
||||
ASTPtr database;
|
||||
@ -60,6 +63,12 @@ bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
|
||||
}
|
||||
else if (query->not_like)
|
||||
return false;
|
||||
|
||||
if (s_limit.ignore(pos, expected))
|
||||
{
|
||||
if (!limit_p.parse(pos, query->limit_length, expected))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
@ -7,14 +7,14 @@ namespace DB
|
||||
{
|
||||
|
||||
/** Query like this:
|
||||
* SHOW TABLES [FROM db] [[NOT] LIKE 'str']
|
||||
* SHOW TABLES [FROM db] [[NOT] LIKE 'str'] [LIMIT expr]
|
||||
* or
|
||||
* SHOW DATABASES.
|
||||
*/
|
||||
class ParserShowTablesQuery : public IParserBase
|
||||
{
|
||||
protected:
|
||||
const char * getName() const { return "SHOW [TEMPORARY] TABLES|DATABASES [[NOT] LIKE 'str']"; }
|
||||
const char * getName() const { return "SHOW [TEMPORARY] TABLES|DATABASES [[NOT] LIKE 'str'] [LIMIT expr]"; }
|
||||
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user