ClickHouse/dbms/src/Parsers/ASTInsertQuery.cpp

86 lines
2.2 KiB
C++
Raw Normal View History

2017-04-16 05:40:17 +00:00
#include <iomanip>
#include <Parsers/ASTInsertQuery.h>
#include <Parsers/ASTFunction.h>
2016-11-20 12:43:20 +00:00
namespace DB
{
namespace ErrorCodes
{
2019-09-05 13:17:01 +00:00
extern const int INVALID_USAGE_OF_INPUT;
}
2016-11-20 12:43:20 +00:00
void ASTInsertQuery::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{
frame.need_parens = false;
settings.ostr << (settings.hilite ? hilite_keyword : "") << "INSERT INTO ";
if (table_function)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "FUNCTION ";
table_function->formatImpl(settings, state, frame);
}
else
settings.ostr << (settings.hilite ? hilite_none : "")
<< (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table);
if (columns)
{
settings.ostr << " (";
columns->formatImpl(settings, state, frame);
settings.ostr << ")";
}
if (select)
{
settings.ostr << " ";
select->formatImpl(settings, state, frame);
}
else
{
if (!format.empty())
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << " FORMAT " << (settings.hilite ? hilite_none : "") << format;
}
else
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << " VALUES" << (settings.hilite ? hilite_none : "");
}
}
if (settings_ast)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SETTINGS " << (settings.hilite ? hilite_none : "");
settings_ast->formatImpl(settings, state, frame);
}
2016-11-20 12:43:20 +00:00
}
2019-05-30 21:33:06 +00:00
void tryFindInputFunctionImpl(const ASTPtr & ast, ASTPtr & input_function)
{
if (!ast)
return;
for (const auto & child : ast->children)
2019-05-30 21:33:06 +00:00
tryFindInputFunctionImpl(child, input_function);
2019-05-30 21:33:06 +00:00
if (const auto * table_function_ast = ast->as<ASTFunction>())
{
2019-05-30 21:33:06 +00:00
if (table_function_ast->name == "input")
{
if (input_function)
2019-09-05 13:17:01 +00:00
throw Exception("You can use 'input()' function only once per request.", ErrorCodes::INVALID_USAGE_OF_INPUT);
input_function = ast;
}
}
}
2019-05-30 21:33:06 +00:00
void ASTInsertQuery::tryFindInputFunction(ASTPtr & input_function) const
{
tryFindInputFunctionImpl(select, input_function);
}
2016-11-20 12:43:20 +00:00
}