2017-09-06 20:34:26 +00:00
|
|
|
#include <Parsers/ASTPartition.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
2020-11-09 16:05:40 +00:00
|
|
|
#include <IO/Operators.h>
|
2017-09-06 20:34:26 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2023-10-13 14:22:18 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTPartition::setPartitionID(const ASTPtr & ast)
|
|
|
|
{
|
|
|
|
if (children.empty())
|
|
|
|
{
|
|
|
|
children.push_back(ast);
|
|
|
|
id = children[0].get();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot have multiple children for partition AST");
|
|
|
|
}
|
|
|
|
void ASTPartition::setPartitionValue(const ASTPtr & ast)
|
|
|
|
{
|
|
|
|
if (children.empty())
|
|
|
|
{
|
|
|
|
children.push_back(ast);
|
|
|
|
value = children[0].get();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot have multiple children for partition AST");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-07 12:34:40 +00:00
|
|
|
String ASTPartition::getID(char delim) const
|
2017-09-06 20:34:26 +00:00
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
return "Partition";
|
2023-10-18 07:26:32 +00:00
|
|
|
|
|
|
|
std::string id_string = id ? id->getID() : "";
|
|
|
|
return "Partition_ID" + (delim + id_string);
|
2017-09-06 20:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ASTPtr ASTPartition::clone() const
|
|
|
|
{
|
|
|
|
auto res = std::make_shared<ASTPartition>(*this);
|
|
|
|
res->children.clear();
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
2023-10-13 14:22:18 +00:00
|
|
|
res->children.push_back(children[0]->clone());
|
|
|
|
res->value = res->children[0].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
res->children.push_back(children[0]->clone());
|
|
|
|
res->id = res->children[0].get();
|
2017-09-06 20:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTPartition::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
value->formatImpl(settings, state, frame);
|
|
|
|
}
|
2023-10-13 14:22:18 +00:00
|
|
|
else if (all)
|
|
|
|
{
|
|
|
|
settings.ostr << "ALL";
|
|
|
|
}
|
2017-09-06 20:34:26 +00:00
|
|
|
else
|
|
|
|
{
|
2023-10-13 14:22:18 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "ID " << (settings.hilite ? hilite_none : "");
|
|
|
|
id->formatImpl(settings, state, frame);
|
2017-09-06 20:34:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|