5656#include " tiledb/common/memory_tracker.h"
5757#include " tiledb/sm/array/array.h"
5858#include " tiledb/sm/array_schema/array_schema.h"
59+ #include " tiledb/sm/array_schema/array_schema_operations.h"
5960#include " tiledb/sm/array_schema/dimension_label.h"
6061#include " tiledb/sm/c_api/api_argument_validator.h"
6162#include " tiledb/sm/config/config.h"
@@ -489,49 +490,9 @@ int32_t tiledb_array_schema_load(
489490 throw CAPIStatusException (" Failed to allocate TileDB array schema object" );
490491 }
491492
492- // Check array name
493- tiledb::sm::URI uri (array_uri);
494- if (uri.is_invalid ()) {
495- throw CAPIStatusException (" Failed to load array schema; Invalid array URI" );
496- }
497-
498- if (uri.is_tiledb ()) {
499- auto & rest_client = ctx->context ().rest_client ();
500- try {
501- auto array_schema_response = rest_client.post_array_schema_from_rest (
502- ctx->resources ().config (), uri, 0 , UINT64_MAX);
503- (*array_schema)->array_schema_ = std::get<0 >(array_schema_response);
504- } catch (...) {
505- delete *array_schema;
506- throw ;
507- }
508- } else {
509- // Create key
510- tiledb::sm::EncryptionKey key;
511- throw_if_not_ok (
512- key.set_key (tiledb::sm::EncryptionType::NO_ENCRYPTION, nullptr , 0 ));
513-
514- // Load URIs from the array directory
515- optional<tiledb::sm::ArrayDirectory> array_dir;
516- try {
517- array_dir.emplace (
518- ctx->resources (),
519- uri,
520- 0 ,
521- UINT64_MAX,
522- tiledb::sm::ArrayDirectoryMode::SCHEMA_ONLY);
523- } catch (const std::logic_error& le) {
524- delete *array_schema;
525- throw CAPIStatusException (le.what ());
526- }
527-
528- auto tracker = ctx->resources ().ephemeral_memory_tracker ();
529- // Load latest array schema
530- auto array_schema_latest =
531- array_dir->load_array_schema_latest (key, tracker);
493+ (*array_schema)->array_schema_ =
494+ handle_load_uri (ctx->context (), sm::URI (array_uri));
532495
533- (*array_schema)->array_schema_ = array_schema_latest;
534- }
535496 return TILEDB_OK;
536497}
537498
@@ -543,8 +504,6 @@ int32_t tiledb_array_schema_load_with_options(
543504 ensure_context_is_valid (ctx);
544505 ensure_config_is_valid (config);
545506 ensure_output_pointer_is_valid (array_schema);
546- bool incl_enmrs = config->config ().get <bool >(
547- " rest.load_enumerations_on_array_open" , sm::Config::must_find);
548507
549508 // Create array schema
550509 *array_schema = new (std::nothrow) tiledb_array_schema_t ;
@@ -554,65 +513,9 @@ int32_t tiledb_array_schema_load_with_options(
554513
555514 // Check array name
556515 tiledb::sm::URI uri (array_uri);
557- if (uri.is_invalid ()) {
558- throw CAPIStatusException (" Failed to load array schema; Invalid array URI" );
559- }
516+ (*array_schema)->array_schema_ = handle_load_uri (
517+ ctx->context (), uri, config ? &config->config () : nullptr );
560518
561- if (uri.is_tiledb ()) {
562- auto & rest_client = ctx->context ().rest_client ();
563- try {
564- auto array_schema_response = rest_client.post_array_schema_from_rest (
565- ctx->resources ().config (), uri, 0 , UINT64_MAX);
566- (*array_schema)->array_schema_ = std::get<0 >(array_schema_response);
567- } catch (...) {
568- delete *array_schema;
569- throw ;
570- }
571- } else {
572- // Create key
573- tiledb::sm::EncryptionKey key;
574- throw_if_not_ok (
575- key.set_key (tiledb::sm::EncryptionType::NO_ENCRYPTION, nullptr , 0 ));
576-
577- // Load URIs from the array directory
578- optional<tiledb::sm::ArrayDirectory> array_dir;
579- try {
580- array_dir.emplace (
581- ctx->resources (),
582- uri,
583- 0 ,
584- UINT64_MAX,
585- tiledb::sm::ArrayDirectoryMode::SCHEMA_ONLY);
586- } catch (const std::logic_error& le) {
587- delete *array_schema;
588- throw CAPIStatusException (le.what ());
589- }
590-
591- auto tracker = ctx->resources ().ephemeral_memory_tracker ();
592-
593- // Load latest array schema
594- auto && array_schema_latest =
595- array_dir->load_array_schema_latest (key, tracker);
596-
597- if (incl_enmrs) {
598- std::vector<std::string> enmr_paths_to_load;
599- auto enmr_names = array_schema_latest->get_enumeration_names ();
600- for (auto & name : enmr_names) {
601- if (!array_schema_latest->is_enumeration_loaded (name)) {
602- auto & path = array_schema_latest->get_enumeration_path_name (name);
603- enmr_paths_to_load.emplace_back (path);
604- }
605- }
606-
607- auto enmrs_loaded = array_dir->load_enumerations_from_paths (
608- enmr_paths_to_load, key, tracker);
609- for (auto & enmr : enmrs_loaded) {
610- array_schema_latest->store_enumeration (enmr);
611- }
612- }
613-
614- (*array_schema)->array_schema_ = array_schema_latest;
615- }
616519 return TILEDB_OK;
617520}
618521
0 commit comments