From 4d3db821bbc37f5c60290b385e57a2b033e903e1 Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Sat, 21 Aug 2021 17:03:16 +0800 Subject: [PATCH] Fix JSONExtract String with null value. --- src/Functions/FunctionsJSON.h | 2 ++ .../queries/0_stateless/01915_json_extract_raw_string.reference | 1 + tests/queries/0_stateless/01915_json_extract_raw_string.sql | 2 ++ 3 files changed, 5 insertions(+) diff --git a/src/Functions/FunctionsJSON.h b/src/Functions/FunctionsJSON.h index d0762ff9a8d..0ac04ae0dec 100644 --- a/src/Functions/FunctionsJSON.h +++ b/src/Functions/FunctionsJSON.h @@ -695,6 +695,8 @@ struct JSONExtractTree { if (element.isString()) return JSONExtractStringImpl::insertResultToColumn(dest, element, {}); + else if (element.isNull()) + return false; else return JSONExtractRawImpl::insertResultToColumn(dest, element, {}); } diff --git a/tests/queries/0_stateless/01915_json_extract_raw_string.reference b/tests/queries/0_stateless/01915_json_extract_raw_string.reference index 839cb33f5f2..3a41f35710c 100644 --- a/tests/queries/0_stateless/01915_json_extract_raw_string.reference +++ b/tests/queries/0_stateless/01915_json_extract_raw_string.reference @@ -1 +1,2 @@ ('123','456','[7,8,9]') +\N diff --git a/tests/queries/0_stateless/01915_json_extract_raw_string.sql b/tests/queries/0_stateless/01915_json_extract_raw_string.sql index 6ba94ac6dfd..4c5be79f6ef 100644 --- a/tests/queries/0_stateless/01915_json_extract_raw_string.sql +++ b/tests/queries/0_stateless/01915_json_extract_raw_string.sql @@ -1 +1,3 @@ select JSONExtract('{"a": "123", "b": 456, "c": [7, 8, 9]}', 'Tuple(a String, b String, c String)'); + +with '{"string_value":null}' as json select JSONExtract(json, 'string_value', 'Nullable(String)');