Skip to content

Commit 28f97ce

Browse files
committed
Make ContextResources available in Enumeration::generate_value_map
1 parent 58e7d86 commit 28f97ce

24 files changed

+236
-63
lines changed

test/src/unit-enumerations.cc

Lines changed: 74 additions & 14 deletions
Large diffs are not rendered by default.

test/src/unit-request-handlers.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ HandleLoadArraySchemaRequestFx::create_string_enumeration(
465465
}
466466

467467
return Enumeration::create(
468+
ctx_.resources(),
468469
name,
469470
Datatype::STRING_ASCII,
470471
constants::var_num,
@@ -546,7 +547,7 @@ HandleLoadArraySchemaRequestFx::call_handler(
546547
REQUIRE(rval == TILEDB_OK);
547548

548549
return serialization::deserialize_load_array_schema_response(
549-
uri_, cfg_, stype, resp_buf->buffer(), memory_tracker_);
550+
ctx_.resources(), uri_, cfg_, stype, resp_buf->buffer(), memory_tracker_);
550551
}
551552

552553
shared_ptr<ArraySchema> HandleQueryPlanRequestFx::create_schema() {

tiledb/api/c_api/enumeration/enumeration_api.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ capi_return_t tiledb_enumeration_alloc(
7171
memory_tracker->set_type(tiledb::sm::MemoryTrackerType::ENUMERATION_CREATE);
7272

7373
*enumeration = tiledb_enumeration_handle_t::make_handle(
74+
ctx->context().resources(),
7475
std::string(name),
7576
datatype,
7677
cell_val_num,
@@ -89,6 +90,7 @@ capi_return_t tiledb_enumeration_alloc(
8990
}
9091

9192
capi_return_t tiledb_enumeration_extend(
93+
tiledb_ctx_t* ctx,
9294
tiledb_enumeration_t* old_enumeration,
9395
const void* data,
9496
uint64_t data_size,
@@ -99,7 +101,7 @@ capi_return_t tiledb_enumeration_extend(
99101
ensure_output_pointer_is_valid(new_enumeration);
100102

101103
auto new_enmr =
102-
old_enumeration->extend(data, data_size, offsets, offsets_size);
104+
old_enumeration->extend(ctx, data, data_size, offsets, offsets_size);
103105

104106
try {
105107
*new_enumeration = tiledb_enumeration_handle_t::make_handle(new_enmr);
@@ -262,7 +264,7 @@ CAPI_INTERFACE(
262264
const void* offsets,
263265
uint64_t offsets_size,
264266
tiledb_enumeration_t** new_enumeration) {
265-
return api_entry_context<tiledb::api::tiledb_enumeration_extend>(
267+
return api_entry<tiledb::api::tiledb_enumeration_extend>(
266268
ctx,
267269
old_enumeration,
268270
data,

tiledb/api/c_api/enumeration/enumeration_api_internal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define TILEDB_CAPI_ENUMERATION_INTERNAL_H
3535

3636
#include "enumeration_api_experimental.h"
37+
#include "tiledb/api/c_api/context/context_api_internal.h"
3738
#include "tiledb/api/c_api_support/handle/handle.h"
3839
#include "tiledb/common/common.h"
3940
#include "tiledb/sm/array_schema/enumeration.h"
@@ -82,11 +83,13 @@ struct tiledb_enumeration_handle_t
8283
* Extend a given enumeration.
8384
*/
8485
[[nodiscard]] shared_ptr<const tiledb::sm::Enumeration> extend(
86+
tiledb_ctx_t* ctx,
8587
const void* data,
8688
uint64_t data_size,
8789
const void* offsets,
8890
uint64_t offsets_size) const {
89-
return enumeration_->extend(data, data_size, offsets, offsets_size);
91+
return enumeration_->extend(
92+
ctx->context().resources(), data, data_size, offsets, offsets_size);
9093
}
9194

9295
/**

tiledb/sm/array/array.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ Status Array::open_without_fragments(
336336
throw instead of return Status */
337337
if (!use_refactored_array_open()) {
338338
auto&& [st, array_schema_latest] =
339-
rest_client->get_array_schema_from_rest(array_uri_);
339+
rest_client->get_array_schema_from_rest(resources_, array_uri_);
340340
if (!st.ok()) {
341341
throw StatusException(st);
342342
}
@@ -499,7 +499,7 @@ Status Array::open(
499499
}
500500
if (!use_refactored_array_open()) {
501501
auto&& [st, array_schema_latest] =
502-
rest_client->get_array_schema_from_rest(array_uri_);
502+
rest_client->get_array_schema_from_rest(resources_, array_uri_);
503503
throw_if_not_ok(st);
504504
set_array_schema_latest(array_schema_latest.value());
505505
if (serialize_enumerations()) {
@@ -850,6 +850,7 @@ Array::get_enumerations_all_schemas() {
850850
// Pass an empty list of enumeration names. REST will use timestamps to
851851
// load all enumerations on all schemas for the array within that range.
852852
ret = rest_client->post_enumerations_from_rest(
853+
resources_,
853854
array_uri_,
854855
array_dir_timestamp_start_,
855856
array_dir_timestamp_end_,
@@ -949,6 +950,7 @@ std::vector<shared_ptr<const Enumeration>> Array::get_enumerations(
949950
}
950951

951952
loaded = rest_client->post_enumerations_from_rest(
953+
resources_,
952954
array_uri_,
953955
array_dir_timestamp_start_,
954956
array_dir_timestamp_end_,
@@ -2137,6 +2139,7 @@ void load_enumeration_into_schema(
21372139
}
21382140

21392141
auto ret = rest_client->post_enumerations_from_rest(
2142+
ctx.resources(),
21402143
array_schema.array_uri(),
21412144
array_schema.timestamp_start(),
21422145
array_schema.timestamp_end(),

tiledb/sm/array/array.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,10 @@ class Array {
746746
return config_;
747747
}
748748

749+
inline const ContextResources& resources() const {
750+
return resources_;
751+
}
752+
749753
/** Directly set the array URI for serialized compatibility with pre
750754
* TileDB 2.5 clients */
751755
void set_uri_serialized(const std::string& uri) {

tiledb/sm/array/array_directory.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ shared_ptr<const Enumeration> ArrayDirectory::load_enumeration(
13441344
}
13451345

13461346
Deserializer deserializer(tile->data(), tile->size());
1347-
return Enumeration::deserialize(deserializer, memory_tracker);
1347+
return Enumeration::deserialize(resources_, deserializer, memory_tracker);
13481348
}
13491349

13501350
} // namespace tiledb::sm

tiledb/sm/array_schema/array_schema_operations.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ shared_ptr<ArraySchema> load_array_schema(
245245
if (uri.is_tiledb()) {
246246
auto& rest_client = ctx.rest_client();
247247
auto&& [st, array_schema_response] =
248-
rest_client.get_array_schema_from_rest(uri);
248+
rest_client.get_array_schema_from_rest(ctx.resources(), uri);
249249
throw_if_not_ok(st);
250250
auto array_schema = std::move(array_schema_response).value();
251251

@@ -254,6 +254,7 @@ shared_ptr<ArraySchema> load_array_schema(
254254
// Pass an empty list of enumeration names. REST will use timestamps to
255255
// load all enumerations on all schemas for the array within that range.
256256
auto ret = rest_client.post_enumerations_from_rest(
257+
ctx.resources(),
257258
uri,
258259
array_schema->timestamp_start(),
259260
array_schema->timestamp_end(),

tiledb/sm/array_schema/enumeration.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class EnumerationException : public StatusException {
4949
};
5050

5151
Enumeration::Enumeration(
52+
const ContextResources& resources,
5253
const std::string& name,
5354
const std::string& path_name,
5455
Datatype type,
@@ -191,11 +192,13 @@ Enumeration::Enumeration(
191192
throw_if_not_ok(offsets_.write(offsets, 0, offsets_size));
192193
}
193194

194-
generate_value_map();
195+
generate_value_map(resources);
195196
}
196197

197198
shared_ptr<const Enumeration> Enumeration::deserialize(
198-
Deserializer& deserializer, shared_ptr<MemoryTracker> memory_tracker) {
199+
const ContextResources& resources,
200+
Deserializer& deserializer,
201+
shared_ptr<MemoryTracker> memory_tracker) {
199202
auto disk_version = deserializer.read<uint32_t>();
200203
if (disk_version > constants::enumerations_version) {
201204
throw EnumerationException(
@@ -233,6 +236,7 @@ shared_ptr<const Enumeration> Enumeration::deserialize(
233236
}
234237

235238
return create(
239+
resources,
236240
name,
237241
path_name,
238242
static_cast<Datatype>(type),
@@ -246,6 +250,7 @@ shared_ptr<const Enumeration> Enumeration::deserialize(
246250
}
247251

248252
shared_ptr<const Enumeration> Enumeration::extend(
253+
const ContextResources& resources,
249254
const void* data,
250255
uint64_t data_size,
251256
const void* offsets,
@@ -326,6 +331,7 @@ shared_ptr<const Enumeration> Enumeration::extend(
326331
}
327332

328333
return create(
334+
resources,
329335
name_,
330336
"",
331337
type_,
@@ -421,7 +427,7 @@ uint64_t Enumeration::index_of(const void* data, uint64_t size) const {
421427
return iter->second;
422428
}
423429

424-
void Enumeration::generate_value_map() {
430+
void Enumeration::generate_value_map(const ContextResources&) {
425431
auto char_data = data_.data_as<char>();
426432
if (var_size()) {
427433
auto offsets = offsets_.data_as<uint64_t>();

tiledb/sm/array_schema/enumeration.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "tiledb/common/types/untyped_datum.h"
4141
#include "tiledb/sm/buffer/buffer.h"
4242
#include "tiledb/sm/enums/datatype.h"
43+
#include "tiledb/sm/storage_manager/context.h"
4344
#include "tiledb/storage_format/serialization/serializers.h"
4445

4546
namespace tiledb::sm {
@@ -75,6 +76,7 @@ class Enumeration {
7576

7677
/** Create a new Enumeration
7778
*
79+
* @param resources Resources for computing the enumeration value map.
7880
* @param name The name of this Enumeration as referenced by attributes.
7981
* @param type The datatype of the enumeration values.
8082
* @param cell_val_num The cell_val_num of the enumeration.
@@ -91,6 +93,7 @@ class Enumeration {
9193
* @return shared_ptr<Enumeration> The created enumeration.
9294
*/
9395
static shared_ptr<const Enumeration> create(
96+
const ContextResources& resources,
9497
const std::string& name,
9598
Datatype type,
9699
uint32_t cell_val_num,
@@ -101,6 +104,7 @@ class Enumeration {
101104
uint64_t offsets_size,
102105
shared_ptr<MemoryTracker> memory_tracker) {
103106
return create(
107+
resources,
104108
name,
105109
"",
106110
type,
@@ -115,6 +119,7 @@ class Enumeration {
115119

116120
/** Create a new Enumeration
117121
*
122+
* @param resources Resources for computing the enumeration value map.
118123
* @param name The name of this Enumeration as referenced by attributes.
119124
* @param path_name The last URI path component of the Enumeration.
120125
* @param type The datatype of the enumeration values.
@@ -132,6 +137,7 @@ class Enumeration {
132137
* @return shared_ptr<Enumeration> The created enumeration.
133138
*/
134139
static shared_ptr<const Enumeration> create(
140+
const ContextResources& resources,
135141
const std::string& name,
136142
const std::string& path_name,
137143
Datatype type,
@@ -144,6 +150,7 @@ class Enumeration {
144150
shared_ptr<MemoryTracker> memory_tracker) {
145151
struct EnableMakeShared : public Enumeration {
146152
EnableMakeShared(
153+
const ContextResources& resources,
147154
const std::string& name,
148155
const std::string& path_name,
149156
Datatype type,
@@ -155,6 +162,7 @@ class Enumeration {
155162
uint64_t offsets_size,
156163
shared_ptr<MemoryTracker> memory_tracker)
157164
: Enumeration(
165+
resources,
158166
name,
159167
path_name,
160168
type,
@@ -169,6 +177,7 @@ class Enumeration {
169177
};
170178
return make_shared<EnableMakeShared>(
171179
HERE(),
180+
resources,
172181
name,
173182
path_name,
174183
type,
@@ -189,7 +198,9 @@ class Enumeration {
189198
* @return A new Enumeration.
190199
*/
191200
static shared_ptr<const Enumeration> deserialize(
192-
Deserializer& deserializer, shared_ptr<MemoryTracker> memory_tracker);
201+
const ContextResources& resources,
202+
Deserializer& deserializer,
203+
shared_ptr<MemoryTracker> memory_tracker);
193204

194205
/**
195206
* Create a new enumeration by extending an existing enumeration's
@@ -207,6 +218,7 @@ class Enumeration {
207218
* @return shared_ptr<Enumeration> The extended enumeration.
208219
*/
209220
shared_ptr<const Enumeration> extend(
221+
const ContextResources& resources,
210222
const void* data,
211223
uint64_t data_size,
212224
const void* offsets,
@@ -361,6 +373,7 @@ class Enumeration {
361373

362374
/** Constructor
363375
*
376+
* @param resources Resources for building the enumeration value map.
364377
* @param name The name of this Enumeration as referenced by attributes.
365378
* @param path_name The last URI path component of the Enumeration.
366379
* @param type The datatype of the enumeration values.
@@ -377,6 +390,7 @@ class Enumeration {
377390
* @param memory_tracker The memory tracker.
378391
*/
379392
Enumeration(
393+
const ContextResources& resources,
380394
const std::string& name,
381395
const std::string& path_name,
382396
Datatype type,
@@ -426,7 +440,7 @@ class Enumeration {
426440
/* ********************************* */
427441

428442
/** Populate the value_map_ */
429-
void generate_value_map();
443+
void generate_value_map(const ContextResources& resources);
430444

431445
/**
432446
* Add a value to value_map_

0 commit comments

Comments
 (0)