aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Analyzer/IdentifierNode.cpp
blob: 88b3daacb125bcf7c68d256fda5934c85e6d9ed2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <Analyzer/IdentifierNode.h>

#include <Common/assert_cast.h>
#include <Common/SipHash.h>

#include <IO/WriteBufferFromString.h>
#include <IO/Operators.h>

#include <Parsers/ASTIdentifier.h>

namespace DB
{

IdentifierNode::IdentifierNode(Identifier identifier_)
    : IQueryTreeNode(children_size)
    , identifier(std::move(identifier_))
{}

IdentifierNode::IdentifierNode(Identifier identifier_, TableExpressionModifiers table_expression_modifiers_)
    : IQueryTreeNode(children_size)
    , identifier(std::move(identifier_))
    , table_expression_modifiers(std::move(table_expression_modifiers_))
{}

void IdentifierNode::dumpTreeImpl(WriteBuffer & buffer, FormatState & format_state, size_t indent) const
{
    buffer << std::string(indent, ' ') << "IDENTIFIER id: " << format_state.getNodeId(this);

    if (hasAlias())
        buffer << ", alias: " << getAlias();

    buffer << ", identifier: " << identifier.getFullName();

    if (table_expression_modifiers)
    {
        buffer << ", ";
        table_expression_modifiers->dump(buffer);
    }
}

bool IdentifierNode::isEqualImpl(const IQueryTreeNode & rhs) const
{
    const auto & rhs_typed = assert_cast<const IdentifierNode &>(rhs);
    return identifier == rhs_typed.identifier && table_expression_modifiers == rhs_typed.table_expression_modifiers;
}

void IdentifierNode::updateTreeHashImpl(HashState & state) const
{
    const auto & identifier_name = identifier.getFullName();
    state.update(identifier_name.size());
    state.update(identifier_name);

    if (table_expression_modifiers)
        table_expression_modifiers->updateTreeHash(state);
}

QueryTreeNodePtr IdentifierNode::cloneImpl() const
{
    return std::make_shared<IdentifierNode>(identifier);
}

ASTPtr IdentifierNode::toASTImpl(const ConvertToASTOptions & /* options */) const
{
    auto identifier_parts = identifier.getParts();
    return std::make_shared<ASTIdentifier>(std::move(identifier_parts));
}

}