Skip to content

Commit b6009a6

Browse files
committed
Feedback from review
1 parent 6c79915 commit b6009a6

File tree

3 files changed

+53
-39
lines changed

3 files changed

+53
-39
lines changed

tiledb/sm/serialization/query.cc

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -271,33 +271,35 @@ Subarray subarray_from_capnp(
271271
auto ranges_reader = reader.getRanges();
272272

273273
uint32_t dim_num = ranges_reader.size();
274-
std::vector<RangeSetAndSuperset> range_subset(dim_num);
274+
std::vector<RangeSetAndSuperset> range_subset;
275+
range_subset.reserve(dim_num);
275276
std::vector<bool> is_default(dim_num, false);
276277
for (uint32_t i = 0; i < dim_num; i++) {
277278
auto range_reader = ranges_reader[i];
278-
Datatype type = Datatype::UINT8;
279-
throw_if_not_ok(datatype_enum(range_reader.getType(), &type));
279+
Datatype type = datatype_enum(range_reader.getType());
280280
auto dim = array->array_schema_latest().dimension_ptr(i);
281281

282-
bool implicitly_initialized = range_reader.getHasDefaultRange();
283-
range_subset[i] = RangeSetAndSuperset(
284-
dim->type(), dim->domain(), implicitly_initialized, coalesce_ranges);
285-
is_default[i] = implicitly_initialized;
286-
if (range_reader.hasBufferSizes()) {
287-
auto ranges = range_buffers_from_capnp(range_reader);
282+
is_default[i] = range_reader.getHasDefaultRange();
283+
if (is_default[i]) {
288284
// If the range is implicitly initialized, the RangeSetAndSuperset
289285
// constructor will initialize the ranges to the domain.
290-
if (!implicitly_initialized) {
286+
range_subset.emplace_back(
287+
type, dim->domain(), is_default[i], coalesce_ranges);
288+
} else {
289+
std::vector<Range> ranges;
290+
if (range_reader.hasBufferSizes()) {
291+
ranges = range_buffers_from_capnp(range_reader);
291292
// Add custom ranges, clearing any implicit ranges previously set.
292-
range_subset[i] = RangeSetAndSuperset(
293-
dim->type(), dim->domain(), ranges, coalesce_ranges);
293+
range_subset.emplace_back(
294+
type, dim->domain(), std::move(ranges), coalesce_ranges);
295+
} else {
296+
// Handle 1.7 style ranges where there is a single range with no sizes
297+
auto data = range_reader.getBuffer();
298+
auto data_ptr = data.asBytes();
299+
ranges.emplace_back(data_ptr.begin(), data.size());
300+
range_subset.emplace_back(
301+
type, dim->domain(), std::move(ranges), coalesce_ranges);
294302
}
295-
} else {
296-
// Handle 1.7 style ranges where there is a single range with no sizes
297-
auto data = range_reader.getBuffer();
298-
auto data_ptr = data.asBytes();
299-
Range range(data_ptr.begin(), data.size());
300-
throw_if_not_ok(range_subset[i].add_range_unrestricted(range));
301303
}
302304
}
303305

tiledb/sm/subarray/range_subset.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ RangeSetAndSuperset::RangeSetAndSuperset(
135135
RangeSetAndSuperset::RangeSetAndSuperset(
136136
Datatype datatype,
137137
const Range& superset,
138-
std::vector<Range> subset,
138+
std::vector<Range>&& subset,
139139
bool coalesce_ranges)
140-
: RangeSetAndSuperset(datatype, superset, false, coalesce_ranges) {
141-
ranges_ = std::move(subset);
140+
: impl_(range_subset_internals(datatype, superset, coalesce_ranges))
141+
, is_implicitly_initialized_(false)
142+
, ranges_(subset) {
142143
}
143144

144145
void RangeSetAndSuperset::sort_and_merge_ranges(
@@ -171,6 +172,13 @@ tuple<Status, optional<std::string>> RangeSetAndSuperset::add_range(
171172
}
172173
}
173174

175+
void RangeSetAndSuperset::check_oob() {
176+
for (auto& range : ranges_) {
177+
impl_->check_range_is_valid(range);
178+
throw_if_not_ok(impl_->check_range_is_subset(range));
179+
}
180+
}
181+
174182
Status RangeSetAndSuperset::add_range_unrestricted(const Range& range) {
175183
if (is_implicitly_initialized_) {
176184
ranges_.clear();
@@ -179,11 +187,4 @@ Status RangeSetAndSuperset::add_range_unrestricted(const Range& range) {
179187
return impl_->add_range(ranges_, range);
180188
}
181189

182-
void RangeSetAndSuperset::check_oob() {
183-
for (auto& range : ranges_) {
184-
impl_->check_range_is_valid(range);
185-
throw_if_not_ok(impl_->check_range_is_subset(range));
186-
}
187-
}
188-
189190
} // namespace tiledb::sm

tiledb/sm/subarray/range_subset.h

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ class TypedRangeSetAndFullsetImpl<std::string, CoalesceAdds>
419419
*/
420420
class RangeSetAndSuperset {
421421
public:
422+
/** Friend Subarray for calling `add_range_unrestricted` */
423+
friend class Subarray;
424+
422425
/* ********************************* */
423426
/* CONSTRUCTORS & DESTRUCTORS */
424427
/* ********************************* */
@@ -453,7 +456,7 @@ class RangeSetAndSuperset {
453456
RangeSetAndSuperset(
454457
Datatype datatype,
455458
const Range& superset,
456-
std::vector<Range> subset,
459+
std::vector<Range>&& subset,
457460
bool coalesce_ranges);
458461

459462
/** Destructor. */
@@ -484,16 +487,6 @@ class RangeSetAndSuperset {
484487
tuple<Status, optional<std::string>> add_range(
485488
Range& range, const bool read_range_oob_error = true);
486489

487-
/**
488-
* Adds a range to the range manager without performing any checkes.
489-
*
490-
* If the ranges are currently implicitly initialized, then they will be
491-
* cleared before the new range is added.
492-
*
493-
* @param range The range to add.
494-
*/
495-
Status add_range_unrestricted(const Range& range);
496-
497490
/**
498491
* Removes all ranges.
499492
*
@@ -559,6 +552,10 @@ class RangeSetAndSuperset {
559552
void sort_and_merge_ranges(ThreadPool* const compute_tp, bool merge = false);
560553

561554
private:
555+
/* ********************************* */
556+
/* PRIVATE ATTRIBUTES */
557+
/* ********************************* */
558+
562559
/** Pointer to typed implementation details. */
563560
shared_ptr<detail::RangeSetAndSupersetImpl> impl_ = nullptr;
564561

@@ -571,6 +568,20 @@ class RangeSetAndSuperset {
571568

572569
/** Stored ranges. */
573570
std::vector<Range> ranges_{};
571+
572+
/* ********************************* */
573+
/* PRIVATE METHODS */
574+
/* ********************************* */
575+
576+
/**
577+
* Adds a range to the range manager without performing any checkes.
578+
*
579+
* If the ranges are currently implicitly initialized, then they will be
580+
* cleared before the new range is added.
581+
*
582+
* @param range The range to add.
583+
*/
584+
Status add_range_unrestricted(const Range& range);
574585
};
575586

576587
} // namespace tiledb::sm

0 commit comments

Comments
 (0)