2021-01-12 18:34:35 +00:00
|
|
|
#include <Parsers/ASTWindowDefinition.h>
|
|
|
|
|
2021-01-13 19:29:52 +00:00
|
|
|
#include <Common/quoteString.h>
|
|
|
|
#include <IO/Operators.h>
|
|
|
|
|
2021-01-12 18:34:35 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
ASTPtr ASTWindowDefinition::clone() const
|
|
|
|
{
|
|
|
|
auto result = std::make_shared<ASTWindowDefinition>();
|
|
|
|
|
|
|
|
if (partition_by)
|
|
|
|
{
|
|
|
|
result->partition_by = partition_by->clone();
|
|
|
|
result->children.push_back(result->partition_by);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (order_by)
|
|
|
|
{
|
|
|
|
result->order_by = order_by->clone();
|
|
|
|
result->children.push_back(result->order_by);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
String ASTWindowDefinition::getID(char) const
|
|
|
|
{
|
|
|
|
return "WindowDefinition";
|
|
|
|
}
|
|
|
|
|
2021-01-13 19:29:52 +00:00
|
|
|
void ASTWindowDefinition::formatImpl(const FormatSettings & settings,
|
|
|
|
FormatState & state, FormatStateStacked frame) const
|
|
|
|
{
|
|
|
|
if (partition_by)
|
|
|
|
{
|
|
|
|
settings.ostr << "PARTITION BY ";
|
|
|
|
partition_by->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (partition_by && order_by)
|
|
|
|
{
|
|
|
|
settings.ostr << " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (order_by)
|
|
|
|
{
|
|
|
|
settings.ostr << "ORDER BY ";
|
|
|
|
order_by->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ASTWindowDefinition::getDefaultWindowName() const
|
|
|
|
{
|
|
|
|
WriteBufferFromOwnString ostr;
|
|
|
|
FormatSettings settings{ostr, true /* one_line */};
|
|
|
|
FormatState state;
|
|
|
|
FormatStateStacked frame;
|
|
|
|
formatImpl(settings, state, frame);
|
|
|
|
return ostr.str();
|
|
|
|
}
|
|
|
|
|
2021-01-12 18:34:35 +00:00
|
|
|
ASTPtr ASTWindowListElement::clone() const
|
|
|
|
{
|
|
|
|
auto result = std::make_shared<ASTWindowListElement>();
|
|
|
|
|
|
|
|
result->name = name;
|
|
|
|
result->definition = definition->clone();
|
|
|
|
result->children.push_back(result->definition);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
String ASTWindowListElement::getID(char) const
|
|
|
|
{
|
|
|
|
return "WindowListElement";
|
|
|
|
}
|
|
|
|
|
2021-01-13 19:29:52 +00:00
|
|
|
void ASTWindowListElement::formatImpl(const FormatSettings & settings,
|
|
|
|
FormatState & state, FormatStateStacked frame) const
|
|
|
|
{
|
|
|
|
settings.ostr << backQuoteIfNeed(name);
|
|
|
|
settings.ostr << " AS (";
|
|
|
|
definition->formatImpl(settings, state, frame);
|
|
|
|
settings.ostr << ")";
|
|
|
|
}
|
|
|
|
|
2021-01-12 18:34:35 +00:00
|
|
|
}
|