ClickHouse/src/Parsers/ParserQueryWithOutput.cpp

137 lines
5.0 KiB
C++
Raw Normal View History

2021-04-16 20:18:39 +00:00
#include <Parsers/ASTExplainQuery.h>
#include <Parsers/ASTSelectWithUnionQuery.h>
#include <Parsers/ASTSetQuery.h>
#include <Parsers/ParserAlterQuery.h>
#include <Parsers/ParserCheckQuery.h>
#include <Parsers/ParserCreateQuery.h>
2021-04-16 20:18:39 +00:00
#include <Parsers/ParserDescribeTableQuery.h>
#include <Parsers/ParserDropQuery.h>
2021-04-16 20:18:39 +00:00
#include <Parsers/ParserExplainQuery.h>
#include <Parsers/ParserKillQueryQuery.h>
#include <Parsers/ParserOptimizeQuery.h>
2021-04-16 20:18:39 +00:00
#include <Parsers/ParserQueryWithOutput.h>
#include <Parsers/ParserRenameQuery.h>
#include <Parsers/ParserSelectWithUnionQuery.h>
#include <Parsers/ParserSetQuery.h>
2021-04-16 20:18:39 +00:00
#include <Parsers/ParserShowProcesslistQuery.h>
#include <Parsers/ParserShowTablesQuery.h>
#include <Parsers/ParserTablePropertiesQuery.h>
#include <Parsers/ParserWatchQuery.h>
#include <Parsers/QueryWithOutputSettingsPushDownVisitor.h>
#include <Parsers/Access/ParserShowAccessEntitiesQuery.h>
#include <Parsers/Access/ParserShowAccessQuery.h>
#include <Parsers/Access/ParserShowCreateAccessEntityQuery.h>
#include <Parsers/Access/ParserShowGrantsQuery.h>
#include <Parsers/Access/ParserShowPrivilegesQuery.h>
#include "Common/Exception.h"
2016-11-20 12:43:20 +00:00
2015-10-21 14:57:10 +00:00
namespace DB
{
bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
2015-10-21 14:57:10 +00:00
{
ParserShowTablesQuery show_tables_p;
2018-02-25 00:50:53 +00:00
ParserSelectWithUnionQuery select_p;
ParserTablePropertiesQuery table_p;
ParserDescribeTableQuery describe_table_p;
ParserShowProcesslistQuery show_processlist_p;
ParserCreateQuery create_p;
ParserAlterQuery alter_p;
ParserRenameQuery rename_p;
ParserDropQuery drop_p;
ParserCheckQuery check_p;
ParserOptimizeQuery optimize_p;
ParserKillQueryQuery kill_query_p;
ParserWatchQuery watch_p;
2020-06-10 23:08:37 +00:00
ParserShowAccessQuery show_access_p;
ParserShowAccessEntitiesQuery show_access_entities_p;
2019-12-01 22:01:05 +00:00
ParserShowCreateAccessEntityQuery show_create_access_entity_p;
ParserShowGrantsQuery show_grants_p;
2020-05-12 21:46:14 +00:00
ParserShowPrivilegesQuery show_privileges_p;
ParserExplainQuery explain_p(end, allow_settings_after_format_in_insert);
ASTPtr query;
2020-06-22 13:26:55 +00:00
bool parsed =
explain_p.parse(pos, query, expected)
|| 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`
|| show_tables_p.parse(pos, query, expected)
|| table_p.parse(pos, query, expected)
|| describe_table_p.parse(pos, query, expected)
|| show_processlist_p.parse(pos, query, expected)
|| create_p.parse(pos, query, expected)
|| alter_p.parse(pos, query, expected)
|| rename_p.parse(pos, query, expected)
|| drop_p.parse(pos, query, expected)
|| check_p.parse(pos, query, expected)
|| kill_query_p.parse(pos, query, expected)
|| optimize_p.parse(pos, query, expected)
2019-12-01 22:01:05 +00:00
|| watch_p.parse(pos, query, expected)
2020-06-10 23:08:37 +00:00
|| show_access_p.parse(pos, query, expected)
|| 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);
if (!parsed)
return false;
/// FIXME: try to prettify this cast using `as<>()`
auto & query_with_output = dynamic_cast<ASTQueryWithOutput &>(*query);
ParserKeyword s_into_outfile("INTO OUTFILE");
if (s_into_outfile.ignore(pos, expected))
{
ParserStringLiteral out_file_p;
if (!out_file_p.parse(pos, query_with_output.out_file, expected))
return false;
ParserKeyword s_compression_method("COMPRESSION");
if (s_compression_method.ignore(pos, expected))
{
ParserStringLiteral compression;
if (!compression.parse(pos, query_with_output.compression, expected))
return false;
}
query_with_output.children.push_back(query_with_output.out_file);
}
ParserKeyword s_format("FORMAT");
2015-10-21 14:57:10 +00:00
if (s_format.ignore(pos, expected))
{
ParserIdentifier format_p;
2015-10-21 14:57:10 +00:00
if (!format_p.parse(pos, query_with_output.format, expected))
return false;
setIdentifierSpecial(query_with_output.format);
query_with_output.children.push_back(query_with_output.format);
}
// SETTINGS key1 = value1, key2 = value2, ...
ParserKeyword s_settings("SETTINGS");
if (s_settings.ignore(pos, expected))
{
ParserSetQuery parser_settings(true);
if (!parser_settings.parse(pos, query_with_output.settings_ast, expected))
return false;
query_with_output.children.push_back(query_with_output.settings_ast);
// SETTINGS after FORMAT is not parsed by the SELECT parser (ParserSelectQuery)
// Pass them manually, to apply in InterpreterSelectQuery::initSettings()
if (query->as<ASTSelectWithUnionQuery>())
{
QueryWithOutputSettingsPushDownVisitor::Data data{query_with_output.settings_ast};
QueryWithOutputSettingsPushDownVisitor(data).visit(query);
}
}
2020-06-22 14:37:42 +00:00
node = std::move(query);
return true;
2015-10-21 14:57:10 +00:00
}
}