Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion be/src/vec/functions/function_jsonb.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -793,7 +793,7 @@ struct JsonbExtractStringImpl {
std::string_view(str_value->getBlob(), str_value->length()), i, res_data,
res_offsets);
} else if (value->isNull()) {
StringOP::push_value_string("null", i, res_data, res_offsets);
StringOP::push_null_string(i, res_data, res_offsets, null_map);
} else if (value->isTrue()) {
StringOP::push_value_string("true", i, res_data, res_offsets);
} else if (value->isFalse()) {
Expand Down
8 changes: 4 additions & 4 deletions be/test/vec/function/function_jsonb_test.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -667,7 +667,7 @@ TEST(FunctionJsonbTEST, JsonbExtractStringTest) {
// json_extract root
DataSet data_set = {
{{Null(), STRING("$")}, Null()},
{{STRING("null"), STRING("$")}, STRING("null")},
{{STRING("null"), STRING("$")}, Null()},
{{STRING("true"), STRING("$")}, STRING("true")},
{{STRING("false"), STRING("$")}, STRING("false")},
{{STRING("100"), STRING("$")}, STRING("100")}, //int8
Expand DownExpand Up@@ -751,7 +751,7 @@ TEST(FunctionJsonbTEST, JsonbExtractStringTest) {
{{STRING(R"(["abc", "def"])"), STRING("$[1]")}, STRING("def")}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[2]")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0]")},
STRING("null")}, // multi type array
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[1]")},
STRING("true")}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[2]")},
Expand DownExpand Up@@ -1298,7 +1298,7 @@ TEST(FunctionJsonbTEST, GetJSONSTRINGTest) {
// get json from root
DataSet data_set = {
{{Null(), STRING("$")}, Null()},
{{STRING("null"), STRING("$")}, STRING("null")},
{{STRING("null"), STRING("$")}, Null()},
{{STRING("true"), STRING("$")}, STRING("true")},
{{STRING("false"), STRING("$")}, STRING("false")},
{{STRING("100"), STRING("$")}, STRING("100")}, //int8
Expand DownExpand Up@@ -1382,7 +1382,7 @@ TEST(FunctionJsonbTEST, GetJSONSTRINGTest) {
{{STRING(R"(["abc", "def"])"), STRING("$[1]")}, STRING("def")}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[2]")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0]")},
STRING("null")}, // multi type array
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[1]")},
STRING("true")}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[2]")},
Expand Down
8 changes: 4 additions & 4 deletions regression-test/data/json_p0/test_json_load_and_function.out
Original file line numberDiff line numberDiff line change
Expand Up@@ -783,7 +783,7 @@

-- !select --
1 \N \N
2 null null
2 null \N
3 true true
4 false false
5 100 100
Expand DownExpand Up@@ -884,7 +884,7 @@
13 [] \N
14 [123,456] 123
15 ["abc","def"] abc
16 [null,true,false,100,6.18,"abc"] null
16 [null,true,false,100,6.18,"abc"] \N
17 [{"k1":"v41","k2":400},1,"a",3.14] {"k1":"v41","k2":400}
18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]}
26 \N \N
Expand DownExpand Up@@ -7023,7 +7023,7 @@ false
34 {"":1,"ab":"v1","":"v1","":2} \N

-- !select --
2 null null
2 null \N
3 true true
4 false false
5 100 100
Expand DownExpand Up@@ -7118,7 +7118,7 @@ false
13 [] \N
14 [123,456] 123
15 ["abc","def"] abc
16 [null,true,false,100,6.18,"abc"] null
16 [null,true,false,100,6.18,"abc"] \N
17 [{"k1":"v41","k2":400},1,"a",3.14] {"k1":"v41","k2":400}
18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]}
27 {"k1":"v1","k2":200} {"k1":"v1","k2":200}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -619,7 +619,7 @@

-- !select --
1 \N \N
2 null null
2 null \N
3 true true
4 false false
5 100 100
Expand DownExpand Up@@ -702,7 +702,7 @@
13 [] \N
14 [123,456] 123
15 ["abc","def"] abc
16 [null,true,false,100,6.18,"abc"] null
16 [null,true,false,100,6.18,"abc"] \N
17 [{"k1":"v41","k2":400},1,"a",3.14] {"k1":"v41","k2":400}
18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]}
26 \N \N
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -925,7 +925,7 @@

-- !jsonb_extract_string_select --
1 \N \N
2 null null
2 null \N
3 true true
4 false false
5 100 100
Expand DownExpand Up@@ -1026,7 +1026,7 @@
13 [] \N
14 [123,456] 123
15 ["abc","def"] abc
16 [null,true,false,100,6.18,"abc"] null
16 [null,true,false,100,6.18,"abc"] \N
17 [{"k1":"v41","k2":400},1,"a",3.14] {"k1":"v41","k2":400}
18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]}
26 \N \N
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -734,7 +734,7 @@

