ClickHouse/src/Parsers/ASTPartition.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
1.7 KiB
C++
Raw Normal View History

#include <Parsers/ASTPartition.h>
#include <IO/WriteHelpers.h>
2020-11-09 16:05:40 +00:00
#include <IO/Operators.h>
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");
}
String ASTPartition::getID(char delim) const
{
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);
}
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();
}
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";
}
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);
}
}
}