Skip to content

Commit 1e77403

Browse files
authored
[fix](function)fix be coredump when using json_object function (#13443)
1 parent 32b1456 commit 1e77403

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

be/src/exprs/json_functions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ rapidjson::Value JsonFunctions::parse_str_with_flag(const StringVal& arg, const
156156
const int num,
157157
rapidjson::Document::AllocatorType& allocator) {
158158
rapidjson::Value val;
159-
if (*(flag.ptr + num) == '0') { //null
159+
if (arg.is_null || *(flag.ptr + num) == '0') { //null
160160
rapidjson::Value nullObject(rapidjson::kNullType);
161161
val = nullObject;
162162
} else if (*(flag.ptr + num) == '1') { //bool
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !sql --
3+
{"k1":null}
4+
{"k1":null}
5+
{"k1":null}
6+
{"k1":null}
7+
{"k1":null}
8+
{"k1":1}
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("test_query_json_object", "query") {
19+
sql "set enable_vectorized_engine = false;"
20+
def tableName = "test_query_json_object"
21+
sql "DROP TABLE IF EXISTS ${tableName}"
22+
sql """
23+
CREATE TABLE `${tableName}` (
24+
`k1` int(11) NULL COMMENT "user id"
25+
) ENGINE=OLAP
26+
DUPLICATE KEY(`k1`)
27+
COMMENT "OLAP"
28+
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
29+
PROPERTIES (
30+
"replication_allocation" = "tag.location.default: 1",
31+
"in_memory" = "false",
32+
"storage_format" = "V2"
33+
);
34+
"""
35+
sql "insert into ${tableName} values(null);"
36+
sql "insert into ${tableName} values(null);"
37+
sql "insert into ${tableName} values(null);"
38+
sql "insert into ${tableName} values(null);"
39+
sql "insert into ${tableName} values(null);"
40+
sql "insert into ${tableName} values(1);"
41+
qt_sql "select json_object(\"k1\",k1) from ${tableName};"
42+
sql "DROP TABLE ${tableName};"
43+
}

0 commit comments

Comments
 (0)