aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/clickhouse/client/columns/date.cpp
blob: 242511a7eba566baee81bc2da9ed905150612cdd (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "date.h"

namespace NClickHouse {
    TIntrusivePtr<TColumnDate> TColumnDate::Create() {
        return new TColumnDate();
    }

    TIntrusivePtr<TColumnDate> TColumnDate::Create(const TVector<TInstant>& data) {
        return new TColumnDate(data);
    }

    TColumnDate::TColumnDate()
        : TColumn(TType::CreateDate())
        , Data_(TColumnUInt16::Create())
    {
    }

    TColumnDate::TColumnDate(const TVector<TInstant>& data)
        : TColumnDate()
    {
        for (const auto& value : data) {
            Append(value);
        }
    }

    void TColumnDate::Append(const TInstant& value) {
        Data_->Append(static_cast<ui16>(value.Days()));
    }

    std::time_t TColumnDate::At(size_t n) const {
        return Data_->At(n) * 86400;
    }

    void TColumnDate::SetAt(size_t n, const TInstant& value) {
        Data_->SetAt(n, static_cast<ui16>(value.Days()));
    }

    void TColumnDate::Append(TColumnRef column) {
        if (auto col = column->As<TColumnDate>()) {
            Data_->Append(col->Data_);
        }
    }

    bool TColumnDate::Load(TCodedInputStream* input, size_t rows) {
        return Data_->Load(input, rows);
    }

    void TColumnDate::Save(TCodedOutputStream* output) {
        Data_->Save(output);
    }

    size_t TColumnDate::Size() const {
        return Data_->Size();
    }

    TColumnRef TColumnDate::Slice(size_t begin, size_t len) {
        auto col = Data_->Slice(begin, len)->As<TColumnUInt16>();
        auto result = TColumnDate::Create();

        result->Data_->Append(col);

        return result;
    }

    TColumnDateTime::TColumnDateTime()
        : TColumn(TType::CreateDateTime())
        , Data_(TColumnUInt32::Create())
    {
    }

    TColumnDateTime::TColumnDateTime(const TVector<TInstant>& data)
        : TColumnDateTime()
    {
        for (const auto& value : data) {
            Append(value);
        }
    }

    TIntrusivePtr<TColumnDateTime> TColumnDateTime::Create() {
        return new TColumnDateTime();
    }

    TIntrusivePtr<TColumnDateTime> TColumnDateTime::Create(const TVector<TInstant>& data) {
        return new TColumnDateTime(data);
    }

    void TColumnDateTime::Append(const TInstant& value) {
        Data_->Append(static_cast<ui32>(value.Seconds()));
    }

    std::time_t TColumnDateTime::At(size_t n) const {
        return Data_->At(n);
    }

    void TColumnDateTime::SetAt(size_t n, const TInstant& value) {
        Data_->SetAt(n, static_cast<ui32>(value.Seconds()));
    }

    void TColumnDateTime::Append(TColumnRef column) {
        if (auto col = column->As<TColumnDateTime>()) {
            Data_->Append(col->Data_);
        }
    }

    bool TColumnDateTime::Load(TCodedInputStream* input, size_t rows) {
        return Data_->Load(input, rows);
    }

    void TColumnDateTime::Save(TCodedOutputStream* output) {
        Data_->Save(output);
    }

    size_t TColumnDateTime::Size() const {
        return Data_->Size();
    }

    TColumnRef TColumnDateTime::Slice(size_t begin, size_t len) {
        auto col = Data_->Slice(begin, len)->As<TColumnUInt32>();
        auto result = TColumnDateTime::Create();

        result->Data_->Append(col);

        return result;
    }

}