2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/TablePropertiesQueriesASTs.h>
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/CommonParsers.h>
|
|
|
|
#include <Parsers/ParserTablePropertiesQuery.h>
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2016-11-20 12:43:20 +00:00
|
|
|
|
2012-12-15 03:09:04 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2012-12-15 03:09:04 +00:00
|
|
|
{
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_exists("EXISTS");
|
2018-02-14 04:00:37 +00:00
|
|
|
ParserKeyword s_temporary("TEMPORARY");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_show("SHOW");
|
|
|
|
ParserKeyword s_create("CREATE");
|
2018-03-12 14:14:56 +00:00
|
|
|
ParserKeyword s_database("DATABASE");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_table("TABLE");
|
2020-12-27 14:14:08 +00:00
|
|
|
ParserKeyword s_view("VIEW");
|
2019-10-08 12:34:04 +00:00
|
|
|
ParserKeyword s_dictionary("DICTIONARY");
|
2017-07-10 03:28:12 +00:00
|
|
|
ParserToken s_dot(TokenType::Dot);
|
2021-09-06 22:13:54 +00:00
|
|
|
ParserIdentifier name_p(true);
|
2012-12-15 03:09:04 +00:00
|
|
|
|
|
|
|
ASTPtr database;
|
|
|
|
ASTPtr table;
|
2017-01-11 19:05:46 +00:00
|
|
|
std::shared_ptr<ASTQueryWithTableAndOutput> query;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2018-03-12 14:14:56 +00:00
|
|
|
bool parse_only_database_name = false;
|
2020-12-14 14:37:25 +00:00
|
|
|
bool parse_show_create_view = false;
|
2020-12-27 14:14:08 +00:00
|
|
|
bool exists_view = false;
|
2018-03-12 14:14:56 +00:00
|
|
|
|
2019-10-08 19:39:20 +00:00
|
|
|
bool temporary = false;
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_exists.ignore(pos, expected))
|
2013-02-21 10:02:33 +00:00
|
|
|
{
|
2020-12-24 09:16:47 +00:00
|
|
|
if (s_database.ignore(pos, expected))
|
2020-12-24 10:14:01 +00:00
|
|
|
{
|
2020-12-24 09:16:47 +00:00
|
|
|
query = std::make_shared<ASTExistsDatabaseQuery>();
|
2020-12-24 10:14:01 +00:00
|
|
|
parse_only_database_name = true;
|
2020-12-24 10:14:17 +00:00
|
|
|
}
|
2020-12-27 14:14:08 +00:00
|
|
|
else if (s_view.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
query = std::make_shared<ASTExistsViewQuery>();
|
|
|
|
exists_view = true;
|
|
|
|
}
|
2019-12-13 20:24:03 +00:00
|
|
|
else
|
2020-12-24 09:16:47 +00:00
|
|
|
{
|
|
|
|
if (s_temporary.ignore(pos, expected))
|
|
|
|
temporary = true;
|
|
|
|
|
|
|
|
if (s_table.checkWithoutMoving(pos, expected))
|
|
|
|
query = std::make_shared<ASTExistsTableQuery>();
|
|
|
|
else if (s_dictionary.checkWithoutMoving(pos, expected))
|
|
|
|
query = std::make_shared<ASTExistsDictionaryQuery>();
|
|
|
|
else
|
|
|
|
query = std::make_shared<ASTExistsTableQuery>();
|
|
|
|
}
|
2013-02-21 10:02:33 +00:00
|
|
|
}
|
2017-07-10 03:28:12 +00:00
|
|
|
else if (s_show.ignore(pos, expected))
|
2013-02-21 10:02:33 +00:00
|
|
|
{
|
2023-04-10 10:42:54 +00:00
|
|
|
bool has_create = false;
|
2023-04-10 08:27:21 +00:00
|
|
|
|
2023-04-10 10:42:54 +00:00
|
|
|
if (s_create.checkWithoutMoving(pos, expected))
|
2023-04-10 08:27:21 +00:00
|
|
|
{
|
2023-04-10 10:42:54 +00:00
|
|
|
has_create = true;
|
|
|
|
s_create.ignore(pos, expected);
|
2023-04-10 08:27:21 +00:00
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2018-03-12 14:14:56 +00:00
|
|
|
if (s_database.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
parse_only_database_name = true;
|
|
|
|
query = std::make_shared<ASTShowCreateDatabaseQuery>();
|
|
|
|
}
|
2019-10-08 19:39:20 +00:00
|
|
|
else if (s_dictionary.checkWithoutMoving(pos, expected))
|
2019-10-08 12:34:04 +00:00
|
|
|
query = std::make_shared<ASTShowCreateDictionaryQuery>();
|
2020-12-14 14:37:25 +00:00
|
|
|
else if (s_view.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
query = std::make_shared<ASTShowCreateViewQuery>();
|
|
|
|
parse_show_create_view = true;
|
|
|
|
}
|
2019-10-08 19:39:20 +00:00
|
|
|
else
|
2023-04-10 08:27:21 +00:00
|
|
|
{
|
|
|
|
/// We support `SHOW CREATE tbl;` and `SHOW TABLE tbl`,
|
2023-04-10 10:42:54 +00:00
|
|
|
/// but do not support `SHOW tbl`, which is ambiguous
|
2023-04-10 08:27:21 +00:00
|
|
|
/// with other statement like `SHOW PRIVILEGES`.
|
|
|
|
if (has_create || s_table.checkWithoutMoving(pos, expected))
|
|
|
|
query = std::make_shared<ASTShowCreateTableQuery>();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-21 10:02:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-15 03:09:04 +00:00
|
|
|
return false;
|
2013-02-21 10:02:33 +00:00
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2018-03-12 14:14:56 +00:00
|
|
|
if (parse_only_database_name)
|
|
|
|
{
|
|
|
|
if (!name_p.parse(pos, database, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-31 07:50:13 +00:00
|
|
|
if (!(exists_view || parse_show_create_view))
|
2020-12-27 14:14:08 +00:00
|
|
|
{
|
|
|
|
if (temporary || s_temporary.ignore(pos, expected))
|
|
|
|
query->temporary = true;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2020-12-27 14:14:08 +00:00
|
|
|
if (!s_table.ignore(pos, expected))
|
|
|
|
s_dictionary.ignore(pos, expected);
|
|
|
|
}
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!name_p.parse(pos, table, expected))
|
2012-12-15 03:09:04 +00:00
|
|
|
return false;
|
2018-03-12 14:14:56 +00:00
|
|
|
if (s_dot.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
database = table;
|
|
|
|
if (!name_p.parse(pos, table, expected))
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-15 03:09:04 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 22:13:54 +00:00
|
|
|
query->database = database;
|
|
|
|
query->table = table;
|
2021-09-06 22:24:47 +00:00
|
|
|
|
2021-09-06 22:13:54 +00:00
|
|
|
if (database)
|
|
|
|
query->children.push_back(database);
|
|
|
|
|
|
|
|
if (table)
|
|
|
|
query->children.push_back(table);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-01-11 19:05:46 +00:00
|
|
|
node = query;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|