* @brief Executes the read query for the array created in write_array. * * @param ctx The context. * @param qc The query condition to execute the query with. */
| 165 | * @param qc The query condition to execute the query with. |
| 166 | */ |
| 167 | void read_array_with_qc(Context& ctx, std::optional<QueryCondition> qc) { |
| 168 | // Create data buffers to read the values into. |
| 169 | std::vector<int> a_data(num_elems); |
| 170 | std::vector<uint8_t> a_data_validity(num_elems); |
| 171 | |
| 172 | // We initialize the string b_data to contain 44 characters because |
| 173 | // that is the combined size of all strings in attribute b. |
| 174 | std::string b_data; |
| 175 | b_data.resize(44); |
| 176 | |
| 177 | std::vector<uint64_t> b_data_offsets(num_elems); |
| 178 | std::vector<int32_t> c_data(num_elems); |
| 179 | std::vector<float> d_data(num_elems); |
| 180 | |
| 181 | // Execute the read query. |
| 182 | Array array(ctx, array_name, TILEDB_READ); |
| 183 | Query query(ctx, array); |
| 184 | query.set_layout(TILEDB_ROW_MAJOR) |
| 185 | .set_data_buffer("a", a_data) |
| 186 | .set_validity_buffer("a", a_data_validity) |
| 187 | .set_data_buffer("b", b_data) |
| 188 | .set_offsets_buffer("b", b_data_offsets) |
| 189 | .set_data_buffer("c", c_data) |
| 190 | .set_data_buffer("d", d_data); |
| 191 | if (qc) { |
| 192 | query.set_condition(qc.value()); |
| 193 | } |
| 194 | query.submit(); |
| 195 | |
| 196 | // Collect the results of the read query. The number of elements |
| 197 | // the filtered array contains is in num_elements_result. |
| 198 | // The length of the filtered substring of all the data is in |
| 199 | // b_data, and all the offsets for filtered individual elements |
| 200 | // are in b_data_offsets. |
| 201 | auto table = query.result_buffer_elements_nullable(); |
| 202 | size_t num_elements_result = std::get<1>(table["c"]); |
| 203 | uint64_t b_str_length = std::get<1>(table["b"]); |
| 204 | b_data_offsets.push_back(b_str_length); |
| 205 | |
| 206 | // Here we print all the elements that are returned by the query. |
| 207 | for (size_t i = 0; i < num_elements_result; ++i) { |
| 208 | // We pass in nullopt if the data is invalid, per the validity buffer. |
| 209 | std::optional<int> a_val; |
| 210 | if (a_data_validity[i]) { |
| 211 | a_val = a_data[i]; |
| 212 | } else { |
| 213 | a_val = std::nullopt; |
| 214 | } |
| 215 | print_elem( |
| 216 | a_val, |
| 217 | b_data.substr( |
| 218 | b_data_offsets[i], b_data_offsets[i + 1] - b_data_offsets[i]), |
| 219 | c_data[i], |
| 220 | d_data[i]); |
| 221 | } |
| 222 | |
| 223 | query.finalize(); |
| 224 | array.close(); |
no test coverage detected