-- !jsonb_extract_string_select --
1 \N \N
2 null null
2 null \N
3 true true
4 false false
5 100 100
Expand DownExpand Up@@ -817,7 +817,7 @@
13 [] \N
14 [123,456] 123
15 ["abc","def"] abc
16 [null,true,false,100,6.18,"abc"] null
16 [null,true,false,100,6.18,"abc"] \N
17 [{"k1":"v41","k2":400},1,"a",3.14] {"k1":"v41","k2":400}
18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]}
26 \N \N
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -827,7 +827,7 @@

-- !jsonb_extract_string_select --
1 \N \N
2 null null
2 null \N
3 true true
4 false false
5 100 100
Expand DownExpand Up@@ -919,7 +919,7 @@
13 [] \N
14 [123,456] 123
15 ["abc","def"] abc
16 [null,true,false,100,6.18,"abc"] null
16 [null,true,false,100,6.18,"abc"] \N
17 [{"k1":"v41","k2":400},1,"a",3.14] {"k1":"v41","k2":400}
18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]}
26 \N \N
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -780,7 +780,7 @@

-- !select --
1 \N \N
2 null null
2 null \N
3 true true
4 false false
5 100 100
Expand DownExpand Up@@ -881,7 +881,7 @@
13 [] \N
14 [123,456] 123
15 ["abc","def"] abc
16 [null,true,false,100,6.18,"abc"] null
16 [null,true,false,100,6.18,"abc"] \N
17 [{"k1":"v41","k2":400},1,"a",3.14] {"k1":"v41","k2":400}
18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]}
26 \N \N
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -619,7 +619,7 @@

-- !select --
1 \N \N
2 null null
2 null \N
3 true true
4 false false
5 100 100
Expand DownExpand Up@@ -702,7 +702,7 @@
13 [] \N
14 [123,456] 123
15 ["abc","def"] abc
16 [null,true,false,100,6.18,"abc"] null
16 [null,true,false,100,6.18,"abc"] \N
17 [{"k1":"v41","k2":400},1,"a",3.14] {"k1":"v41","k2":400}
18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]}
26 \N \N
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -925,7 +925,7 @@

-- !jsonb_extract_string_select --
1 \N \N
2 null null
2 null \N
3 true true
4 false false
5 100 100
Expand DownExpand Up@@ -1026,7 +1026,7 @@
13 [] \N
14 [123,456] 123
15 ["abc","def"] abc
16 [null,true,false,100,6.18,"abc"] null
16 [null,true,false,100,6.18,"abc"] \N
17 [{"k1":"v41","k2":400},1,"a",3.14] {"k1":"v41","k2":400}
18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]}
26 \N \N
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -734,7 +734,7 @@

-- !jsonb_extract_string_select --
1 \N \N
2 null null
2 null \N
3 true true
4 false false
5 100 100
Expand DownExpand Up@@ -817,7 +817,7 @@
13 [] \N
14 [123,456] 123
15 ["abc","def"] abc
16 [null,true,false,100,6.18,"abc"] null
16 [null,true,false,100,6.18,"abc"] \N
17 [{"k1":"v41","k2":400},1,"a",3.14] {"k1":"v41","k2":400}
18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]}
26 \N \N
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql_string1 --
v31

-- !sql_string2 --
\N

-- !sql_string3 --
\N

-- !sql_string4 --
1234.56

-- !sql_string5 --
2025-06-05 14:47:01.000000

-- !sql_string6 --
\N

-- !sql_string7 --
\N

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
// 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_json_extract") {
qt_sql_string1 """ SELECT JSON_EXTRACT_STRING('{"k1":"v31","k2":300}', '\$.k1'); """
qt_sql_string2 """ SELECT JSON_EXTRACT_STRING(null, '\$.k1'); """
qt_sql_string3 """ SELECT JSON_EXTRACT_STRING('{"k1":"v31","k2":300}', NULL); """
qt_sql_string4 """ SELECT JSON_EXTRACT_STRING('{"k1":"v31","k2":{"sub_key": 1234.56}}', '\$.k2.sub_key'); """
qt_sql_string5 """ SELECT JSON_EXTRACT_STRING(json_array("abc", 123, STR_TO_DATE('2025-06-05 14:47:01', '%Y-%m-%d %H:%i:%s')), '\$[2]'); """
qt_sql_string6 """ SELECT JSON_EXTRACT_STRING('{"k1":"v31","k2": null}', '\$.k2'); """
qt_sql_string7 """ SELECT JSON_EXTRACT_STRING('{"k1":"v31","k2":300}', '\$.k3'); """

test {
sql """ SELECT JSON_EXTRACT_STRING('{"id": 123, "name": "doris"}', '\$.'); """
exception "Invalid Json Path for value: \$."
}
}