diff --git a/dbms/src/Functions/FunctionsJSON.h b/dbms/src/Functions/FunctionsJSON.h index bc1764d2e26..8bf69e6c7d7 100644 --- a/dbms/src/Functions/FunctionsJSON.h +++ b/dbms/src/Functions/FunctionsJSON.h @@ -120,11 +120,22 @@ private: /// prepare() does Impl-specific preparation before handling each row. impl.prepare(Name::name, block, arguments, result_pos); + bool json_parsed_ok = false; + if (col_json_const) + { + StringRef json{reinterpret_cast(&chars[0]), offsets[0] - 1}; + json_parsed_ok = parser.parse(json); + } + for (const auto i : ext::range(0, input_rows_count)) { - StringRef json{reinterpret_cast(&chars[offsets[i - 1]]), offsets[i] - offsets[i - 1] - 1}; - bool ok = parser.parse(json); + if (!col_json_const) + { + StringRef json{reinterpret_cast(&chars[offsets[i - 1]]), offsets[i] - offsets[i - 1] - 1}; + json_parsed_ok = parser.parse(json); + } + bool ok = json_parsed_ok; if (ok) { auto it = parser.getRoot(); diff --git a/dbms/tests/queries/0_stateless/00918_json_functions.reference b/dbms/tests/queries/0_stateless/00918_json_functions.reference index e98579a1aba..631d421b66f 100644 --- a/dbms/tests/queries/0_stateless/00918_json_functions.reference +++ b/dbms/tests/queries/0_stateless/00918_json_functions.reference @@ -64,3 +64,11 @@ Friday {} "\\n\\u0000" "☺" +--const/non-const mixed-- +a +b +c +d +e +u +v diff --git a/dbms/tests/queries/0_stateless/00918_json_functions.sql b/dbms/tests/queries/0_stateless/00918_json_functions.sql index c58e3b70e07..1a9ce2bbc11 100644 --- a/dbms/tests/queries/0_stateless/00918_json_functions.sql +++ b/dbms/tests/queries/0_stateless/00918_json_functions.sql @@ -72,5 +72,9 @@ SELECT JSONExtractRaw('{"a": "hello", "b": [-100, 200.0, 300], "c":{"d":[121,144 SELECT JSONExtractRaw('{"a": "hello", "b": [-100, 200.0, 300], "c":{"d":[121,144]}}', 'c', 'd', 3); SELECT JSONExtractRaw('{"passed": true}'); SELECT JSONExtractRaw('{}'); -select JSONExtractRaw('{"abc":"\\n\\u0000"}', 'abc'); -select JSONExtractRaw('{"abc":"\\u263a"}', 'abc'); +SELECT JSONExtractRaw('{"abc":"\\n\\u0000"}', 'abc'); +SELECT JSONExtractRaw('{"abc":"\\u263a"}', 'abc'); + +SELECT '--const/non-const mixed--'; +SELECT JSONExtractString('["a", "b", "c", "d", "e"]', idx) FROM (SELECT arrayJoin([1,2,3,4,5]) AS idx); +SELECT JSONExtractString(json, 's') FROM (SELECT arrayJoin(['{"s":"u"}', '{"s":"v"}']) AS json);