-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathColumnWriter.hpp
More file actions
234 lines (186 loc) · 6.82 KB
/
ColumnWriter.hpp
File metadata and controls
234 lines (186 loc) · 6.82 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#ifndef CLP_S_COLUMNWRITER_HPP
#define CLP_S_COLUMNWRITER_HPP
#include <cstddef>
#include <cstdint>
#include <memory>
#include <utility>
#include <vector>
#include <clp/Defs.h>
#include <clp_s/DictionaryEntry.hpp>
#include <clp_s/DictionaryWriter.hpp>
#include <clp_s/FloatFormatEncoding.hpp>
#include <clp_s/ParsedMessage.hpp>
#include <clp_s/ZstdCompressor.hpp>
namespace clp_s {
class BaseColumnWriter {
public:
// Constructors
BaseColumnWriter() = default;
BaseColumnWriter(BaseColumnWriter const&) = default;
BaseColumnWriter(BaseColumnWriter&&) noexcept = default;
// Operators
auto operator=(BaseColumnWriter const&) -> BaseColumnWriter& = default;
auto operator=(BaseColumnWriter&&) noexcept -> BaseColumnWriter& = default;
// Destructor
virtual ~BaseColumnWriter() = default;
// Methods
/**
* Adds a value to the column
* @param value
* @return the size of the encoded data appended to this column in bytes
*/
virtual auto add_value(ParsedMessage::variable_t& value) -> size_t = 0;
/**
* Stores the column to a compressed file.
* @param compressor
*/
virtual auto store(ZstdCompressor& compressor) -> void = 0;
/**
* Returns the total size of the header data that will be written to the compressor. This header
* size plus the sum of sizes returned by add_value is equal to the total size of data that will
* be written to the compressor in bytes.
*
* @return the total size of header data that will be written to the compressor in bytes
*/
[[nodiscard]] virtual auto get_total_header_size() const -> size_t { return 0; }
};
class Int64ColumnWriter : public BaseColumnWriter {
public:
// Methods implementing BaseColumnWriter
auto add_value(ParsedMessage::variable_t& value) -> size_t override;
auto store(ZstdCompressor& compressor) -> void override;
private:
// Variables
std::vector<int64_t> m_values;
};
class DeltaEncodedInt64ColumnWriter : public BaseColumnWriter {
public:
// Methods implementing BaseColumnWriter
auto add_value(ParsedMessage::variable_t& value) -> size_t override;
auto store(ZstdCompressor& compressor) -> void override;
// Methods
[[nodiscard]] auto add_value(int64_t value) -> size_t;
private:
// Variables
std::vector<int64_t> m_values;
int64_t m_cur{};
};
class FloatColumnWriter : public BaseColumnWriter {
public:
// Methods implementing BaseColumnWriter
auto add_value(ParsedMessage::variable_t& value) -> size_t override;
auto store(ZstdCompressor& compressor) -> void override;
private:
// Variables
std::vector<double> m_values;
};
class FormattedFloatColumnWriter : public BaseColumnWriter {
public:
// Methods implementing BaseColumnWriter
auto add_value(ParsedMessage::variable_t& value) -> size_t override;
auto store(ZstdCompressor& compressor) -> void override;
private:
// Variables
std::vector<double> m_values;
std::vector<float_format_t> m_formats;
};
class DictionaryFloatColumnWriter : public BaseColumnWriter {
public:
// Constructors
explicit DictionaryFloatColumnWriter(std::shared_ptr<VariableDictionaryWriter> var_dict)
: m_var_dict(std::move(var_dict)) {}
// Methods implementing BaseColumnWriter
auto add_value(ParsedMessage::variable_t& value) -> size_t override;
auto store(ZstdCompressor& compressor) -> void override;
private:
// Variables
std::shared_ptr<VariableDictionaryWriter> m_var_dict;
std::vector<clp::variable_dictionary_id_t> m_var_dict_ids;
};
class BooleanColumnWriter : public BaseColumnWriter {
public:
// Methods implementing BaseColumnWriter
auto add_value(ParsedMessage::variable_t& value) -> size_t override;
auto store(ZstdCompressor& compressor) -> void override;
private:
// Variables
std::vector<uint8_t> m_values;
};
class ClpStringColumnWriter : public BaseColumnWriter {
public:
// Types
using encoded_log_dict_id_t = uint64_t;
// Constructors
ClpStringColumnWriter(
std::shared_ptr<VariableDictionaryWriter> var_dict,
std::shared_ptr<LogTypeDictionaryWriter> log_dict
)
: m_var_dict(std::move(var_dict)),
m_log_dict(std::move(log_dict)) {}
// Methods implementing BaseColumnWriter
auto add_value(ParsedMessage::variable_t& value) -> size_t override;
auto store(ZstdCompressor& compressor) -> void override;
// Methods
[[nodiscard]] auto get_total_header_size() const -> size_t override { return sizeof(size_t); }
/**
* @param encoded_id
* @return the encoded log dict id
*/
static auto get_encoded_log_dict_id(encoded_log_dict_id_t encoded_id)
-> clp::logtype_dictionary_id_t {
return static_cast<clp::logtype_dictionary_id_t>(encoded_id & cLogDictIdMask);
}
/**
* @param encoded_id
* @return The encoded offset
*/
static auto get_encoded_offset(encoded_log_dict_id_t encoded_id) -> uint64_t {
return (encoded_id & cOffsetMask) >> cOffsetBitPosition;
}
private:
// Methods
/**
* Encodes a log dict id
* @param id
* @param offset
* @return The encoded log dict id
*/
static auto encode_log_dict_id(clp::logtype_dictionary_id_t id, uint64_t offset)
-> encoded_log_dict_id_t {
return static_cast<encoded_log_dict_id_t>(id) | (offset << cOffsetBitPosition);
}
// Variables
static constexpr int cOffsetBitPosition = 24;
static constexpr uint64_t cLogDictIdMask = (1ULL << cOffsetBitPosition) - 1;
static constexpr uint64_t cOffsetMask = ~cLogDictIdMask;
std::shared_ptr<VariableDictionaryWriter> m_var_dict;
std::shared_ptr<LogTypeDictionaryWriter> m_log_dict;
LogTypeDictionaryEntry m_logtype_entry;
std::vector<encoded_log_dict_id_t> m_logtypes;
std::vector<clp::encoded_variable_t> m_encoded_vars;
};
class VariableStringColumnWriter : public BaseColumnWriter {
public:
// Constructors
explicit VariableStringColumnWriter(std::shared_ptr<VariableDictionaryWriter> var_dict)
: m_var_dict(std::move(var_dict)) {}
// Methods implementing BaseColumnWriter
auto add_value(ParsedMessage::variable_t& value) -> size_t override;
auto store(ZstdCompressor& compressor) -> void override;
private:
// Variables
std::shared_ptr<VariableDictionaryWriter> m_var_dict;
std::vector<clp::variable_dictionary_id_t> m_var_dict_ids;
};
class TimestampColumnWriter : public BaseColumnWriter {
public:
// Methods implementing BaseColumnWriter
auto add_value(ParsedMessage::variable_t& value) -> size_t override;
auto store(ZstdCompressor& compressor) -> void override;
private:
// Variables
DeltaEncodedInt64ColumnWriter m_timestamps;
std::vector<uint64_t> m_timestamp_encodings;
};
} // namespace clp_s
#endif // CLP_S_COLUMNWRITER_HPP