diff --git a/tiledb/api/c_api/array_schema/array_schema_api.cc b/tiledb/api/c_api/array_schema/array_schema_api.cc index 3191dc75c12b..64a006ca08b5 100644 --- a/tiledb/api/c_api/array_schema/array_schema_api.cc +++ b/tiledb/api/c_api/array_schema/array_schema_api.cc @@ -95,6 +95,28 @@ capi_return_t tiledb_array_schema_alloc( return TILEDB_OK; } +capi_return_t tiledb_array_schema_alloc_at_timestamp( + tiledb_ctx_t* ctx, + tiledb_array_type_t array_type, + tiledb_array_schema_t** array_schema, + uint64_t t1, + uint64_t t2) { + ensure_output_pointer_is_valid(array_schema); + + // Create ArraySchema object + auto memory_tracker = ctx->resources().create_memory_tracker(); + memory_tracker->set_type(MemoryTrackerType::ARRAY_CREATE); + auto timestamp_range = std::make_pair(t1, t2); + auto opt_range = + std::optional>(timestamp_range); + *array_schema = tiledb_array_schema_t::make_handle( + static_cast(array_type), + memory_tracker, + opt_range); + + return TILEDB_OK; +} + void tiledb_array_schema_free(tiledb_array_schema_t** array_schema) { ensure_output_pointer_is_valid(array_schema); ensure_array_schema_is_valid(*array_schema); @@ -454,6 +476,18 @@ CAPI_INTERFACE( ctx, array_type, array_schema); } +CAPI_INTERFACE( + array_schema_alloc_at_timestamp, + tiledb_ctx_t* ctx, + tiledb_array_type_t array_type, + tiledb_array_schema_t** array_schema, + uint64_t t1, + uint64_t t2) { + return api_entry_with_context< + tiledb::api::tiledb_array_schema_alloc_at_timestamp>( + ctx, array_type, array_schema, t1, t2); +} + CAPI_INTERFACE_VOID(array_schema_free, tiledb_array_schema_t** array_schema) { return api_entry_void(array_schema); } diff --git a/tiledb/api/c_api/array_schema/array_schema_api_external.h b/tiledb/api/c_api/array_schema/array_schema_api_external.h index 703c25a772fe..cc39cf2ff9f8 100644 --- a/tiledb/api/c_api/array_schema/array_schema_api_external.h +++ b/tiledb/api/c_api/array_schema/array_schema_api_external.h @@ -121,6 +121,31 @@ TILEDB_EXPORT capi_return_t tiledb_array_schema_alloc( tiledb_array_type_t array_type, tiledb_array_schema_t** array_schema) TILEDB_NOEXCEPT; +/** + * Creates a TileDB array schema object with specified creation time. + * + * **Example:** + * + * @code{.c} + * tiledb_array_schema_t* array_schema; + * uint64_t t1 = 10; + * uint64_t t2 = 20; + * tiledb_array_schema_alloc_at_timestamp(ctx, TILEDB_DENSE, &array_schema, t1, + * t2); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_type The array type. + * @param[out] array_schema The TileDB array schema to be created. + * @return `TILEDB_OK` for success and `TILEDB_OOM` or `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_alloc_at_timestamp( + tiledb_ctx_t* ctx, + tiledb_array_type_t array_type, + tiledb_array_schema_t** array_schema, + uint64_t t1, + uint64_t t2); + /** * Destroys an array schema, freeing associated memory. * diff --git a/tiledb/sm/array/array.cc b/tiledb/sm/array/array.cc index c37682971d39..41e8bff8974f 100644 --- a/tiledb/sm/array/array.cc +++ b/tiledb/sm/array/array.cc @@ -203,7 +203,7 @@ void Array::create( std::lock_guard lock{object_mtx}; array_schema->set_array_uri(array_uri); - array_schema->generate_uri(); + array_schema->generate_uri(array_schema->timestamp_range()); array_schema->check(resources.config()); // Check current domain is specified correctly if set diff --git a/tiledb/sm/array_schema/array_schema.cc b/tiledb/sm/array_schema/array_schema.cc index 24df5692c67e..3d1396b22acc 100644 --- a/tiledb/sm/array_schema/array_schema.cc +++ b/tiledb/sm/array_schema/array_schema.cc @@ -80,13 +80,20 @@ class ArraySchemaException : public StatusException { /* ****************************** */ ArraySchema::ArraySchema( - ArrayType array_type, shared_ptr memory_tracker) + ArrayType array_type, + shared_ptr memory_tracker, + std::optional> timestamp_range) : memory_tracker_(memory_tracker) , uri_(URI()) , array_uri_(URI()) , version_(constants::format_version) - , timestamp_range_(std::make_pair( - utils::time::timestamp_now_ms(), utils::time::timestamp_now_ms())) + , timestamp_range_( + timestamp_range.has_value() ? std::make_pair( + timestamp_range.value().first, + timestamp_range.value().second) : + std::make_pair( + utils::time::timestamp_now_ms(), + utils::time::timestamp_now_ms())) , name_("") , array_type_(array_type) , allows_dups_(false) @@ -121,7 +128,7 @@ ArraySchema::ArraySchema( Datatype::UINT8)); // Generate URI and name for ArraySchema - generate_uri(); + generate_uri(timestamp_range); } ArraySchema::ArraySchema( diff --git a/tiledb/sm/array_schema/array_schema.h b/tiledb/sm/array_schema/array_schema.h index 8ca8daae80d9..f5e88de57cae 100644 --- a/tiledb/sm/array_schema/array_schema.h +++ b/tiledb/sm/array_schema/array_schema.h @@ -99,7 +99,11 @@ class ArraySchema { * @param memory_tracker The memory tracker of the array this fragment * metadata corresponds to. */ - ArraySchema(ArrayType array_type, shared_ptr memory_tracker); + ArraySchema( + ArrayType array_type, + shared_ptr memory_tracker, + std::optional> timestamp_range = + std::nullopt); /** Constructor with std::vector attributes. * @param uri The URI of the array schema file. diff --git a/tiledb/sm/cpp_api/array_schema.h b/tiledb/sm/cpp_api/array_schema.h index 86c113a97883..98c8db7ed637 100644 --- a/tiledb/sm/cpp_api/array_schema.h +++ b/tiledb/sm/cpp_api/array_schema.h @@ -107,10 +107,23 @@ class ArraySchema : public Schema { * @param ctx TileDB context * @param type Array type, sparse or dense. */ - explicit ArraySchema(const Context& ctx, tiledb_array_type_t type) + explicit ArraySchema( + const Context& ctx, + tiledb_array_type_t type, + std::optional> timestamp_range = std::nullopt) : Schema(ctx) { tiledb_array_schema_t* schema; - ctx.handle_error(tiledb_array_schema_alloc(ctx.ptr().get(), type, &schema)); + if (timestamp_range.has_value()) { + ctx.handle_error(tiledb_array_schema_alloc_at_timestamp( + ctx.ptr().get(), + type, + &schema, + timestamp_range.value().first, + timestamp_range.value().second)); + } else { + ctx.handle_error( + tiledb_array_schema_alloc(ctx.ptr().get(), type, &schema)); + } schema_ = std::shared_ptr(schema, deleter_); }