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

Function read_array

examples/cpp_api/array_schema_evolution.cc:101–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101void 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
138void read_array2(const Context& ctx) {
139 // Prepare the array for reading

Callers 1

mainFunction · 0.70

Calls 7

add_rangeMethod · 0.45
set_data_bufferMethod · 0.45
set_layoutMethod · 0.45
set_subarrayMethod · 0.45
submitMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected