forked from UWQuickstep/quickstep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompressedColumnStoreValueAccessor.hpp
200 lines (178 loc) · 7.84 KB
/
CompressedColumnStoreValueAccessor.hpp
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
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
**/
#ifndef QUICKSTEP_STORAGE_COMPRESSED_COLUMN_STORE_VALUE_ACCESSOR_HPP_
#define QUICKSTEP_STORAGE_COMPRESSED_COLUMN_STORE_VALUE_ACCESSOR_HPP_
#include <cstddef>
#include <cstdint>
#include <vector>
#include "catalog/CatalogRelationSchema.hpp"
#include "catalog/CatalogTypedefs.hpp"
#include "compression/CompressionDictionaryLite.hpp"
#include "storage/StorageBlockInfo.hpp"
#include "storage/StorageBlockLayout.pb.h"
#include "storage/ValueAccessor.hpp"
#include "types/Type.hpp"
#include "types/TypedValue.hpp"
#include "utility/BitVector.hpp"
#include "utility/Macros.hpp"
#include "utility/PtrMap.hpp"
namespace quickstep {
class CompressedColumnStoreTupleStorageSubBlock;
class CompressedColumnStoreValueAccessorHelper {
public:
CompressedColumnStoreValueAccessorHelper(
const CatalogRelationSchema &relation,
const tuple_id num_tuples,
const CompressedBlockInfo &compression_info,
const std::vector<bool> &dictionary_coded_attributes,
const std::vector<bool> &truncated_attributes,
const std::vector<bool> &truncated_attribute_is_int,
const PtrMap<attribute_id, CompressionDictionaryLite> &dictionaries,
const std::vector<void*> &column_stripes,
const PtrVector<BitVector<false>, true> &uncompressed_column_null_bitmaps)
: relation_(relation),
num_tuples_(num_tuples),
compression_info_(compression_info),
dictionary_coded_attributes_(dictionary_coded_attributes),
truncated_attributes_(truncated_attributes),
truncated_attribute_is_int_(truncated_attribute_is_int),
dictionaries_(dictionaries),
column_stripes_(column_stripes),
uncompressed_column_null_bitmaps_(uncompressed_column_null_bitmaps) {
}
inline tuple_id numPackedTuples() const {
return num_tuples_;
}
/**
* @brief Returns whether this accessor has a fast strided ColumnAccessor available
* that can be used to optimize memory access in a tight loop iteration
* over the underlying storage block.
*
* @return true if fast ColumnAccessor is supported, otherwise false.
*/
inline bool isColumnAccessorSupported() const {
return false;
}
/**
* @brief Get a pointer to a ColumnAccessor object that provides a fast strided memory
* access on the underlying storage block.
* @note The ownership of the returned object lies with the caller.
* @warning This method should only be called if isColumnAccessorSupported() method
* returned true. If ColumnAccessor is not supported this method will return a nullptr.
*
* @param current_tuple_position A constant reference to the tuple position in the containing
* ValueAccessor. This reference value is shared between the containing ValueAccessor &
* a ColumnAccessor. However, a ColumnAccessor *CANNOT* modify this tuple position.
* @param attr_id The attribute id on which this ColumnAccessor will be created.
*
* @return A pointer to a ColumnAccessor object with specific properties set that can be used
* in a tight loop iterations over the underlying storage block.
**/
template <bool check_null = true>
inline const ColumnAccessor<check_null>* getColumnAccessor(const tuple_id ¤t_tuple_position,
const attribute_id attr_id) const {
// Return nullptr because this value accessor does not support column accessor yet.
return nullptr;
}
template <bool check_null>
inline const void* getAttributeValue(const tuple_id tuple,
const attribute_id attr) const {
if (dictionary_coded_attributes_[attr]) {
return dictionaries_.atUnchecked(attr).getUntypedValueForCode<check_null>(
getCode(tuple, attr));
} else if (truncated_attributes_[attr]) {
if (truncated_attribute_is_int_[attr]) {
int_buffer_ = getCode(tuple, attr);
return &int_buffer_;
} else {
long_buffer_ = getCode(tuple, attr);
return &long_buffer_;
}
} else {
return getAttributePtr<check_null>(tuple, attr);
}
}
inline TypedValue getAttributeValueTyped(const tuple_id tuple,
const attribute_id attr) const {
if (dictionary_coded_attributes_[attr]) {
return dictionaries_.atUnchecked(attr).getTypedValueForCode(
getCode(tuple, attr));
} else if (truncated_attributes_[attr]) {
if (truncated_attribute_is_int_[attr]) {
return TypedValue(static_cast<int>(getCode(tuple, attr)));
} else {
return TypedValue(static_cast<std::int64_t>(getCode(tuple, attr)));
}
} else {
const Type &attr_type = relation_.getAttributeById(attr)->getType();
const void *untyped_value = getAttributePtr<true>(tuple, attr);
return (untyped_value == nullptr)
? attr_type.makeNullValue()
: attr_type.makeValue(untyped_value, attr_type.maximumByteLength());
}
}
private:
template <bool check_null>
inline const void* getAttributePtr(const tuple_id tid,
const attribute_id attr_id) const {
if (check_null
&& compression_info_.uncompressed_attribute_has_nulls(attr_id)
&& uncompressed_column_null_bitmaps_[attr_id].getBit(tid)) {
return nullptr;
} else {
return static_cast<const char*>(column_stripes_[attr_id])
+ tid * compression_info_.attribute_size(attr_id);
}
}
inline std::uint32_t getCode(const tuple_id tid,
const attribute_id attr_id) const {
const void *code_location = getAttributePtr<false>(tid, attr_id);
switch (compression_info_.attribute_size(attr_id)) {
case 1:
return *static_cast<const std::uint8_t*>(code_location);
case 2:
return *static_cast<const std::uint16_t*>(code_location);
case 4:
return *static_cast<const std::uint32_t*>(code_location);
default:
FATAL_ERROR("Unexpected byte-length (not 1, 2, or 4) for compressed "
"attribute ID " << attr_id
<< " in CompressedColumnStoreValueAccessorHelper::getCode()");
}
}
const CatalogRelationSchema &relation_;
const tuple_id num_tuples_;
const CompressedBlockInfo &compression_info_;
const std::vector<bool> &dictionary_coded_attributes_;
const std::vector<bool> &truncated_attributes_;
const std::vector<bool> &truncated_attribute_is_int_;
const PtrMap<attribute_id, CompressionDictionaryLite> &dictionaries_;
const std::vector<void*> &column_stripes_;
const PtrVector<BitVector<false>, true> &uncompressed_column_null_bitmaps_;
mutable int int_buffer_;
mutable std::int64_t long_buffer_;
DISALLOW_COPY_AND_ASSIGN(CompressedColumnStoreValueAccessorHelper);
};
typedef PackedTupleStorageSubBlockValueAccessor<
CompressedColumnStoreTupleStorageSubBlock,
CompressedColumnStoreValueAccessorHelper,
ValueAccessor::Implementation::kCompressedColumnStore>
CompressedColumnStoreValueAccessor;
} // namespace quickstep
#endif // QUICKSTEP_STORAGE_COMPRESSED_COLUMN_STORE_VALUE_ACCESSOR_HPP_