Skip to content

Commit

Permalink
Support setting of schema-creation timestamp [WIP] [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Aug 27, 2024
1 parent 910fffd commit 14db17d
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 8 deletions.
34 changes: 34 additions & 0 deletions tiledb/api/c_api/array_schema/array_schema_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<uint64_t, uint64_t>>(timestamp_range);
*array_schema = tiledb_array_schema_t::make_handle(
static_cast<tiledb::sm::ArrayType>(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);
Expand Down Expand Up @@ -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<tiledb::api::tiledb_array_schema_free>(array_schema);
}
Expand Down
25 changes: 25 additions & 0 deletions tiledb/api/c_api/array_schema/array_schema_api_external.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/array/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void Array::create(

std::lock_guard<std::mutex> 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
Expand Down
15 changes: 11 additions & 4 deletions tiledb/sm/array_schema/array_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,20 @@ class ArraySchemaException : public StatusException {
/* ****************************** */

ArraySchema::ArraySchema(
ArrayType array_type, shared_ptr<MemoryTracker> memory_tracker)
ArrayType array_type,
shared_ptr<MemoryTracker> memory_tracker,
std::optional<std::pair<uint64_t, uint64_t>> 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)
Expand Down Expand Up @@ -121,7 +128,7 @@ ArraySchema::ArraySchema(
Datatype::UINT8));

// Generate URI and name for ArraySchema
generate_uri();
generate_uri(timestamp_range);
}

ArraySchema::ArraySchema(
Expand Down
6 changes: 5 additions & 1 deletion tiledb/sm/array_schema/array_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemoryTracker> memory_tracker);
ArraySchema(
ArrayType array_type,
shared_ptr<MemoryTracker> memory_tracker,
std::optional<std::pair<uint64_t, uint64_t>> timestamp_range =
std::nullopt);

/** Constructor with std::vector attributes.
* @param uri The URI of the array schema file.
Expand Down
17 changes: 15 additions & 2 deletions tiledb/sm/cpp_api/array_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<int64_t, int64_t>> 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<tiledb_array_schema_t>(schema, deleter_);
}

Expand Down

0 comments on commit 14db17d

Please sign in to comment.