| 221 | } |
| 222 | |
| 223 | std::vector<JsonWrapper> jsonifyQueryResult( |
| 224 | const std::vector<std::shared_ptr<common::ValueVector>>& columns, |
| 225 | const std::vector<std::string>& names) { |
| 226 | auto numRows = 1u; // 1 if all vectors are flat |
| 227 | for (auto i = 0u; i < columns.size(); i++) { |
| 228 | if (!columns[i]->state->isFlat()) { |
| 229 | numRows = columns[i]->state->getSelVector().getSelSize(); |
| 230 | break; |
| 231 | } |
| 232 | } |
| 233 | std::vector<JsonWrapper> result; |
| 234 | std::vector<yyjson_val*> firstResultValues; |
| 235 | // save pointer to first result values so that flat tuples can just copy over |
| 236 | for (auto i = 0u; i < numRows; i++) { |
| 237 | JsonMutWrapper curResult; |
| 238 | auto root = yyjson_mut_obj(curResult.ptr); |
| 239 | yyjson_mut_doc_set_root(curResult.ptr, root); |
| 240 | for (auto j = 0u; j < columns.size(); j++) { |
| 241 | auto key = yyjson_mut_strncpy(curResult.ptr, names[j].c_str(), names[j].size()); |
| 242 | if (columns[j]->state->isFlat() && i > 0) { |
| 243 | // copy from first result |
| 244 | auto val = yyjson_val_mut_copy(curResult.ptr, firstResultValues[j]); |
| 245 | yyjson_mut_obj_add(root, key, val); |
| 246 | } else { |
| 247 | // create new yyjson value |
| 248 | auto val = jsonify(curResult, *columns[j], |
| 249 | columns[j]->state->getSelVector().getSelectedPositions()[i]); |
| 250 | yyjson_mut_obj_add(root, key, val); |
| 251 | } |
| 252 | } |
| 253 | result.push_back(JsonWrapper(yyjson_mut_doc_imut_copy(curResult.ptr, nullptr))); |
| 254 | if (i == 0) { |
| 255 | yyjson_val *key = nullptr, *val = nullptr; |
| 256 | auto iter = yyjson_obj_iter_with(yyjson_doc_get_root(result[i].ptr)); |
| 257 | while ((key = yyjson_obj_iter_next(&iter))) { |
| 258 | val = yyjson_obj_iter_get_val(key); |
| 259 | firstResultValues.push_back(val); |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | return result; |
| 264 | } |
| 265 | |
| 266 | common::LogicalType jsonSchema(yyjson_val* val, int64_t depth, int64_t breadth) { |
| 267 | if (depth == 0) { |
no test coverage detected