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

Function write_array

examples/cpp_api/query_condition_sparse.cc:118–159  ·  view source on GitHub ↗

* @brief Execute a write on array query_condition_sparse array * which then stores the following data in the array. The table * is organized by dimension/attribute. * * index | a | b | c | d * ------------------------------- * 0 | null | alice | 0 | 4.1 * 1 | 2 | bob | 0 | 3.4 * 2 | null | craig | 0 | 5.6 * 3 | 4 | dave | 0 | 3.7 * 4 | null | erin |

Source from the content-addressed store, hash-verified

116 * @param ctx The context.
117 */
118void write_array(Context& ctx) {
119 // Create data buffers that store the values to be written in.
120 std::vector<int32_t> dim_data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
121 std::vector<int32_t> a_data = {0, 2, 0, 4, 0, 6, 0, 8, 0, 10};
122 std::vector<uint8_t> a_data_validity = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
123 std::vector<std::string> b_strs = {
124 "alice",
125 "bob",
126 "craig",
127 "dave",
128 "erin",
129 "frank",
130 "grace",
131 "heidi",
132 "ivan",
133 "judy"};
134 std::string b_data = "";
135 std::vector<uint64_t> b_data_offsets;
136 for (const auto& elem : b_strs) {
137 b_data_offsets.push_back(b_data.size());
138 b_data += elem;
139 }
140 std::vector<int32_t> c_data = {0, 0, 0, 0, 0, 0, 1, 2, 3, 4};
141 std::vector<float> d_data = {
142 4.1, 3.4, 5.6, 3.7, 2.3, 1.7, 3.8, 4.9, 3.2, 3.1};
143
144 // Execute the write query.
145 Array array_w(ctx, array_name, TILEDB_WRITE);
146 Query query_w(ctx, array_w);
147 query_w.set_layout(TILEDB_UNORDERED)
148 .set_data_buffer("index", dim_data)
149 .set_data_buffer("a", a_data)
150 .set_validity_buffer("a", a_data_validity)
151 .set_data_buffer("b", b_data)
152 .set_offsets_buffer("b", b_data_offsets)
153 .set_data_buffer("c", c_data)
154 .set_data_buffer("d", d_data);
155
156 query_w.submit();
157 query_w.finalize();
158 array_w.close();
159}
160
161/**
162 * @brief Executes the read query for the array created in write_array.

Callers 1

mainFunction · 0.70

Calls 9

push_backMethod · 0.45
sizeMethod · 0.45
set_data_bufferMethod · 0.45
set_offsets_bufferMethod · 0.45
set_validity_bufferMethod · 0.45
set_layoutMethod · 0.45
submitMethod · 0.45
finalizeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected