From 89f6aec0bc4c8c9bcd1865a39eb220ce5abbfa2c Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Wed, 31 Jan 2024 16:48:37 -0500 Subject: [PATCH] Fix test --- tiledb/sm/serialization/query.cc | 16 +++++++++------- tiledb/sm/subarray/range_subset.cc | 10 ++++++++++ tiledb/sm/subarray/range_subset.h | 20 ++++++++++++++++++-- tiledb/sm/subarray/subarray.cc | 10 ++++++++++ tiledb/sm/subarray/subarray.h | 14 ++++++++++++++ 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/tiledb/sm/serialization/query.cc b/tiledb/sm/serialization/query.cc index ec81144a5493..6d255657483a 100644 --- a/tiledb/sm/serialization/query.cc +++ b/tiledb/sm/serialization/query.cc @@ -295,11 +295,11 @@ Subarray subarray_from_capnp( // Edge case for dimension labels where there are only label ranges set. if (ranges.empty()) { range_subset[i] = RangeSetAndSuperset( - dim->type(), dim->domain(), false, coalesce_ranges); - } - // Add custom ranges, clearing any implicit ranges previously set. - for (const auto& range : ranges) { - throw_if_not_ok(range_subset[i].add_range_unrestricted(range)); + dim->type(), dim->domain(), {dim->domain()}, coalesce_ranges); + } else { + // Add custom ranges, clearing any implicit ranges previously set. + range_subset[i] = RangeSetAndSuperset( + dim->type(), dim->domain(), ranges, coalesce_ranges); } } } else { @@ -324,11 +324,13 @@ Subarray subarray_from_capnp( // Deserialize ranges for this dim label auto range_reader = label_range_reader.getRanges(); - auto ranges = range_buffers_from_capnp(range_reader); + auto label_ranges = range_buffers_from_capnp(range_reader); // Set ranges for this dim label on the subarray label_range_subset[dim_index] = { - label_name, dim->type(), coalesce_ranges}; + label_name, dim->type(), label_ranges, coalesce_ranges}; + range_subset[dim_index].clear(); + is_default[dim_index] = false; } } diff --git a/tiledb/sm/subarray/range_subset.cc b/tiledb/sm/subarray/range_subset.cc index 7aa6df657c5d..59822b7a37a6 100644 --- a/tiledb/sm/subarray/range_subset.cc +++ b/tiledb/sm/subarray/range_subset.cc @@ -33,6 +33,7 @@ #include "tiledb/sm/subarray/range_subset.h" #include +#include using namespace tiledb::common; using namespace tiledb::type; @@ -131,6 +132,15 @@ RangeSetAndSuperset::RangeSetAndSuperset( ranges_.emplace_back(superset); } +RangeSetAndSuperset::RangeSetAndSuperset( + Datatype datatype, + const Range& superset, + std::vector subset, + bool coalesce_ranges) + : RangeSetAndSuperset(datatype, superset, false, coalesce_ranges) { + ranges_ = std::move(subset); +} + void RangeSetAndSuperset::sort_and_merge_ranges( ThreadPool* const compute_tp, bool merge) { if (ranges_.empty()) { diff --git a/tiledb/sm/subarray/range_subset.h b/tiledb/sm/subarray/range_subset.h index 16b12ab44713..f8b702b1ffeb 100644 --- a/tiledb/sm/subarray/range_subset.h +++ b/tiledb/sm/subarray/range_subset.h @@ -429,10 +429,11 @@ class RangeSetAndSuperset { /** General constructor * * @param datatype The TileDB datatype of of the ranges. + * @param superset The superset of ranges to initialize the range set. * @param implicitly_initialize If ``true``, set the ranges to contain the - * full superset until a new range is explicitly added. + * full superset until a new range is explicitly added. * @param coalesce_ranges If ``true``, when adding a new range, attempt to - * combine with the first left-adjacent range found. + * combine with the first left-adjacent range found. **/ RangeSetAndSuperset( Datatype datatype, @@ -440,6 +441,21 @@ class RangeSetAndSuperset { bool implicitly_initialize, bool coalesce_ranges); + /** + * Constructor. + * + * @param datatype The TileDB datatype of of the ranges. + * @param superset The superset of ranges to initialize the range set. + * @param subset The subset of ranges to initialize the range set. + * @param coalesce_ranges If ``true``, when adding a new range, attempt to + * combine with the first left-adjacent range found. + **/ + RangeSetAndSuperset( + Datatype datatype, + const Range& superset, + std::vector subset, + bool coalesce_ranges); + /** Destructor. */ ~RangeSetAndSuperset() = default; diff --git a/tiledb/sm/subarray/subarray.cc b/tiledb/sm/subarray/subarray.cc index d9d87b797c9a..fb54059e746d 100644 --- a/tiledb/sm/subarray/subarray.cc +++ b/tiledb/sm/subarray/subarray.cc @@ -3260,5 +3260,15 @@ Subarray::LabelRangeSubset::LabelRangeSubset( , ranges_{RangeSetAndSuperset(type, Range(), false, coalesce_ranges)} { } +Subarray::LabelRangeSubset::LabelRangeSubset( + const std::string& name, + Datatype type, + std::vector ranges, + bool coalesce_ranges) + : name_{name} + , ranges_{RangeSetAndSuperset( + type, Range(), std::move(ranges), coalesce_ranges)} { +} + } // namespace sm } // namespace tiledb diff --git a/tiledb/sm/subarray/subarray.h b/tiledb/sm/subarray/subarray.h index 6f4ff939a13d..3ad1abc68c97 100644 --- a/tiledb/sm/subarray/subarray.h +++ b/tiledb/sm/subarray/subarray.h @@ -234,6 +234,20 @@ class Subarray { LabelRangeSubset( const std::string& name, Datatype type, bool coalesce_ranges = true); + /** + * Constructor + * + * @param name The name of the dimension label the ranges will be set on. + * @param type The type of the label the ranges will be set on. + * @param ranges The range subset for the dimension label. + * @param coalesce_ranges Set if ranges should be combined when adjacent. + */ + LabelRangeSubset( + const std::string& name, + Datatype type, + std::vector ranges, + bool coalesce_ranges = true); + inline const std::vector& get_ranges() const { return ranges_.ranges(); }