ClickHouse/src/Analyzer/InterpolateNode.cpp

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

71 lines
2.2 KiB
C++
Raw Normal View History

#include <Analyzer/InterpolateNode.h>
2022-09-03 16:20:09 +00:00
#include <Common/SipHash.h>
#include <IO/WriteBufferFromString.h>
#include <IO/Operators.h>
#include <Parsers/ASTInterpolateElement.h>
namespace DB
{
InterpolateNode::InterpolateNode(std::shared_ptr<IdentifierNode> expression_, QueryTreeNodePtr interpolate_expression_)
2022-10-07 10:44:28 +00:00
: IQueryTreeNode(children_size)
2022-09-03 16:20:09 +00:00
{
2024-06-11 14:47:35 +00:00
if (expression_)
expression_name = expression_->getIdentifier().getFullName();
2022-09-03 16:20:09 +00:00
children[expression_child_index] = std::move(expression_);
children[interpolate_expression_child_index] = std::move(interpolate_expression_);
}
void InterpolateNode::dumpTreeImpl(WriteBuffer & buffer, FormatState & format_state, size_t indent) const
2022-09-03 16:20:09 +00:00
{
2022-10-19 10:25:27 +00:00
buffer << std::string(indent, ' ') << "INTERPOLATE id: " << format_state.getNodeId(this);
2022-09-03 16:20:09 +00:00
buffer << '\n' << std::string(indent + 2, ' ') << "EXPRESSION\n";
getExpression()->dumpTreeImpl(buffer, format_state, indent + 4);
buffer << '\n' << std::string(indent + 2, ' ') << "INTERPOLATE_EXPRESSION\n";
getInterpolateExpression()->dumpTreeImpl(buffer, format_state, indent + 4);
}
2024-04-05 16:22:57 +00:00
bool InterpolateNode::isEqualImpl(const IQueryTreeNode &, CompareOptions) const
2022-09-03 16:20:09 +00:00
{
2022-10-19 10:25:27 +00:00
/// No state in interpolate node
2022-09-03 16:20:09 +00:00
return true;
}
2024-04-05 16:22:57 +00:00
void InterpolateNode::updateTreeHashImpl(HashState &, CompareOptions) const
2022-09-03 16:20:09 +00:00
{
2022-10-19 10:25:27 +00:00
/// No state in interpolate node
2022-09-03 16:20:09 +00:00
}
QueryTreeNodePtr InterpolateNode::cloneImpl() const
{
auto cloned = std::make_shared<InterpolateNode>(nullptr /*expression*/, nullptr /*interpolate_expression*/);
cloned->expression_name = expression_name;
return cloned;
}
2023-03-14 09:14:58 +00:00
ASTPtr InterpolateNode::toASTImpl(const ConvertToASTOptions & options) const
2022-09-03 16:20:09 +00:00
{
auto result = std::make_shared<ASTInterpolateElement>();
2024-06-11 10:23:56 +00:00
/// Interpolate parser supports only identifier node.
/// In case of alias, identifier is replaced to expression, which can't be parsed.
/// In this case, keep original alias name.
if (const auto * identifier = getExpression()->as<IdentifierNode>())
result->column = identifier->toAST(options)->getColumnName();
else
result->column = expression_name;
result->children.push_back(getInterpolateExpression()->toAST(options));
2022-09-03 16:20:09 +00:00
result->expr = result->children.back();
return result;
}
}