You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by ya...@apache.org on 2021/07/16 01:21:38 UTC

[incubator-doris] branch master updated: [Bug][RoutineLoad] Can not match whole json in routine load (#6213)

This is an automated email from the ASF dual-hosted git repository.

yangzhg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new c2695e9  [Bug][RoutineLoad] Can not match whole json in routine load (#6213)
c2695e9 is described below

commit c2695e9716e8ddd5f7e90de745fe90ee87d2f789
Author: Mingyu Chen <mo...@gmail.com>
AuthorDate: Fri Jul 16 09:21:27 2021 +0800

    [Bug][RoutineLoad] Can not match whole json in routine load (#6213)
    
    Support using json path "$" to match the whole json in routine load
    
    Co-authored-by: chenmingyu <ch...@baidu.com>
---
 be/src/exprs/json_functions.cpp      | 15 +++++++++++++++
 be/test/exprs/json_function_test.cpp | 12 ++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/be/src/exprs/json_functions.cpp b/be/src/exprs/json_functions.cpp
index 88c238d..470902f 100644
--- a/be/src/exprs/json_functions.cpp
+++ b/be/src/exprs/json_functions.cpp
@@ -281,6 +281,16 @@ rapidjson::Value* JsonFunctions::get_json_array_from_parsed_json(
         return nullptr;
     }
 
+    if (parsed_paths.size() == 1) {
+        // the json path is "$", just return entire document
+        // wrapper an array
+        rapidjson::Value* array_obj = nullptr;
+        array_obj = static_cast<rapidjson::Value*>(mem_allocator.Malloc(sizeof(rapidjson::Value)));
+        array_obj->SetArray();
+        array_obj->PushBack(*document, mem_allocator);
+        return array_obj;
+    }
+
     rapidjson::Value* root = match_value(parsed_paths, document, mem_allocator, true);
     if (root == nullptr || root == document) { // not found
         return nullptr;
@@ -301,6 +311,11 @@ rapidjson::Value* JsonFunctions::get_json_object_from_parsed_json(
         return nullptr;
     }
 
+    if (parsed_paths.size() == 1) {
+        // the json path is "$", just return entire document
+        return document;
+    }
+
     rapidjson::Value* root = match_value(parsed_paths, document, mem_allocator, true);
     if (root == nullptr || root == document) { // not found
         return nullptr;
diff --git a/be/test/exprs/json_function_test.cpp b/be/test/exprs/json_function_test.cpp
index 0f76936..d1c4a4f 100644
--- a/be/test/exprs/json_function_test.cpp
+++ b/be/test/exprs/json_function_test.cpp
@@ -187,8 +187,8 @@ TEST_F(JsonFunctionTest, special_char) {
 
 TEST_F(JsonFunctionTest, json_path1) {
     std::string json_raw_data(
-            "[{\"k1\":\"v1\", \"keyname\":{\"ip\":\"10.10.0.1\", \"value\":20}},{\"k1\":\"v1-1\", "
-            "\"keyname\":{\"ip\":\"10.20.10.1\", \"value\":20}}]");
+            "[{\"k1\":\"v1\",\"keyname\":{\"ip\":\"10.10.0.1\",\"value\":20}},{\"k1\":\"v1-1\","
+            "\"keyname\":{\"ip\":\"10.20.10.1\",\"value\":20}}]");
     rapidjson::Document jsonDoc;
     if (jsonDoc.Parse(json_raw_data.c_str()).HasParseError()) {
         ASSERT_TRUE(false);
@@ -207,6 +207,14 @@ TEST_F(JsonFunctionTest, json_path1) {
     for (int i = 0; i < res3->Size(); i++) {
         std::cout << (*res3)[i].GetString() << std::endl;
     }
+
+    res3 = JsonFunctions::get_json_array_from_parsed_json("$", &jsonDoc, jsonDoc.GetAllocator());
+    ASSERT_TRUE(res3->IsArray());
+    rapidjson::StringBuffer buffer;
+    buffer.Clear();
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+    (*res3)[0].Accept(writer);
+    ASSERT_EQ(json_raw_data, std::string(buffer.GetString()));
 }
 
 TEST_F(JsonFunctionTest, json_path_get_nullobject) {

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org