2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ParserQueryWithOutput.h>
|
|
|
|
#include <Parsers/ParserShowTablesQuery.h>
|
2018-02-25 00:50:53 +00:00
|
|
|
#include <Parsers/ParserSelectWithUnionQuery.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ParserTablePropertiesQuery.h>
|
2017-11-01 14:34:05 +00:00
|
|
|
#include <Parsers/ParserDescribeTableQuery.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ParserShowProcesslistQuery.h>
|
|
|
|
#include <Parsers/ParserCheckQuery.h>
|
2017-08-03 17:00:41 +00:00
|
|
|
#include <Parsers/ParserCreateQuery.h>
|
|
|
|
#include <Parsers/ParserRenameQuery.h>
|
|
|
|
#include <Parsers/ParserAlterQuery.h>
|
|
|
|
#include <Parsers/ParserDropQuery.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ParserKillQueryQuery.h>
|
2018-07-20 05:46:48 +00:00
|
|
|
#include <Parsers/ParserOptimizeQuery.h>
|
2019-05-28 21:17:48 +00:00
|
|
|
#include <Parsers/ParserWatchQuery.h>
|
2019-01-23 19:23:37 +00:00
|
|
|
#include <Parsers/ParserSetQuery.h>
|
2018-09-21 15:20:23 +00:00
|
|
|
#include <Parsers/ASTExplainQuery.h>
|
2020-05-07 02:45:27 +00:00
|
|
|
#include <Parsers/ParserShowAccessEntitiesQuery.h>
|
2019-12-01 22:01:05 +00:00
|
|
|
#include <Parsers/ParserShowCreateAccessEntityQuery.h>
|
2020-05-07 02:45:27 +00:00
|
|
|
#include <Parsers/ParserShowGrantsQuery.h>
|
2020-05-12 21:46:14 +00:00
|
|
|
#include <Parsers/ParserShowPrivilegesQuery.h>
|
2016-11-20 12:43:20 +00:00
|
|
|
|
2015-10-21 14:57:10 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2015-10-21 14:57:10 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserShowTablesQuery show_tables_p;
|
2018-02-25 00:50:53 +00:00
|
|
|
ParserSelectWithUnionQuery select_p;
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserTablePropertiesQuery table_p;
|
2017-11-01 14:34:05 +00:00
|
|
|
ParserDescribeTableQuery describe_table_p;
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserShowProcesslistQuery show_processlist_p;
|
2017-08-03 17:00:41 +00:00
|
|
|
ParserCreateQuery create_p;
|
|
|
|
ParserAlterQuery alter_p;
|
|
|
|
ParserRenameQuery rename_p;
|
|
|
|
ParserDropQuery drop_p;
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserCheckQuery check_p;
|
2018-07-20 05:46:48 +00:00
|
|
|
ParserOptimizeQuery optimize_p;
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserKillQueryQuery kill_query_p;
|
2019-05-28 21:17:48 +00:00
|
|
|
ParserWatchQuery watch_p;
|
2020-05-07 02:45:27 +00:00
|
|
|
ParserShowAccessEntitiesQuery show_access_entities_p;
|
2019-12-01 22:01:05 +00:00
|
|
|
ParserShowCreateAccessEntityQuery show_create_access_entity_p;
|
2020-02-04 22:37:04 +00:00
|
|
|
ParserShowGrantsQuery show_grants_p;
|
2020-05-12 21:46:14 +00:00
|
|
|
ParserShowPrivilegesQuery show_privileges_p;
|
2017-01-11 19:05:46 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr query;
|
2017-01-11 19:05:46 +00:00
|
|
|
|
2018-09-21 15:20:23 +00:00
|
|
|
ParserKeyword s_ast("AST");
|
2019-02-11 19:53:55 +00:00
|
|
|
ParserKeyword s_analyze("ANALYZE");
|
2018-09-21 15:20:23 +00:00
|
|
|
bool explain_ast = false;
|
2019-02-11 19:53:55 +00:00
|
|
|
bool analyze_syntax = false;
|
2018-10-09 14:32:11 +00:00
|
|
|
|
|
|
|
if (enable_explain && s_ast.ignore(pos, expected))
|
2018-09-21 15:20:23 +00:00
|
|
|
explain_ast = true;
|
|
|
|
|
2019-02-11 19:53:55 +00:00
|
|
|
if (enable_explain && s_analyze.ignore(pos, expected))
|
|
|
|
analyze_syntax = true;
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool parsed = select_p.parse(pos, query, expected)
|
2019-12-01 22:01:05 +00:00
|
|
|
|| show_create_access_entity_p.parse(pos, query, expected) /// should be before `show_tables_p`
|
2017-07-10 03:28:12 +00:00
|
|
|
|| show_tables_p.parse(pos, query, expected)
|
|
|
|
|| table_p.parse(pos, query, expected)
|
2017-11-01 14:34:05 +00:00
|
|
|
|| describe_table_p.parse(pos, query, expected)
|
2017-07-10 03:28:12 +00:00
|
|
|
|| show_processlist_p.parse(pos, query, expected)
|
2017-08-03 17:00:41 +00:00
|
|
|
|| create_p.parse(pos, query, expected)
|
|
|
|
|| alter_p.parse(pos, query, expected)
|
|
|
|
|| rename_p.parse(pos, query, expected)
|
|
|
|
|| drop_p.parse(pos, query, expected)
|
2017-07-10 03:28:12 +00:00
|
|
|
|| check_p.parse(pos, query, expected)
|
2018-07-20 05:46:48 +00:00
|
|
|
|| kill_query_p.parse(pos, query, expected)
|
2019-05-28 21:17:48 +00:00
|
|
|
|| optimize_p.parse(pos, query, expected)
|
2019-12-01 22:01:05 +00:00
|
|
|
|| watch_p.parse(pos, query, expected)
|
2020-05-07 02:45:27 +00:00
|
|
|
|| show_access_entities_p.parse(pos, query, expected)
|
2020-05-12 21:46:14 +00:00
|
|
|
|| show_grants_p.parse(pos, query, expected)
|
|
|
|
|| show_privileges_p.parse(pos, query, expected);
|
2017-01-11 19:05:46 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!parsed)
|
|
|
|
return false;
|
2017-01-11 19:05:46 +00:00
|
|
|
|
2019-03-12 12:41:57 +00:00
|
|
|
/// FIXME: try to prettify this cast using `as<>()`
|
2019-03-15 16:14:13 +00:00
|
|
|
auto & query_with_output = dynamic_cast<ASTQueryWithOutput &>(*query);
|
2017-01-11 19:05:46 +00:00
|
|
|
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_into_outfile("INTO OUTFILE");
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_into_outfile.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
ParserStringLiteral out_file_p;
|
2019-03-15 16:14:13 +00:00
|
|
|
if (!out_file_p.parse(pos, query_with_output.out_file, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2017-01-11 19:05:46 +00:00
|
|
|
|
2019-03-15 16:14:13 +00:00
|
|
|
query_with_output.children.push_back(query_with_output.out_file);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2017-01-11 19:05:46 +00:00
|
|
|
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_format("FORMAT");
|
2015-10-21 14:57:10 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_format.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
ParserIdentifier format_p;
|
2015-10-21 14:57:10 +00:00
|
|
|
|
2019-03-15 16:14:13 +00:00
|
|
|
if (!format_p.parse(pos, query_with_output.format, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2019-03-15 16:14:13 +00:00
|
|
|
setIdentifierSpecial(query_with_output.format);
|
2017-01-11 19:05:46 +00:00
|
|
|
|
2019-03-15 16:14:13 +00:00
|
|
|
query_with_output.children.push_back(query_with_output.format);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2015-10-21 15:04:20 +00:00
|
|
|
|
2019-01-23 19:23:37 +00:00
|
|
|
// SETTINGS key1 = value1, key2 = value2, ...
|
|
|
|
ParserKeyword s_settings("SETTINGS");
|
|
|
|
if (s_settings.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
ParserSetQuery parser_settings(true);
|
2019-03-15 16:14:13 +00:00
|
|
|
if (!parser_settings.parse(pos, query_with_output.settings_ast, expected))
|
2019-01-23 19:23:37 +00:00
|
|
|
return false;
|
2019-03-15 16:14:13 +00:00
|
|
|
query_with_output.children.push_back(query_with_output.settings_ast);
|
2019-01-23 19:23:37 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 15:20:23 +00:00
|
|
|
if (explain_ast)
|
|
|
|
{
|
2019-02-11 19:53:55 +00:00
|
|
|
node = std::make_shared<ASTExplainQuery>(ASTExplainQuery::ParsedAST);
|
|
|
|
node->children.push_back(query);
|
|
|
|
}
|
|
|
|
else if (analyze_syntax)
|
|
|
|
{
|
|
|
|
node = std::make_shared<ASTExplainQuery>(ASTExplainQuery::AnalyzedSyntax);
|
2018-09-21 15:20:23 +00:00
|
|
|
node->children.push_back(query);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
node = query;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2015-10-21 14:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|