MCPcopy Create free account
hub / github.com/TileDB-Inc/TileDB / read_array_and_labels

Function read_array_and_labels

examples/cpp_api/quickstart_dimension_labels.cc:177–225  ·  view source on GitHub ↗

* Example reading data from the array and all dimension labels. * * @param ctx TileDB context to call TileDB API with. * @param array_uri URI of the array to read from. */

Source from the content-addressed store, hash-verified

175 * @param array_uri URI of the array to read from.
176 */
177void read_array_and_labels(const Context& ctx, const char* array_uri) {
178 printf("\nRead from main array\n");
179 // Open array for reading.
180 Array array(ctx, array_uri, TILEDB_READ);
181
182 // Create subarray for reading data.
183 Subarray subarray(ctx, array);
184 subarray.add_range(0, 1, 2);
185 subarray.add_range(1, 0, 2);
186
187 // Create buffers to hold the output data.
188 std::vector<int16_t> a(6);
189 std::vector<double> x(2);
190 std::vector<double> y(2);
191 std::vector<int64_t> timestamp(3);
192
193 // Create the query.
194 //
195 // Note: This example includes getting data from all 3 dimension labels. The
196 // data will be returned for any label buffers set. It can be all, some, or
197 // none of the possible dimension labels.
198 Query query(ctx, array);
199 query.set_layout(TILEDB_ROW_MAJOR);
200 query.set_subarray(subarray);
201 query.set_data_buffer("a", a);
202 QueryExperimental::set_data_buffer(query, "x", x);
203 QueryExperimental::set_data_buffer(query, "y", y);
204 QueryExperimental::set_data_buffer(query, "timestamp", timestamp);
205 // Submit the query and check if it finished.
206 auto status = query.submit();
207 if (status != Query::Status::COMPLETE) {
208 printf("Warning: Read query did not complete.\n");
209 }
210
211 // Print results.
212 for (unsigned i = 0; i < 2; ++i) {
213 for (unsigned j = 0; j < 3; ++j) {
214 int32_t x_val = i + 1;
215 int32_t sample_val = j + 0;
216 printf(" Cell (%d, %d)\n", x_val, sample_val);
217 printf(" * a(%d, %d) = %d\n", x_val, sample_val, a[3 * i + j]);
218 printf(" * x(%d) = %4.1f\n", x_val, x[i]);
219 printf(" * y(%d) = %4.1f\n", x_val, y[i]);
220 printf(" * timestamp(%d) = ", sample_val);
221 print_timestamp(timestamp[j]);
222 printf("\n");
223 }
224 }
225}
226
227/**
228 * Example reading data from one dimension label.

Callers 1

mainFunction · 0.70

Calls 6

print_timestampFunction · 0.70
add_rangeMethod · 0.45
set_layoutMethod · 0.45
set_subarrayMethod · 0.45
set_data_bufferMethod · 0.45
submitMethod · 0.45

Tested by

no test coverage detected