ClickHouse/dbms/src/Parsers/ParserQueryWithOutput.cpp

84 lines
2.3 KiB
C++
Raw Normal View History

2015-10-21 14:57:10 +00:00
#include <DB/Parsers/ParserQueryWithOutput.h>
#include <DB/Parsers/ParserShowTablesQuery.h>
#include <DB/Parsers/ParserSelectQuery.h>
#include <DB/Parsers/ParserTablePropertiesQuery.h>
#include <DB/Parsers/ParserShowProcesslistQuery.h>
#include <DB/Parsers/ParserCheckQuery.h>
2017-01-24 13:39:39 +00:00
#include <DB/Parsers/ParserKillQueryQuery.h>
2015-10-21 14:57:10 +00:00
#include <DB/Parsers/ASTIdentifier.h>
#include <DB/Parsers/ExpressionElementParsers.h>
2016-11-20 12:43:20 +00:00
#include <DB/Common/typeid_cast.h>
2015-10-21 14:57:10 +00:00
namespace DB
{
bool ParserQueryWithOutput::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
2015-10-21 14:57:10 +00:00
{
ParserShowTablesQuery show_tables_p;
ParserSelectQuery select_p;
ParserTablePropertiesQuery table_p;
ParserShowProcesslistQuery show_processlist_p;
ParserCheckQuery check_p;
2017-01-24 13:39:39 +00:00
ParserKillQueryQuery kill_query_p;
ASTPtr query;
bool parsed = select_p.parse(pos, end, query, max_parsed_pos, expected)
|| show_tables_p.parse(pos, end, query, max_parsed_pos, expected)
|| table_p.parse(pos, end, query, max_parsed_pos, expected)
|| show_processlist_p.parse(pos, end, query, max_parsed_pos, expected)
2017-01-24 13:39:39 +00:00
|| check_p.parse(pos, end, query, max_parsed_pos, expected)
|| kill_query_p.parse(pos, end, query, max_parsed_pos, expected);
if (!parsed)
return false;
auto & query_with_output = dynamic_cast<ASTQueryWithOutput &>(*query);
ParserString s_into("INTO", /* word_boundary_ = */ true, /* case_insensitive_ = */ true);
if (s_into.ignore(pos, end, max_parsed_pos, expected))
{
ws.ignore(pos, end);
2017-01-19 12:02:30 +00:00
ParserString s_outfile("OUTFILE", true, true);
if (!s_outfile.ignore(pos, end, max_parsed_pos, expected))
{
expected = "OUTFILE";
return false;
}
ws.ignore(pos, end);
ParserStringLiteral out_file_p;
if (!out_file_p.parse(pos, end, query_with_output.out_file, max_parsed_pos, expected))
return false;
query_with_output.children.push_back(query_with_output.out_file);
ws.ignore(pos, end);
}
2015-10-21 14:57:10 +00:00
ParserString s_format("FORMAT", true, true);
if (s_format.ignore(pos, end, max_parsed_pos, expected))
{
ws.ignore(pos, end);
ParserIdentifier format_p;
if (!format_p.parse(pos, end, query_with_output.format, max_parsed_pos, expected))
2015-10-21 14:57:10 +00:00
return false;
typeid_cast<ASTIdentifier &>(*(query_with_output.format)).kind = ASTIdentifier::Format;
query_with_output.children.push_back(query_with_output.format);
2015-10-21 14:57:10 +00:00
ws.ignore(pos, end);
}
node = query;
return true;
2015-10-21 14:57:10 +00:00
}
}