From 95cd8762176663b1971f24bc69e4cb28f936c99f Mon Sep 17 00:00:00 2001 From: John Kerl Date: Mon, 19 Aug 2024 11:13:37 -0400 Subject: [PATCH] [c++] Methodize timestamped-schema-evolution factory (#2909) --- libtiledbsoma/src/soma/soma_array.cc | 21 +++++++++++++-------- libtiledbsoma/src/soma/soma_array.h | 7 +++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/libtiledbsoma/src/soma/soma_array.cc b/libtiledbsoma/src/soma/soma_array.cc index ccda688494..32d415aa38 100644 --- a/libtiledbsoma/src/soma/soma_array.cc +++ b/libtiledbsoma/src/soma/soma_array.cc @@ -471,6 +471,18 @@ uint64_t SOMAArray::_get_max_capacity(tiledb_datatype_t index_type) { } } +ArraySchemaEvolution SOMAArray::_make_se() { + ArraySchemaEvolution se(*ctx_->tiledb_ctx()); + if (timestamp_.has_value()) { + // ArraySchemaEvolution requires us to pair (t2, t2) even if our range + // is (t1, t2). + auto v = timestamp_.value(); + TimestampRange tr(v.second, v.second); + se.set_timestamp_range(tr); + } + return se; +} + void SOMAArray::set_column_data( std::string_view name, uint64_t num_elems, @@ -738,14 +750,7 @@ ArrowTable SOMAArray::_cast_table( // Go through all columns in the ArrowTable and cast the values to what is // in the ArraySchema on disk - ArraySchemaEvolution se(*ctx_->tiledb_ctx()); - if (timestamp_.has_value()) { - // ArraySchemaEvolution requires us to pair (t2, t2) even if our range - // is (t1, t2). - auto v = timestamp_.value(); - TimestampRange tr(v.second, v.second); - se.set_timestamp_range(tr); - } + ArraySchemaEvolution se = _make_se(); bool evolve_schema = false; for (auto i = 0; i < arrow_schema->n_children; ++i) { auto orig_arrow_sch_ = arrow_schema->children[i]; diff --git a/libtiledbsoma/src/soma/soma_array.h b/libtiledbsoma/src/soma/soma_array.h index d3a57987f2..a4bdffa9d3 100644 --- a/libtiledbsoma/src/soma/soma_array.h +++ b/libtiledbsoma/src/soma/soma_array.h @@ -762,6 +762,13 @@ class SOMAArray : public SOMAObject { uint64_t _get_max_capacity(tiledb_datatype_t index_type); + /** + * Convenience function for creating an ArraySchemaEvolution object + * referencing this array's context pointer, along with its open-at + * timestamp (if any). + */ + ArraySchemaEvolution _make_se(); + bool _extend_enumeration( ArrowSchema* value_schema, ArrowArray* value_array,