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

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

commit 876248aa4e382d6268b44811909e6fecc8002ed0
Author: Mryange <59914473+mrya...@users.noreply.github.com>
AuthorDate: Sat May 11 14:17:43 2024 +0800

    [fix](function) json_object can not input null value (#34591)
---
 be/src/vec/functions/function_json.cpp             | 24 +++++++++++++++++++++-
 .../json_function/test_query_json_object.groovy    |  4 ++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/be/src/vec/functions/function_json.cpp 
b/be/src/vec/functions/function_json.cpp
index 4418561d881..e7c2fc1781d 100644
--- a/be/src/vec/functions/function_json.cpp
+++ b/be/src/vec/functions/function_json.cpp
@@ -619,6 +619,7 @@ struct ExecuteReducer {
 struct FunctionJsonArrayImpl {
     static constexpr auto name = "json_array";
 
+    static constexpr auto must_not_null = false;
     template <int flag>
     using Reducer = ExecuteReducer<flag, FunctionJsonArrayImpl>;
 
@@ -654,7 +655,7 @@ struct FunctionJsonArrayImpl {
 
 struct FunctionJsonObjectImpl {
     static constexpr auto name = "json_object";
-
+    static constexpr auto must_not_null = true;
     template <int flag>
     using Reducer = ExecuteReducer<flag, FunctionJsonObjectImpl>;
 
@@ -743,6 +744,9 @@ public:
                 data_columns.push_back(assert_cast<const 
ColumnString*>(column_ptrs.back().get()));
             }
         }
+        if (SpecificImpl::must_not_null) {
+            RETURN_IF_ERROR(check_keys_all_not_null(nullmaps, 
input_rows_count, arguments.size()));
+        }
         execute(data_columns, 
*assert_cast<ColumnString*>(result_column.get()), input_rows_count,
                 nullmaps);
         block.get_by_position(result).column = std::move(result_column);
@@ -774,6 +778,24 @@ public:
             result_column.insert_data(buf.GetString(), buf.GetSize());
         }
     }
+
+    static Status check_keys_all_not_null(const std::vector<const 
ColumnUInt8*>& nullmaps, int size,
+                                          size_t args) {
+        for (int i = 0; i < args; i += 2) {
+            const auto* null_map = nullmaps[i];
+            if (null_map) {
+                const bool not_null_num =
+                        
simd::count_zero_num((int8_t*)null_map->get_data().data(), size);
+                if (not_null_num < size) {
+                    return Status::InternalError(
+                            "function {} can not input null value , JSON 
documents may not contain "
+                            "NULL member names.",
+                            name);
+                }
+            }
+        }
+        return Status::OK();
+    }
 };
 
 struct FunctionJsonQuoteImpl {
diff --git 
a/regression-test/suites/query_p0/sql_functions/json_function/test_query_json_object.groovy
 
b/regression-test/suites/query_p0/sql_functions/json_function/test_query_json_object.groovy
index 2a12d69ffe0..e4ebe839276 100644
--- 
a/regression-test/suites/query_p0/sql_functions/json_function/test_query_json_object.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/json_function/test_query_json_object.groovy
@@ -41,5 +41,9 @@ suite("test_query_json_object", "query") {
     sql "insert into ${tableName} values(4,null,null,'test','2022-01-01 
11:11:11');"
     sql "insert into ${tableName} values(5,1,true,'test','2022-01-01 
11:11:11');"
     qt_sql1 "select json_object('k0',k0,'k1',k1,'k2',k2,'k3',k3,'k4',k4,'k5', 
null,'k6','k6') from ${tableName} order by k0;"
+    test {
+        sql """select k0,json_object(k3,123) from ${tableName} order by k0;"""
+        exception "[CANCELLED][INTERNAL_ERROR] function json_object can not 
input null value , JSON documents may not contain NULL member names."
+    }
     sql "DROP TABLE ${tableName};"
 }


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

Reply via email to