* @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. */
| 188 | * @param qc The query condition to execute the query with. |
| 189 | */ |
| 190 | void read_array_with_qc(tiledb_ctx_t* ctx, tiledb_query_condition_t* qc) { |
| 191 | // Create data buffers to read the values into. |
| 192 | int a_data[10]; |
| 193 | uint64_t a_size = sizeof(a_data); |
| 194 | uint8_t a_data_validity[10]; |
| 195 | uint64_t a_validity_size = sizeof(a_data_validity); |
| 196 | |
| 197 | // We initialize the string b_data to contain 45 characters because |
| 198 | // that is the combined size of all strings in attribute b. |
| 199 | char b_data[256]; |
| 200 | memset(b_data, 0, 256); |
| 201 | uint64_t b_size = sizeof(b_data); |
| 202 | uint64_t b_data_offsets[10]; |
| 203 | uint64_t b_offsets_size = sizeof(b_data_offsets); |
| 204 | |
| 205 | int32_t c_data[10]; |
| 206 | uint64_t c_size = sizeof(c_data); |
| 207 | float d_data[10]; |
| 208 | uint64_t d_size = sizeof(d_data); |
| 209 | |
| 210 | tiledb_array_t* array; |
| 211 | tiledb_array_alloc(ctx, array_name, &array); |
| 212 | tiledb_array_open(ctx, array, TILEDB_READ); |
| 213 | |
| 214 | // Execute the read query. |
| 215 | tiledb_query_t* query; |
| 216 | tiledb_query_alloc(ctx, array, TILEDB_READ, &query); |
| 217 | tiledb_query_set_layout(ctx, query, TILEDB_ROW_MAJOR); |
| 218 | tiledb_query_set_data_buffer(ctx, query, "a", a_data, &a_size); |
| 219 | tiledb_query_set_validity_buffer( |
| 220 | ctx, query, "a", a_data_validity, &a_validity_size); |
| 221 | tiledb_query_set_data_buffer(ctx, query, "b", b_data, &b_size); |
| 222 | tiledb_query_set_offsets_buffer( |
| 223 | ctx, query, "b", b_data_offsets, &b_offsets_size); |
| 224 | tiledb_query_set_data_buffer(ctx, query, "c", c_data, &c_size); |
| 225 | tiledb_query_set_data_buffer(ctx, query, "d", d_data, &d_size); |
| 226 | |
| 227 | if (qc) { |
| 228 | tiledb_query_set_condition(ctx, query, qc); |
| 229 | } |
| 230 | |
| 231 | tiledb_query_submit(ctx, query); |
| 232 | |
| 233 | // Collect the results of the read query. The number of elements |
| 234 | // the filtered array contains is calculated by determining the |
| 235 | // number of valid elements in c_data, since the array is |
| 236 | // sparse. The length of the filtered substring of all the |
| 237 | // data is in b_data, and all the offsets for filtered |
| 238 | // individual elements are in b_data_offsets. |
| 239 | |
| 240 | // Here we print all the elements that are returned by the query. |
| 241 | uint64_t result_num = c_size / sizeof(int); |
| 242 | for (uint64_t i = 0; i < result_num; ++i) { |
| 243 | uint64_t element_start = b_data_offsets[i]; |
| 244 | uint64_t element_length = (i == result_num - 1) ? |
| 245 | (b_size / sizeof(char)) - element_start : |
| 246 | b_data_offsets[i + 1] - element_start; |
| 247 | print_elem( |
no test coverage detected