This repository was archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathColumnStoreUtil.hpp
More file actions
234 lines (195 loc) · 7.62 KB
/
ColumnStoreUtil.hpp
File metadata and controls
234 lines (195 loc) · 7.62 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
/**
* Copyright 2011-2015 Quickstep Technologies LLC.
* Copyright 2015 Pivotal Software, Inc.
*
* Licensed 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_COLUMN_STORE_UTIL_HPP_
#define QUICKSTEP_STORAGE_COLUMN_STORE_UTIL_HPP_
#include <cstddef>
#include <iterator>
#include "catalog/CatalogTypedefs.hpp"
#include "storage/StorageBlockInfo.hpp"
#include "utility/Macros.hpp"
namespace quickstep {
class BasicColumnStoreTupleStorageSubBlock;
class CatalogRelationSchema;
class ComparisonPredicate;
class CompressedColumnStoreTupleStorageSubBlock;
class TupleIdSequence;
namespace column_store_util {
/** \addtogroup Storage
* @{
*/
/**
* @brief An iterator over the values in a column stripe. Used internally by
* BasicColumnStoreTupleStorageSubBlock and
* CompressedColumnStoreTupleStorageSubBlock.
**/
class ColumnStripeIterator : public std::iterator<std::random_access_iterator_tag, void*> {
public:
typedef std::iterator<std::random_access_iterator_tag, void*>::difference_type difference_type;
ColumnStripeIterator()
: stripe_start_(NULL),
attr_length_(0),
tuple_position_(0) {
}
ColumnStripeIterator(const ColumnStripeIterator &other)
: stripe_start_(other.stripe_start_),
attr_length_(other.attr_length_),
tuple_position_(other.tuple_position_) {
}
ColumnStripeIterator& operator=(const ColumnStripeIterator& other) = default;
// Comparisons.
inline bool operator==(const ColumnStripeIterator& other) const {
DEBUG_ASSERT(stripe_start_ == other.stripe_start_);
DEBUG_ASSERT(attr_length_ == other.attr_length_);
return tuple_position_ == other.tuple_position_;
}
inline bool operator!=(const ColumnStripeIterator& other) const {
DEBUG_ASSERT(stripe_start_ == other.stripe_start_);
DEBUG_ASSERT(attr_length_ == other.attr_length_);
return tuple_position_ != other.tuple_position_;
}
inline bool operator<(const ColumnStripeIterator& other) const {
DEBUG_ASSERT(stripe_start_ == other.stripe_start_);
DEBUG_ASSERT(attr_length_ == other.attr_length_);
return tuple_position_ < other.tuple_position_;
}
inline bool operator<=(const ColumnStripeIterator& other) const {
DEBUG_ASSERT(stripe_start_ == other.stripe_start_);
DEBUG_ASSERT(attr_length_ == other.attr_length_);
return tuple_position_ <= other.tuple_position_;
}
inline bool operator>(const ColumnStripeIterator& other) const {
DEBUG_ASSERT(stripe_start_ == other.stripe_start_);
DEBUG_ASSERT(attr_length_ == other.attr_length_);
return tuple_position_ > other.tuple_position_;
}
inline bool operator>=(const ColumnStripeIterator& other) const {
DEBUG_ASSERT(stripe_start_ == other.stripe_start_);
DEBUG_ASSERT(attr_length_ == other.attr_length_);
return tuple_position_ >= other.tuple_position_;
}
// Increment/decrement.
inline ColumnStripeIterator& operator++() {
++tuple_position_;
return *this;
}
ColumnStripeIterator operator++(int) {
ColumnStripeIterator result(*this);
++(*this);
return result;
}
inline ColumnStripeIterator& operator--() {
--tuple_position_;
return *this;
}
ColumnStripeIterator operator--(int) {
ColumnStripeIterator result(*this);
--(*this);
return result;
}
// Compound assignment.
inline ColumnStripeIterator& operator+=(difference_type n) {
tuple_position_ += n;
return *this;
}
inline ColumnStripeIterator& operator-=(difference_type n) {
tuple_position_ -= n;
return *this;
}
// Note: + operator with difference_type on the left is not defined.
ColumnStripeIterator operator+(difference_type n) const {
return ColumnStripeIterator(stripe_start_, attr_length_, tuple_position_ + n);
}
ColumnStripeIterator operator-(difference_type n) const {
return ColumnStripeIterator(stripe_start_, attr_length_, tuple_position_ - n);
}
difference_type operator-(const ColumnStripeIterator &other) const {
DEBUG_ASSERT(stripe_start_ == other.stripe_start_);
DEBUG_ASSERT(attr_length_ == other.attr_length_);
return tuple_position_ - other.tuple_position_;
}
// Dereference.
inline void* operator*() const {
return static_cast<char*>(stripe_start_) + tuple_position_ * attr_length_;
}
inline void** operator->() const {
FATAL_ERROR("-> dereference operator unimplemented for ColumnStripeIterator.");
}
void* operator[](difference_type n) const {
return static_cast<char*>(stripe_start_) + (tuple_position_ + n) * attr_length_;
}
tuple_id getTuplePosition() const {
return tuple_position_;
}
private:
ColumnStripeIterator(void *stripe_start,
const std::size_t attr_length,
const tuple_id tuple_position)
: stripe_start_(stripe_start),
attr_length_(attr_length),
tuple_position_(tuple_position) {
}
void *stripe_start_;
std::size_t attr_length_;
tuple_id tuple_position_;
friend class quickstep::BasicColumnStoreTupleStorageSubBlock;
friend class SortColumnPredicateEvaluator;
};
/**
* @brief A class which contains static helper methods for predicate evaluation
* on the sort column of a BasicColumnStoreTupleStorageSubBlock or a
* CompressedColumnStoreTupleStorageSubBlock.
**/
class SortColumnPredicateEvaluator {
public:
/**
* @brief Attempt to evaluate a predicate on an uncompressed sorted column of
* a BasicColumnStoreTupleStorageSubBlock or
* CompressedColumnStoreTupleStorageSubBlock.
* @note Currently this method can only evaluate a simple comparison of a
* literal value with the value of a sort attribute. It will return
* NULL if called with a predicate it does not know how to evaluate.
*
* @param predicate A predicate to attempt to evaluate.
* @param relation The relation which the TupleStorageSubBlock which uses
* this method belongs to.
* @param sort_attribute_id The ID of the sort column attribute in relation.
* @param sort_column_stripe A sorted, packed, and uncompressed column stripe
* of values belonging to the attribute with sort_attribute_id in
* relation.
* @param num_tuples The number of tuples in the TupleStorageSubBlock which
* uses this method (i.e. the number of values in sort_column_stripe).
* @return A sequence of tuple_ids which match predicate, or NULL if this
* method is unable to evaluate predicate (in which case the default
* TupleStorageSubBlock::getMatchesForPredicate() method should be
* used as a fallback).
**/
static TupleIdSequence* EvaluatePredicateForUncompressedSortColumn(
const ComparisonPredicate &predicate,
const CatalogRelationSchema &relation,
const attribute_id sort_attribute_id,
void *sort_attribute_stripe,
const tuple_id num_tuples);
private:
// Undefined default constructor - class is all static and should not be
// instantiated.
SortColumnPredicateEvaluator();
DISALLOW_COPY_AND_ASSIGN(SortColumnPredicateEvaluator);
};
/** @} */
} // namespace column_store_util
} // namespace quickstep
#endif // QUICKSTEP_STORAGE_COLUMN_STORE_UTIL_HPP_