forked from ClickHouse/clickhouse-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate.h
More file actions
149 lines (101 loc) · 3.81 KB
/
date.h
File metadata and controls
149 lines (101 loc) · 3.81 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#pragma once
#include "decimal.h"
#include "numeric.h"
#include <ctime>
namespace clickhouse {
/** */
class ColumnDate : public Column {
public:
using ValueType = std::time_t;
ColumnDate();
/// Appends one element to the end of column.
/// TODO: The implementation is fundamentally wrong.
void Append(const std::time_t& value);
/// Returns element at given row number.
/// TODO: The implementation is fundamentally wrong.
std::time_t At(size_t n) const;
/// Appends content of given column to the end of current one.
void Append(ColumnRef column) override;
/// Loads column data from input stream.
bool LoadBody(InputStream* input, size_t rows) override;
/// Saves column data to output stream.
void SaveBody(OutputStream* output) override;
/// Clear column data .
void Clear() override;
/// Returns count of rows in the column.
size_t Size() const override;
/// Makes slice of the current column.
ColumnRef Slice(size_t begin, size_t len) const override;
void Swap(Column& other) override;
ItemView GetItem(size_t index) const override;
private:
std::shared_ptr<ColumnUInt16> data_;
};
/** */
class ColumnDateTime : public Column {
public:
using ValueType = std::time_t;
ColumnDateTime();
explicit ColumnDateTime(std::string timezone);
/// Appends one element to the end of column.
void Append(const std::time_t& value);
/// Returns element at given row number.
std::time_t At(size_t n) const;
/// Timezone associated with a data column.
std::string Timezone() const;
public:
/// Appends content of given column to the end of current one.
void Append(ColumnRef column) override;
/// Loads column data from input stream.
bool LoadBody(InputStream* input, size_t rows) override;
/// Clear column data .
void Clear() override;
/// Saves column data to output stream.
void SaveBody(OutputStream* output) override;
/// Returns count of rows in the column.
size_t Size() const override;
/// Makes slice of the current column.
ColumnRef Slice(size_t begin, size_t len) const override;
void Swap(Column& other) override;
ItemView GetItem(size_t index) const override;
private:
std::shared_ptr<ColumnUInt32> data_;
};
/** */
class ColumnDateTime64 : public Column {
public:
using ValueType = Int64;
explicit ColumnDateTime64(size_t precision);
ColumnDateTime64(size_t precision, std::string timezone);
/// Appends one element to the end of column.
void Append(const Int64& value);
// It is a bit controversal: users might expect it to parse string of ISO8601 or some other human-friendly format,
// but current implemntation parses it as fractional integer with decimal point, e.g. "123.456".
// void Append(const std::string& value);
/// Returns element at given row number.
Int64 At(size_t n) const;
/// Timezone associated with a data column.
std::string Timezone() const;
public:
/// Appends content of given column to the end of current one.
void Append(ColumnRef column) override;
/// Loads column data from input stream.
bool LoadBody(InputStream* input, size_t rows) override;
/// Clear column data .
void Clear() override;
/// Saves column data to output stream.
void SaveBody(OutputStream* output) override;
/// Returns count of rows in the column.
size_t Size() const override;
/// Makes slice of the current column.
ColumnRef Slice(size_t begin, size_t len) const override;
void Swap(Column& other) override;
ItemView GetItem(size_t index) const override;
size_t GetPrecision() const;
private:
ColumnDateTime64(TypeRef type, std::shared_ptr<ColumnDecimal> data);
private:
std::shared_ptr<ColumnDecimal> data_;
const size_t precision_;
};
}