From cd74399ada41217140f21e7998af99ca334607c4 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Fri, 29 Mar 2024 17:42:36 -0400 Subject: [PATCH] Fix tests. --- test/src/unit-capi-fragment_info.cc | 2 +- tiledb/sm/array/array.cc | 3 +++ tiledb/sm/array/array.h | 13 +++++++++++++ tiledb/sm/consolidator/fragment_consolidator.cc | 9 ++++++--- tiledb/sm/fragment/fragment_metadata.cc | 16 +++++++++------- tiledb/sm/fragment/fragment_metadata.h | 7 +++++++ 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/test/src/unit-capi-fragment_info.cc b/test/src/unit-capi-fragment_info.cc index 1a40a59aa524..795ca1b48008 100644 --- a/test/src/unit-capi-fragment_info.cc +++ b/test/src/unit-capi-fragment_info.cc @@ -1810,7 +1810,7 @@ TEST_CASE( "- Unconsolidated metadata num: 1\n" + "- To vacuum num: 0\n" + "- Fragment #1:\n" + " > URI: " + written_frag_uri + "\n" + " > Type: sparse\n" + " > Non-empty domain: [a, ddd]\n" + - " > Size: 3442\n" + " > Cell num: 4\n" + + " > Size: 3460\n" + " > Cell num: 4\n" + " > Timestamp range: [1, 1]\n" + " > Format version: " + ver + "\n" + " > Has consolidated metadata: no\n"; FILE* gold_fout = fopen("gold_fout.txt", "w"); diff --git a/tiledb/sm/array/array.cc b/tiledb/sm/array/array.cc index e8568fdce151..dcc26b42bcfc 100644 --- a/tiledb/sm/array/array.cc +++ b/tiledb/sm/array/array.cc @@ -1087,6 +1087,9 @@ NDRange& Array::shape_data() { for (const auto& meta : frag_meta) { // Check each dimension in the fragment shape data. const auto& frag_shape_data = meta->shape_data(); + if (meta->has_shape_data()) { + opened_array_->has_shape_data() = true; + } for (size_t j = 0; j < frag_shape_data.size(); j++) { auto dim = opened_array_->array_schema_latest().dimension_ptr(j); if (dim->var_size()) { diff --git a/tiledb/sm/array/array.h b/tiledb/sm/array/array.h index 8acdb4fb65bd..c278ec9c77ea 100644 --- a/tiledb/sm/array/array.h +++ b/tiledb/sm/array/array.h @@ -104,6 +104,7 @@ class OpenedArray { , metadata_(memory_tracker) , metadata_loaded_(false) , non_empty_domain_computed_(false) + , has_shape_data_(false) , encryption_key_(make_shared(HERE())) , timestamp_start_(timestamp_start) , timestamp_end_opened_at_(timestamp_end_opened_at) @@ -170,6 +171,10 @@ class OpenedArray { return non_empty_domain_; } + inline bool& has_shape_data() { + return has_shape_data_; + } + /** Gets a reference to the shape data. */ inline NDRange& shape_data() { return shape_data_; @@ -236,6 +241,9 @@ class OpenedArray { /** The non-empty domain of the array. */ NDRange non_empty_domain_; + /** True if the opened array has shape data, else false. */ + bool has_shape_data_; + /** The shape data for the array. */ NDRange shape_data_; @@ -784,6 +792,11 @@ class Array { opened_array_->non_empty_domain_computed() = is_computed; } + /** Returns a reference to has_shape_data_ */ + inline bool has_shape_data() const { + return opened_array_->has_shape_data(); + } + /** Returns a reference to the shape data. */ NDRange& shape_data(); diff --git a/tiledb/sm/consolidator/fragment_consolidator.cc b/tiledb/sm/consolidator/fragment_consolidator.cc index 56805b23060c..3e16aa14bd11 100644 --- a/tiledb/sm/consolidator/fragment_consolidator.cc +++ b/tiledb/sm/consolidator/fragment_consolidator.cc @@ -710,10 +710,13 @@ Status FragmentConsolidator::create_queries( (*query_w)->set_processed_conditions(processed_conditions); auto shape_data = array_for_reads->shape_data(); - for (size_t i = 0; i < shape_data.size(); i++) { - (*query_w)->set_shape( - i, shape_data[i].start_fixed(), shape_data[i].end_fixed()); + if (array_for_reads->has_shape_data()) { + for (size_t i = 0; i < shape_data.size(); i++) { + (*query_w)->set_shape( + i, shape_data[i].start_fixed(), shape_data[i].end_fixed()); + } } + // Set the URI for the new fragment. auto frag_uri = array_for_reads->array_directory().get_fragments_dir(write_version); diff --git a/tiledb/sm/fragment/fragment_metadata.cc b/tiledb/sm/fragment/fragment_metadata.cc index 415d602b7a38..713c921423f0 100644 --- a/tiledb/sm/fragment/fragment_metadata.cc +++ b/tiledb/sm/fragment/fragment_metadata.cc @@ -118,6 +118,7 @@ FragmentMetadata::FragmentMetadata( , last_tile_cell_num_(0) , has_timestamps_(has_timestamps) , has_delete_meta_(has_deletes_meta) + , has_shape_data_(false) , sparse_tile_num_(0) , meta_file_size_(0) , rtree_(RTree( @@ -164,6 +165,7 @@ void FragmentMetadata::set_shape_data(const NDRange& range) { " dimensions on a fragment with " + std::to_string(array_schema_->dim_num()) + " dimensions."); } + has_shape_data_ = true; shape_data_ = range; } @@ -2805,12 +2807,12 @@ void FragmentMetadata::load_mbrs(Deserializer& deserializer) { } void FragmentMetadata::load_non_empty_domain(Deserializer& deserializer) { - // Get null non-empty domain if (version_ <= 2) { load_non_empty_domain_v1_v2(deserializer); return; } + // Get null non-empty domain. bool null_non_empty_domain = load_null_non_empty_domain(deserializer); if (!null_non_empty_domain) { if (version_ == 3 || version_ == 4) { @@ -2835,10 +2837,11 @@ bool FragmentMetadata::load_null_non_empty_domain( // has_shape_data (char) // shape_data: range(void*) void FragmentMetadata::load_shape_data(Deserializer& deserializer) { - bool has_shape_data = deserializer.read(); - if (!has_shape_data) { + has_shape_data_ = deserializer.read(); + if (!has_shape_data_) { // Load the non-empty domain if there is no shape data. - load_non_empty_domain(deserializer); + load_non_empty_domain_v5_or_higher(deserializer); + shape_data_ = non_empty_domain_; } else { auto dim_num = array_schema_->dim_num(); shape_data_.reserve(dim_num); @@ -3985,13 +3988,12 @@ void FragmentMetadata::write_non_empty_domain(Serializer& serializer) const { // shape_data: range(void*) void FragmentMetadata::write_shape_data(Serializer& serializer) const { // Write has shape data. - auto has_shape_data = (char)!shape_data_.empty(); - serializer.write(has_shape_data); + serializer.write((char)has_shape_data_); auto& domain = array_schema_->domain(); auto dim_num = domain.dim_num(); // If the shape data is empty, write the non-empty domain. - if (shape_data_.empty()) { + if (!has_shape_data_) { write_non_empty_domain(serializer); } else { // Write shape data for each dimension. diff --git a/tiledb/sm/fragment/fragment_metadata.h b/tiledb/sm/fragment/fragment_metadata.h index 5873fa3a692f..d7315ac9ceff 100644 --- a/tiledb/sm/fragment/fragment_metadata.h +++ b/tiledb/sm/fragment/fragment_metadata.h @@ -1227,6 +1227,10 @@ class FragmentMetadata { return non_empty_domain_; } + bool& has_shape_data() { + return has_shape_data_; + } + /** Shape data accessor. */ NDRange& shape_data() { return shape_data_; @@ -1350,6 +1354,9 @@ class FragmentMetadata { /** True if the fragment has delete metadata, and false otherwise. */ bool has_delete_meta_; + /** True if the fragment has shape data, false otherwise. */ + bool has_shape_data_; + /** Number of sparse tiles. */ uint64_t sparse_tile_num_;