| 99 | } |
| 100 | |
| 101 | void read_array(const Context& ctx) { |
| 102 | // Prepare the array for reading |
| 103 | Array array(ctx, array_uri, TILEDB_READ); |
| 104 | |
| 105 | // Slice only rows 1, 2 and cols 2, 3, 4 |
| 106 | Subarray subarray(ctx, array); |
| 107 | subarray.add_range(0, 1, 2).add_range(1, 2, 4); |
| 108 | |
| 109 | // Prepare the vector that will hold the result. |
| 110 | // We take an upper bound on the result size, as we do not |
| 111 | // know a priori how big it is (since the array is sparse) |
| 112 | std::vector<int> data(3); |
| 113 | std::vector<int> coords_rows(3); |
| 114 | std::vector<int> coords_cols(3); |
| 115 | |
| 116 | // Prepare the query |
| 117 | Query query(ctx, array, TILEDB_READ); |
| 118 | query.set_subarray(subarray) |
| 119 | .set_layout(TILEDB_ROW_MAJOR) |
| 120 | .set_data_buffer("a", data) |
| 121 | .set_data_buffer("rows", coords_rows) |
| 122 | .set_data_buffer("cols", coords_cols); |
| 123 | |
| 124 | // Submit the query and close the array. |
| 125 | query.submit(); |
| 126 | array.close(); |
| 127 | |
| 128 | // Print out the results. |
| 129 | auto result_num = (int)query.result_buffer_elements()["a"].second; |
| 130 | for (int r = 0; r < result_num; r++) { |
| 131 | int i = coords_rows[r]; |
| 132 | int j = coords_cols[r]; |
| 133 | int a = data[r]; |
| 134 | std::cout << "Cell (" << i << ", " << j << ") has data " << a << "\n"; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | void read_array2(const Context& ctx) { |
| 139 | // Prepare the array for reading |
no test coverage detected