aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Analyzer/ListNode.cpp
blob: 799c471d6859f36219d2056526f50e2ecbed1e93 (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
69
70
#include <Analyzer/ListNode.h>

#include <Common/SipHash.h>

#include <IO/WriteBuffer.h>
#include <IO/WriteHelpers.h>
#include <IO/Operators.h>

#include <Parsers/ASTExpressionList.h>

namespace DB
{

ListNode::ListNode()
    : IQueryTreeNode(0 /*children_size*/)
{}

ListNode::ListNode(QueryTreeNodes nodes)
    : IQueryTreeNode(0 /*children_size*/)
{
    children = std::move(nodes);
}

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

    size_t children_size = children.size();
    buffer << ", nodes: " << children_size << '\n';

    for (size_t i = 0; i < children_size; ++i)
    {
        const auto & node = children[i];
        node->dumpTreeImpl(buffer, format_state, indent + 2);

        if (i + 1 != children_size)
            buffer << '\n';
    }
}

bool ListNode::isEqualImpl(const IQueryTreeNode &) const
{
    /// No state
    return true;
}

void ListNode::updateTreeHashImpl(HashState &) const
{
    /// No state
}

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

ASTPtr ListNode::toASTImpl(const ConvertToASTOptions & options) const
{
    auto expression_list_ast = std::make_shared<ASTExpressionList>();

    size_t children_size = children.size();
    expression_list_ast->children.resize(children_size);

    for (size_t i = 0; i < children_size; ++i)
        expression_list_ast->children[i] = children[i]->toAST(options);

    return expression_list_ast;
}

}