| 114 | } |
| 115 | |
| 116 | capi_return_t tiledb_array_create( |
| 117 | tiledb_ctx_t* ctx, |
| 118 | const char* array_uri, |
| 119 | const tiledb_array_schema_t* array_schema) { |
| 120 | ensure_array_schema_is_valid(array_schema); |
| 121 | |
| 122 | tiledb::sm::URI uri(array_uri, URI::must_be_valid); |
| 123 | if (uri.is_tiledb()) { |
| 124 | auto& rest_client = ctx->context().rest_client(); |
| 125 | if (rest_client.rest_legacy()) { |
| 126 | throw_if_not_ok(rest_client.post_array_schema_to_rest( |
| 127 | uri, *(array_schema->array_schema()))); |
| 128 | } else { |
| 129 | rest_client.post_array_create_to_rest( |
| 130 | uri, *(array_schema->array_schema())); |
| 131 | } |
| 132 | } else { |
| 133 | // Create key |
| 134 | tiledb::sm::EncryptionKey key; |
| 135 | throw_if_not_ok( |
| 136 | key.set_key(tiledb::sm::EncryptionType::NO_ENCRYPTION, nullptr, 0)); |
| 137 | // Create the array |
| 138 | tiledb::sm::Array::create( |
| 139 | ctx->resources(), uri, array_schema->array_schema(), key); |
| 140 | |
| 141 | // Create any dimension labels in the array. |
| 142 | for (tiledb::sm::ArraySchema::dimension_label_size_type ilabel{0}; |
| 143 | ilabel < array_schema->dim_label_num(); |
| 144 | ++ilabel) { |
| 145 | // Get dimension label information and define URI and name. |
| 146 | const auto& dim_label_ref = array_schema->dimension_label(ilabel); |
| 147 | if (dim_label_ref.is_external()) |
| 148 | continue; |
| 149 | if (!dim_label_ref.has_schema()) { |
| 150 | throw CAPIException( |
| 151 | "Failed to create array. Dimension labels that are " |
| 152 | "not external must have a schema."); |
| 153 | } |
| 154 | |
| 155 | // Create the dimension label array with the same key. |
| 156 | tiledb::sm::Array::create( |
| 157 | ctx->resources(), |
| 158 | dim_label_ref.uri(uri), |
| 159 | dim_label_ref.schema(), |
| 160 | key); |
| 161 | } |
| 162 | } |
| 163 | return TILEDB_OK; |
| 164 | } |
| 165 | |
| 166 | capi_return_t tiledb_array_open( |
| 167 | tiledb_array_t* array, tiledb_query_type_t query_type) { |