Skip to content

Commit

Permalink
Fix REST CI segfault.
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunrd0 committed Jul 19, 2024
1 parent ddd3ac9 commit b00936b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
10 changes: 4 additions & 6 deletions test/src/unit-rest-array-schema-load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,14 @@ TEST_CASE_METHOD(
"[rest][array-schema][simple-load]") {
create_array();

auto config = ctx_.config();
config.set("rest.load_enumerations_on_array_open", "false");
vfs_test_setup_.update_config(config.ptr().get());
ctx_ = vfs_test_setup_.ctx();

ArraySchema schema = Array::load_schema(ctx_, uri_);
auto matcher = Catch::Matchers::ContainsSubstring(
"Enumeration 'my_enum' is not loaded.");
REQUIRE_THROWS_WITH(
ArraySchemaExperimental::get_enumeration(ctx_, schema, "my_enum"),
matcher);

// Schema was constructed prior to creating the array, the array URI is empty.
// schema_ was constructed prior to creating the array, so array URI is empty.
// Set the schema's array_uri without opening the array.
schema_.ptr()->array_schema_->set_array_uri(sm::URI(uri_));
test::schema_equiv(
Expand All @@ -88,6 +83,9 @@ TEST_CASE_METHOD(
REQUIRE_NOTHROW(
ArraySchemaExperimental::get_enumeration(ctx_, schema, "my_enum"));

// schema_ was constructed prior to creating the array, so array URI is empty.
// Set the schema's array_uri without opening the array.
schema_.ptr()->array_schema_->set_array_uri(sm::URI(uri_));
test::schema_equiv(
*schema.ptr()->array_schema_, *schema_.ptr()->array_schema_);
}
Expand Down
11 changes: 6 additions & 5 deletions tiledb/sm/array_schema/array_schema_operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ void store_array_schema(
}

shared_ptr<ArraySchema> load_array_schema(
const Context& ctx, const URI& uri, const Config* config) {
const Context& ctx, const URI& uri, const Config& config) {
// Check array name
if (uri.is_invalid()) {
throw std::runtime_error("Failed to load array schema; Invalid array URI");
}

if (uri.is_tiledb()) {
auto& rest_client = ctx.rest_client();
auto array_schema_response = rest_client.post_array_schema_from_rest(
config ? *config : ctx.resources().config(), uri, 0, UINT64_MAX);
auto array_schema_response =
rest_client.post_array_schema_from_rest(config, uri, 0, UINT64_MAX);
return std::move(std::get<0>(array_schema_response));
} else {
// Create key
Expand All @@ -161,9 +161,10 @@ shared_ptr<ArraySchema> load_array_schema(
auto&& array_schema_latest =
array_dir->load_array_schema_latest(key, tracker);

bool incl_enums = config->get<bool>(
// Load enumerations if config option is set.
bool incl_enums = config.get<bool>(
"rest.load_enumerations_on_array_open", Config::must_find);
if (config && incl_enums) {
if (incl_enums) {
std::vector<std::string> enmr_paths_to_load;
auto enmr_names = array_schema_latest->get_enumeration_names();
for (auto& name : enmr_names) {
Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/array_schema/array_schema_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void store_array_schema(
* @param config TileDB Config. If null, the context config will be used.
*/
shared_ptr<ArraySchema> load_array_schema(
const Context& ctx, const URI& uri, const Config* config = nullptr);
const Context& ctx, const URI& uri, const Config& config);

} // namespace tiledb::sm

Expand Down
10 changes: 6 additions & 4 deletions tiledb/sm/c_api/tiledb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,9 @@ int32_t tiledb_array_schema_load(
throw CAPIStatusException("Failed to allocate TileDB array schema object");
}

// Use a default constructed config to load the schema with default options.
(*array_schema)->array_schema_ =
load_array_schema(ctx->context(), sm::URI(array_uri));
load_array_schema(ctx->context(), sm::URI(array_uri), sm::Config());

return TILEDB_OK;
}
Expand All @@ -511,10 +512,11 @@ int32_t tiledb_array_schema_load_with_options(
throw CAPIStatusException("Failed to allocate TileDB array schema object");
}

// Check array name
tiledb::sm::URI uri(array_uri);
// Use passed config or context config to load the schema with set options.
(*array_schema)->array_schema_ = load_array_schema(
ctx->context(), uri, config ? &config->config() : nullptr);
ctx->context(),
sm::URI(array_uri),
config ? config->config() : ctx->config());

return TILEDB_OK;
}
Expand Down

0 comments on commit b00936b

Please sign in to comment.