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

#include <Core/Field.h>
#include <DataTypes/IDataType.h>

namespace DB
{

/** Immutable constant value representation during analysis stage.
  * Some query nodes can be represented by constant (scalar subqueries, functions with constant arguments).
  */
class ConstantValue;
using ConstantValuePtr = std::shared_ptr<ConstantValue>;

class ConstantValue
{
public:
    ConstantValue(Field value_, DataTypePtr data_type_)
        : value(std::move(value_))
        , data_type(std::move(data_type_))
    {}

    const Field & getValue() const
    {
        return value;
    }

    const DataTypePtr & getType() const
    {
        return data_type;
    }
private:
    Field value;
    DataTypePtr data_type;
};

inline bool operator==(const ConstantValue & lhs, const ConstantValue & rhs)
{
    return lhs.getValue() == rhs.getValue() && lhs.getType()->equals(*rhs.getType());
}

inline bool operator!=(const ConstantValue & lhs, const ConstantValue & rhs)
{
    return !(lhs == rhs);
}

}