2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTLiteral.h>
|
|
|
|
#include <Parsers/ASTIdentifier.h>
|
|
|
|
#include <Parsers/ASTShowTablesQuery.h>
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/CommonParsers.h>
|
|
|
|
#include <Parsers/ParserShowTablesQuery.h>
|
|
|
|
#include <Parsers/ExpressionElementParsers.h>
|
2019-09-15 16:07:27 +00:00
|
|
|
#include <Parsers/ExpressionListParsers.h>
|
2020-06-05 09:13:13 +00:00
|
|
|
#include <Parsers/parseIdentifierOrStringLiteral.h>
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2016-11-20 12:43:20 +00:00
|
|
|
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2012-06-18 07:49:19 +00:00
|
|
|
{
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_show("SHOW");
|
2018-01-25 17:50:57 +00:00
|
|
|
ParserKeyword s_temporary("TEMPORARY");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_tables("TABLES");
|
|
|
|
ParserKeyword s_databases("DATABASES");
|
2020-06-05 09:13:13 +00:00
|
|
|
ParserKeyword s_clusters("CLUSTERS");
|
|
|
|
ParserKeyword s_cluster("CLUSTER");
|
2019-10-11 13:21:52 +00:00
|
|
|
ParserKeyword s_dictionaries("DICTIONARIES");
|
2020-12-14 02:33:51 +00:00
|
|
|
ParserKeyword s_settings("SETTINGS");
|
2020-12-15 06:44:39 +00:00
|
|
|
ParserKeyword s_changed("CHANGED");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_from("FROM");
|
2020-02-11 11:35:30 +00:00
|
|
|
ParserKeyword s_in("IN");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_not("NOT");
|
|
|
|
ParserKeyword s_like("LIKE");
|
2020-07-05 15:57:59 +00:00
|
|
|
ParserKeyword s_ilike("ILIKE");
|
2020-02-11 11:35:30 +00:00
|
|
|
ParserKeyword s_where("WHERE");
|
2019-09-15 16:07:27 +00:00
|
|
|
ParserKeyword s_limit("LIMIT");
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserStringLiteral like_p;
|
|
|
|
ParserIdentifier name_p;
|
2020-02-11 11:35:30 +00:00
|
|
|
ParserExpressionWithOptionalAlias exp_elem(false);
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr like;
|
|
|
|
ASTPtr database;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
auto query = std::make_shared<ASTShowTablesQuery>();
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!s_show.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2020-12-17 04:24:36 +00:00
|
|
|
if (s_databases.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
query->databases = true;
|
2020-09-07 02:54:59 +00:00
|
|
|
|
|
|
|
if (s_not.ignore(pos, expected))
|
|
|
|
query->not_like = true;
|
|
|
|
|
|
|
|
if (bool insensitive = s_ilike.ignore(pos, expected); insensitive || s_like.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (insensitive)
|
|
|
|
query->case_insensitive_like = true;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2018-02-02 13:17:45 +00:00
|
|
|
}
|
2020-12-17 04:24:36 +00:00
|
|
|
else if (s_clusters.ignore(pos, expected))
|
2020-06-05 09:13:13 +00:00
|
|
|
{
|
|
|
|
query->clusters = true;
|
|
|
|
|
|
|
|
if (s_not.ignore(pos, expected))
|
|
|
|
query->not_like = true;
|
|
|
|
|
2020-07-05 15:57:59 +00:00
|
|
|
if (bool insensitive = s_ilike.ignore(pos, expected); insensitive || s_like.ignore(pos, expected))
|
2020-06-05 09:13:13 +00:00
|
|
|
{
|
2020-07-05 15:57:59 +00:00
|
|
|
if (insensitive)
|
|
|
|
query->case_insensitive_like = true;
|
|
|
|
|
2020-06-05 09:13:13 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2020-12-17 04:24:36 +00:00
|
|
|
else if (s_cluster.ignore(pos, expected))
|
2020-06-05 09:13:13 +00:00
|
|
|
{
|
|
|
|
query->cluster = true;
|
|
|
|
|
2020-06-08 02:29:53 +00:00
|
|
|
String cluster_str;
|
|
|
|
if (!parseIdentifierOrStringLiteral(pos, expected, cluster_str))
|
|
|
|
return false;
|
2020-06-10 18:11:30 +00:00
|
|
|
|
2020-06-08 02:29:53 +00:00
|
|
|
query->cluster_str = std::move(cluster_str);
|
2020-06-05 09:13:13 +00:00
|
|
|
}
|
2020-12-17 04:24:36 +00:00
|
|
|
else if (bool changed = s_changed.ignore(pos, expected); changed || s_settings.ignore(pos, expected))
|
2020-12-14 02:33:51 +00:00
|
|
|
{
|
|
|
|
query->m_settings = true;
|
|
|
|
|
2020-12-15 06:44:39 +00:00
|
|
|
if (changed)
|
|
|
|
{
|
|
|
|
query->changed = true;
|
|
|
|
if (!s_settings.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Not expected due to "SHOW SETTINGS PROFILES"
|
2020-12-17 04:24:36 +00:00
|
|
|
if (bool insensitive = s_ilike.ignore(pos, expected); insensitive || s_like.ignore(pos, expected))
|
2020-12-14 02:33:51 +00:00
|
|
|
{
|
|
|
|
if (insensitive)
|
|
|
|
query->case_insensitive_like = true;
|
|
|
|
|
|
|
|
if (!like_p.parse(pos, like, expected))
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-15 06:44:39 +00:00
|
|
|
else
|
|
|
|
return false;
|
2020-12-14 02:33:51 +00:00
|
|
|
}
|
2018-02-02 13:17:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (s_temporary.ignore(pos))
|
2018-01-25 17:50:57 +00:00
|
|
|
query->temporary = true;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2019-10-11 13:21:52 +00:00
|
|
|
if (!s_tables.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-10-11 13:21:52 +00:00
|
|
|
if (s_dictionaries.ignore(pos, expected))
|
|
|
|
query->dictionaries = true;
|
|
|
|
else
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2019-10-11 13:21:52 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 11:35:30 +00:00
|
|
|
if (s_from.ignore(pos, expected) || s_in.ignore(pos, expected))
|
2019-10-11 13:21:52 +00:00
|
|
|
{
|
|
|
|
if (!name_p.parse(pos, database, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s_not.ignore(pos, expected))
|
|
|
|
query->not_like = true;
|
2019-09-15 16:07:27 +00:00
|
|
|
|
2020-07-05 15:57:59 +00:00
|
|
|
if (bool insensitive = s_ilike.ignore(pos, expected); insensitive || s_like.ignore(pos, expected))
|
2019-10-11 13:21:52 +00:00
|
|
|
{
|
2020-07-05 15:57:59 +00:00
|
|
|
if (insensitive)
|
|
|
|
query->case_insensitive_like = true;
|
|
|
|
|
2019-10-11 13:21:52 +00:00
|
|
|
if (!like_p.parse(pos, like, expected))
|
|
|
|
return false;
|
2018-02-02 13:17:45 +00:00
|
|
|
}
|
2019-10-11 13:21:52 +00:00
|
|
|
else if (query->not_like)
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2020-02-11 11:35:30 +00:00
|
|
|
else if (s_where.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!exp_elem.parse(pos, query->where_expression, expected))
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-11 13:21:52 +00:00
|
|
|
|
|
|
|
if (s_limit.ignore(pos, expected))
|
|
|
|
{
|
2020-02-11 11:35:30 +00:00
|
|
|
if (!exp_elem.parse(pos, query->limit_length, expected))
|
2019-10-11 13:21:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2019-08-08 20:02:30 +00:00
|
|
|
tryGetIdentifierNameInto(database, query->from);
|
2020-07-05 15:57:59 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (like)
|
2019-03-15 16:14:13 +00:00
|
|
|
query->like = safeGet<const String &>(like->as<ASTLiteral &>().value);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
node = query;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2012-06-18 07:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|