| 63 | } |
| 64 | |
| 65 | yyjson_mut_val* jsonify(JsonMutWrapper& wrapper, const common::ValueVector& vec, uint64_t pos) { |
| 66 | // creates a mutable value linked to wrapper.ptr, but the responsibility to integrate it into |
| 67 | // wrapper is placed upon the caller |
| 68 | yyjson_mut_val* result = nullptr; |
| 69 | if (vec.isNull(pos)) { |
| 70 | result = yyjson_mut_null(wrapper.ptr); |
| 71 | } else if (JsonType::isJson(vec.dataType)) { |
| 72 | auto strVal = vec.getValue<string_t>(pos); |
| 73 | auto strContent = strVal.getAsStringView(); |
| 74 | |
| 75 | // Convert JSON string to an immutable JSON document using stringToJson |
| 76 | JsonWrapper immutable_json_wrapper = stringToJson(std::string(strContent)); |
| 77 | yyjson_doc* immutable_doc = immutable_json_wrapper.ptr; |
| 78 | if (!immutable_doc) { |
| 79 | // Handle error if parsing fails |
| 80 | return yyjson_mut_null(wrapper.ptr); |
| 81 | } |
| 82 | |
| 83 | // Create a new mutable document in the wrapper and copy the root from the immutable |
| 84 | // document |
| 85 | yyjson_mut_val* mut_root = |
| 86 | yyjson_val_mut_copy(wrapper.ptr, yyjson_doc_get_root(immutable_doc)); |
| 87 | |
| 88 | return mut_root; |
| 89 | } else { |
| 90 | switch (vec.dataType.getLogicalTypeID()) { |
| 91 | case LogicalTypeID::BOOL: |
| 92 | result = yyjson_mut_bool(wrapper.ptr, vec.getValue<bool>(pos)); |
| 93 | break; |
| 94 | case LogicalTypeID::SERIAL: |
| 95 | case LogicalTypeID::INT64: |
| 96 | result = yyjson_mut_sint(wrapper.ptr, vec.getValue<int64_t>(pos)); |
| 97 | break; |
| 98 | case LogicalTypeID::INT32: |
| 99 | result = yyjson_mut_sint(wrapper.ptr, vec.getValue<int32_t>(pos)); |
| 100 | break; |
| 101 | case LogicalTypeID::INT16: |
| 102 | result = yyjson_mut_sint(wrapper.ptr, vec.getValue<int16_t>(pos)); |
| 103 | break; |
| 104 | case LogicalTypeID::INT8: |
| 105 | result = yyjson_mut_sint(wrapper.ptr, vec.getValue<int8_t>(pos)); |
| 106 | break; |
| 107 | case LogicalTypeID::UINT64: |
| 108 | result = yyjson_mut_uint(wrapper.ptr, vec.getValue<uint64_t>(pos)); |
| 109 | break; |
| 110 | case LogicalTypeID::UINT32: |
| 111 | result = yyjson_mut_uint(wrapper.ptr, vec.getValue<uint32_t>(pos)); |
| 112 | break; |
| 113 | case LogicalTypeID::UINT16: |
| 114 | result = yyjson_mut_uint(wrapper.ptr, vec.getValue<uint16_t>(pos)); |
| 115 | break; |
| 116 | case LogicalTypeID::UINT8: |
| 117 | result = yyjson_mut_uint(wrapper.ptr, vec.getValue<uint8_t>(pos)); |
| 118 | break; |
| 119 | case LogicalTypeID::DOUBLE: |
| 120 | result = yyjson_mut_real(wrapper.ptr, vec.getValue<double>(pos)); |
| 121 | break; |
| 122 | case LogicalTypeID::FLOAT: |
no test coverage detected