2021-08-12 11:42:51 +00:00
|
|
|
#include <Parsers/ASTSelectIntersectExceptQuery.h>
|
2021-04-16 20:18:39 +00:00
|
|
|
#include <Parsers/ASTSubquery.h>
|
2021-08-10 06:24:12 +00:00
|
|
|
#include <Parsers/ASTSelectWithUnionQuery.h>
|
|
|
|
|
2021-04-16 20:18:39 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-08-12 11:42:51 +00:00
|
|
|
ASTPtr ASTSelectIntersectExceptQuery::clone() const
|
2021-04-16 20:18:39 +00:00
|
|
|
{
|
2021-08-12 11:42:51 +00:00
|
|
|
auto res = std::make_shared<ASTSelectIntersectExceptQuery>(*this);
|
|
|
|
|
2021-04-16 20:18:39 +00:00
|
|
|
res->children.clear();
|
2021-08-12 11:42:51 +00:00
|
|
|
for (const auto & child : children)
|
|
|
|
res->children.push_back(child->clone());
|
|
|
|
|
|
|
|
res->final_operator = final_operator;
|
2021-04-16 20:18:39 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-11-01 13:19:31 +00:00
|
|
|
void ASTSelectIntersectExceptQuery::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
2021-04-16 20:18:39 +00:00
|
|
|
{
|
|
|
|
std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' ');
|
2021-08-10 06:24:12 +00:00
|
|
|
|
2021-08-14 12:31:55 +00:00
|
|
|
for (ASTs::const_iterator it = children.begin(); it != children.end(); ++it)
|
2021-08-10 06:24:12 +00:00
|
|
|
{
|
2021-08-14 12:31:55 +00:00
|
|
|
if (it != children.begin())
|
2021-08-10 06:24:12 +00:00
|
|
|
{
|
|
|
|
settings.ostr << settings.nl_or_ws << indent_str << (settings.hilite ? hilite_keyword : "")
|
2022-08-30 10:09:01 +00:00
|
|
|
<< fromOperator(final_operator)
|
2021-08-15 06:55:43 +00:00
|
|
|
<< (settings.hilite ? hilite_none : "")
|
|
|
|
<< settings.nl_or_ws;
|
2021-08-10 06:24:12 +00:00
|
|
|
}
|
|
|
|
|
2021-08-14 12:31:55 +00:00
|
|
|
(*it)->formatImpl(settings, state, frame);
|
2021-08-10 06:24:12 +00:00
|
|
|
}
|
2021-04-16 20:18:39 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 08:16:18 +00:00
|
|
|
ASTs ASTSelectIntersectExceptQuery::getListOfSelects() const
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Because of normalization actual number of selects is 2.
|
|
|
|
* But this is checked in InterpreterSelectIntersectExceptQuery.
|
|
|
|
*/
|
|
|
|
ASTs selects;
|
|
|
|
for (const auto & child : children)
|
|
|
|
{
|
|
|
|
if (typeid_cast<ASTSelectQuery *>(child.get())
|
|
|
|
|| typeid_cast<ASTSelectWithUnionQuery *>(child.get())
|
|
|
|
|| typeid_cast<ASTSelectIntersectExceptQuery *>(child.get()))
|
|
|
|
selects.push_back(child);
|
|
|
|
}
|
|
|
|
return selects;
|
|
|
|
}
|
|
|
|
|
2022-08-30 10:09:01 +00:00
|
|
|
const char * ASTSelectIntersectExceptQuery::fromOperator(Operator op)
|
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case Operator::EXCEPT_ALL:
|
|
|
|
return "EXCEPT ALL";
|
|
|
|
case Operator::EXCEPT_DISTINCT:
|
|
|
|
return "EXCEPT DISTINCT";
|
|
|
|
case Operator::INTERSECT_ALL:
|
|
|
|
return "INTERSECT ALL";
|
|
|
|
case Operator::INTERSECT_DISTINCT:
|
|
|
|
return "INTERSECT DISTINCT";
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2021-04-16 20:18:39 +00:00
|
|
|
}
|