HappenLee commented on code in PR #54276:
URL: https://github.com/apache/doris/pull/54276#discussion_r2287216486


##########
be/src/vec/utils/util.hpp:
##########
@@ -285,6 +285,33 @@ inline size_t calculate_false_number(ColumnPtr column) {
     }
 }
 
+template <typename T>
+T read_from_json(const std::string& json_str) {
+    auto memBufferIn = 
std::make_shared<apache::thrift::transport::TMemoryBuffer>(
+            reinterpret_cast<uint8_t*>(const_cast<char*>(json_str.data())),
+            static_cast<uint32_t>(json_str.size()));
+    auto jsonProtocolIn = 
std::make_shared<apache::thrift::protocol::TJSONProtocol>(memBufferIn);
+    T params;
+    params.read(jsonProtocolIn.get());
+    return params;
+}
+
+template <typename T>
+void write_to_json(const std::string& path, std::string name, const T& expr) {
+    auto memBuffer = 
std::make_shared<apache::thrift::transport::TMemoryBuffer>();
+    auto jsonProtocol = 
std::make_shared<apache::thrift::protocol::TJSONProtocol>(memBuffer);
+
+    expr.write(jsonProtocol.get());
+    uint8_t* buf;
+    uint32_t size;
+    memBuffer->getBuffer(&buf, &size);
+    std::string file_path = fmt::format("{}/{}.json", path, name);
+    std::ofstream ofs(file_path, std::ios::binary);
+    ofs.write(reinterpret_cast<const char*>(buf), size);
+    ofs.close();
+    std::cout << fmt::format("Serialized JSON written to {}\n", file_path);

Review Comment:
   shoud each time print the msg to std::cout ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to