* Example reading data from the array by the dimension labels. * * @param ctx TileDB context to call TileDB API with. * @param array_uri URI of the array to read from. */
| 273 | * @param array_uri URI of the array to read from. |
| 274 | */ |
| 275 | void read_array_by_label(const Context& ctx, const char* array_uri) { |
| 276 | printf("\nRead array from label ranges\n"); |
| 277 | Array array(ctx, array_uri, TILEDB_READ); |
| 278 | |
| 279 | // Create subarray for reading data. |
| 280 | double y_range[2] = {3.0, 8.0}; |
| 281 | int64_t timestamp_range[2] = {31943, 32380}; |
| 282 | Subarray subarray(ctx, array); |
| 283 | SubarrayExperimental::add_label_range( |
| 284 | ctx, subarray, "y", y_range[0], y_range[1]); |
| 285 | SubarrayExperimental::add_label_range( |
| 286 | ctx, subarray, "timestamp", timestamp_range[0], timestamp_range[1]); |
| 287 | |
| 288 | // Create buffers to hold the output data. |
| 289 | std::vector<int16_t> a(6); |
| 290 | std::vector<double> y(3); |
| 291 | std::vector<int64_t> timestamp(2); |
| 292 | |
| 293 | // Create the query. |
| 294 | // Note: Setting the label buffers is optional. If they are not set, then |
| 295 | // only data for `a` will be returned. |
| 296 | Query query(ctx, array); |
| 297 | query.set_layout(TILEDB_ROW_MAJOR); |
| 298 | query.set_subarray(subarray); |
| 299 | QueryExperimental::set_data_buffer(query, "y", y); |
| 300 | QueryExperimental::set_data_buffer(query, "timestamp", timestamp); |
| 301 | query.set_data_buffer("a", a); |
| 302 | |
| 303 | // Submit the query. |
| 304 | auto status = query.submit(); |
| 305 | if (status != Query::Status::COMPLETE) { |
| 306 | printf("Warning: Read query did not complete.\n"); |
| 307 | } |
| 308 | |
| 309 | // Print results. |
| 310 | for (unsigned i = 0; i < 3; ++i) { |
| 311 | for (unsigned j = 0; j < 2; ++j) { |
| 312 | printf(" Cell (%3.1f, ", y[i]); |
| 313 | print_timestamp(timestamp[j]); |
| 314 | printf(")\n"); |
| 315 | printf(" * a(%3.1f, ", y[i]); |
| 316 | print_timestamp(timestamp[j]); |
| 317 | printf(") = %d\n", a[2 * i + j]); |
| 318 | printf("\n"); |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | /** Run the example. */ |
| 324 | int main() { |
no test coverage detected