aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Analyzer/InterpolateNode.h
blob: c45800ebaaff2c29532d7379741926f6e8eb61fe (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
#pragma once

#include <Analyzer/IQueryTreeNode.h>
#include <Analyzer/ListNode.h>

namespace DB
{

/** Interpolate node represents expression interpolation in INTERPOLATE section that is part of ORDER BY section in query tree.
  *
  * Example: SELECT * FROM test_table ORDER BY id WITH FILL INTERPOLATE (value AS value + 1);
  * value - expression to interpolate.
  * value + 1 - interpolate expression.
  */
class InterpolateNode;
using InterpolateNodePtr = std::shared_ptr<InterpolateNode>;

class InterpolateNode final : public IQueryTreeNode
{
public:
    /// Initialize interpolate node with expression and interpolate expression
    explicit InterpolateNode(QueryTreeNodePtr expression_, QueryTreeNodePtr interpolate_expression_);

    /// Get expression to interpolate
    const QueryTreeNodePtr & getExpression() const
    {
        return children[expression_child_index];
    }

    /// Get expression to interpolate
    QueryTreeNodePtr & getExpression()
    {
        return children[expression_child_index];
    }

    /// Get interpolate expression
    const QueryTreeNodePtr & getInterpolateExpression() const
    {
        return children[interpolate_expression_child_index];
    }

    /// Get interpolate expression
    QueryTreeNodePtr & getInterpolateExpression()
    {
        return children[interpolate_expression_child_index];
    }

    QueryTreeNodeType getNodeType() const override
    {
        return QueryTreeNodeType::INTERPOLATE;
    }

    void dumpTreeImpl(WriteBuffer & buffer, FormatState & format_state, size_t indent) const override;

protected:
    bool isEqualImpl(const IQueryTreeNode & rhs) const override;

    void updateTreeHashImpl(HashState & hash_state) const override;

    QueryTreeNodePtr cloneImpl() const override;

    ASTPtr toASTImpl(const ConvertToASTOptions & options) const override;

private:
    static constexpr size_t expression_child_index = 0;
    static constexpr size_t interpolate_expression_child_index = 1;
    static constexpr size_t children_size = interpolate_expression_child_index + 1;
};

}