You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by da...@apache.org on 2022/10/20 06:11:03 UTC

[doris] branch branch-1.1-lts updated: [Bug](function)fix be coredump when using json_object function (#13500)

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

dataroaring pushed a commit to branch branch-1.1-lts
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-1.1-lts by this push:
     new de29beedd0 [Bug](function)fix be coredump when using json_object function (#13500)
de29beedd0 is described below

commit de29beedd03dd268dd61e3546f2330308df2b1a8
Author: ChPi <ch...@gmail.com>
AuthorDate: Thu Oct 20 14:10:56 2022 +0800

    [Bug](function)fix be coredump when using json_object function (#13500)
    
    Co-authored-by: chenjie <ch...@cecdat.com>
---
 be/src/exprs/json_functions.cpp                    |  2 +-
 .../json_function/test_query_json_object.out       |  9 +++++
 .../json_function/test_query_json_object.groovy    | 43 ++++++++++++++++++++++
 3 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/be/src/exprs/json_functions.cpp b/be/src/exprs/json_functions.cpp
index bfe26c2d20..35c3144bad 100644
--- a/be/src/exprs/json_functions.cpp
+++ b/be/src/exprs/json_functions.cpp
@@ -160,7 +160,7 @@ rapidjson::Value JsonFunctions::parse_str_with_flag(const StringVal& arg, const
                                                     const int num,
                                                     rapidjson::Document::AllocatorType& allocator) {
     rapidjson::Value val;
-    if (*(flag.ptr + num) == '0') { //null
+    if (arg.is_null || *(flag.ptr + num) == '0') { //null
         rapidjson::Value nullObject(rapidjson::kNullType);
         val = nullObject;
     } else if (*(flag.ptr + num) == '1') { //bool
diff --git a/regression-test/data/query/sql_functions/json_function/test_query_json_object.out b/regression-test/data/query/sql_functions/json_function/test_query_json_object.out
new file mode 100644
index 0000000000..ee1dd4abd8
--- /dev/null
+++ b/regression-test/data/query/sql_functions/json_function/test_query_json_object.out
@@ -0,0 +1,9 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !sql --
+{"k1":null}
+{"k1":null}
+{"k1":null}
+{"k1":null}
+{"k1":null}
+{"k1":1}
+
diff --git a/regression-test/suites/query/sql_functions/json_function/test_query_json_object.groovy b/regression-test/suites/query/sql_functions/json_function/test_query_json_object.groovy
new file mode 100644
index 0000000000..924bffcc75
--- /dev/null
+++ b/regression-test/suites/query/sql_functions/json_function/test_query_json_object.groovy
@@ -0,0 +1,43 @@
+// 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.
+
+suite("test_query_json_object", "query") {
+    sql "set enable_vectorized_engine = false;"
+    def tableName = "test_query_json_object"
+    sql "DROP TABLE IF EXISTS ${tableName}"
+    sql """
+            CREATE TABLE `${tableName}` (
+              `k1` int(11) NULL COMMENT "user id"
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`k1`)
+            COMMENT "OLAP"
+            DISTRIBUTED BY HASH(`k1`) BUCKETS 1
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1",
+            "in_memory" = "false",
+            "storage_format" = "V2"
+            );
+        """
+    sql "insert into ${tableName} values(null);"
+    sql "insert into ${tableName} values(null);"
+    sql "insert into ${tableName} values(null);"
+    sql "insert into ${tableName} values(null);"
+    sql "insert into ${tableName} values(null);"
+    sql "insert into ${tableName} values(1);"
+    qt_sql "select json_object(\"k1\",k1) from ${tableName};"
+    sql "DROP TABLE ${tableName};"
+}


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