eldenmoon commented on code in PR #51876:
URL: https://github.com/apache/doris/pull/51876#discussion_r2154135657


##########
be/test/util/jsonb_serialize_test.cpp:
##########
@@ -0,0 +1,115 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+
+#include <fstream>
+
+#include "testutil/test_util.h"
+#include "util/jsonb_parser_simd.h"
+#include "util/jsonb_writer.h"
+
+// This test verifies the stability of Jsonb serialization format.
+// DO NOT modify or remove this test!
+// It serves as a guard against changes that may unintentionally break
+// backward compatibility or introduce inconsistencies in serialized data.
+//
+// If the JSON format must be changed, please carefully review the impact
+// on compatibility, and update this test accordingly with proper 
justification.
+// NOTE:
+//  1. Content of file `be/test/util/test_data/jsonb_serialize_test_data.bin` 
should NOT be modified.
+//  2. Content of string `JSON_DATA_STRING` should NOT be modified.
+//  3. If you need add more types in Jsonb format, you should write a new test 
case instead of modifying this one.
+
+namespace doris {
+static inline const std::string JSON_DATA_STRING = R"({
+  "string_example": "Hello, world!",
+  "int_number": 42,
+  "float_number": 3.14159,
+  "boolean_true": true,
+  "boolean_false": false,
+  "null_value": null,
+  "array_example": [
+    "apple",
+    123,
+    true,
+    null,
+    {
+      "nested_key": "nested_value"
+    }
+  ],
+  "object_example": {
+    "name": "Alice",
+    "age": 30,
+    "is_member": false,
+    "preferences": {
+      "colors": ["red", "green", "blue"],
+      "notifications": {
+        "email": true,
+        "sms": false
+      }
+    }
+  }
+}
+)";
+
+class JsonbSerializeTest : public testing::Test {
+public:
+    void SetUp() override {
+        // Setup code if needed
+    }
+
+    void TearDown() override {
+        // Cleanup code if needed
+    }
+
+    std::string load_serialized_jsonb_data() {
+        std::string dir_path = GetCurrentRunningDir();
+        std::string serialized_data_path = dir_path + data_path;
+        std::ifstream ifs(serialized_data_path, std::ios::binary);
+        if (!ifs.is_open()) {
+            throw std::runtime_error("Failed to open file: " + 
serialized_data_path);
+        }
+        std::string data((std::istreambuf_iterator<char>(ifs)), 
std::istreambuf_iterator<char>());
+        ifs.close();
+        return data;
+    }
+
+protected:
+    inline static std::string data_path = 
"/util/test_data/jsonb_serialize_test_data.bin";
+};
+
+TEST_F(JsonbSerializeTest, serialize) {
+    JsonbParser parser;
+    ASSERT_TRUE(parser.parse(JSON_DATA_STRING)) << "Failed to parse JSON data";
+
+    auto& writer = parser.getWriter();
+    auto* output = writer.getOutput();
+
+    ASSERT_TRUE(output != nullptr) << "Output stream is null";
+
+    auto* jsonb_doc = JsonbDocument::createDocument(output->getBuffer(), 
output->getSize());

Review Comment:
   JsonbDocument::createDocument(serialized_data)



-- 
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