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

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new dc55458030a  [bug](json)Fix the problem of be down caused by json path 
ending with \  #28180 (#28378)
dc55458030a is described below

commit dc55458030aa1aa6b810f299a94fc9f24a0b1bc2
Author: Liqf <109049295+lemonlit...@users.noreply.github.com>
AuthorDate: Thu Dec 14 15:47:22 2023 +0800

     [bug](json)Fix the problem of be down caused by json path ending with \  
#28180 (#28378)
---
 be/src/util/jsonb_document.h                                      | 1 +
 be/src/vec/functions/function_json.cpp                            | 6 ++++++
 regression-test/data/json_p0/test_json_load_and_function.out      | 3 +++
 regression-test/suites/json_p0/test_json_load_and_function.groovy | 1 +
 4 files changed, 11 insertions(+)

diff --git a/be/src/util/jsonb_document.h b/be/src/util/jsonb_document.h
index 657438fefee..3780bf69405 100644
--- a/be/src/util/jsonb_document.h
+++ b/be/src/util/jsonb_document.h
@@ -1568,6 +1568,7 @@ inline bool JsonbPath::parse_member(Stream* stream, 
JsonbPath* path) {
             stream->skip(1);
             stream->add_leg_len();
             stream->set_has_escapes(true);
+            if (stream->exhausted()) return false;
             continue;
         } else if (stream->peek() == DOUBLE_QUOTE) {
             if (left_quotation_marks == nullptr) {
diff --git a/be/src/vec/functions/function_json.cpp 
b/be/src/vec/functions/function_json.cpp
index 92908ff734d..6f11921b6b3 100644
--- a/be/src/vec/functions/function_json.cpp
+++ b/be/src/vec/functions/function_json.cpp
@@ -230,6 +230,12 @@ rapidjson::Value* get_json_object(std::string_view 
json_string, std::string_view
     std::vector<JsonPath>* parsed_paths;
     std::vector<JsonPath> tmp_parsed_paths;
 
+    //Cannot use '\' as the last character, return NULL
+    if (path_string.back() == '\\') {
+        document->SetNull();
+        return document;
+    }
+
 #ifdef USE_LIBCPP
     std::string s(path_string);
     auto tok = get_json_token(s);
diff --git a/regression-test/data/json_p0/test_json_load_and_function.out 
b/regression-test/data/json_p0/test_json_load_and_function.out
index e12fb79e380..422bbbeece0 100644
--- a/regression-test/data/json_p0/test_json_load_and_function.out
+++ b/regression-test/data/json_p0/test_json_load_and_function.out
@@ -45,6 +45,9 @@
 30     -9223372036854775808
 31     18446744073709551615
 
+-- !select --
+\N
+
 -- !select --
 1      \N      \N
 2      null    null
diff --git a/regression-test/suites/json_p0/test_json_load_and_function.groovy 
b/regression-test/suites/json_p0/test_json_load_and_function.groovy
index 11b72ae486f..3746006af83 100644
--- a/regression-test/suites/json_p0/test_json_load_and_function.groovy
+++ b/regression-test/suites/json_p0/test_json_load_and_function.groovy
@@ -152,6 +152,7 @@ suite("test_json_load_and_function", "p0") {
     qt_select "SELECT * FROM ${testTable} ORDER BY id"
 
     // json_extract
+    qt_select "SELECT json_extract( '{\"k1\\\\\": \"v1\"}', \"\$.k1\\\\\")"
     qt_select "SELECT id, j, jsonb_extract(j, '\$') FROM ${testTable} ORDER BY 
id"
     qt_select "SELECT id, j, jsonb_extract(j, '\$.*') FROM ${testTable} ORDER 
BY id"
 


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

Reply via email to