From 11ab1f1ae5b324a1cdef5e6d1f6b0f7d5e0f37f6 Mon Sep 17 00:00:00 2001 From: kssenii Date: Thu, 18 Nov 2021 08:45:59 +0000 Subject: [PATCH] Fix --- src/Functions/FunctionSQLJSON.h | 8 +++++--- .../0_stateless/01889_sql_json_functions.reference | 4 ++++ tests/queries/0_stateless/01889_sql_json_functions.sql | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Functions/FunctionSQLJSON.h b/src/Functions/FunctionSQLJSON.h index db28663c64f..d860da62b9d 100644 --- a/src/Functions/FunctionSQLJSON.h +++ b/src/Functions/FunctionSQLJSON.h @@ -268,13 +268,15 @@ public: out << current_element.getElement(); auto output_str = out.str(); ColumnString & col_str = assert_cast(dest); + ColumnString::Chars & data = col_str.getChars(); + ColumnString::Offsets & offsets = col_str.getOffsets(); if (current_element.isString()) { ReadBufferFromString buf(output_str); - String unquoted_output_str; - readJSONString(unquoted_output_str, buf); - col_str.insertData(unquoted_output_str.data(), unquoted_output_str.size()); + readJSONStringInto(data, buf); + data.push_back(0); + offsets.push_back(data.size()); } else { diff --git a/tests/queries/0_stateless/01889_sql_json_functions.reference b/tests/queries/0_stateless/01889_sql_json_functions.reference index 4ed6a9ee611..c2c106e8632 100644 --- a/tests/queries/0_stateless/01889_sql_json_functions.reference +++ b/tests/queries/0_stateless/01889_sql_json_functions.reference @@ -98,4 +98,8 @@ SELECT id, JSON_QUERY(json, '$.friends[0 to 2]') FROM 01889_sql_json ORDER BY id 0 ["Vasily", "Kostya"] 1 ["Tihon", "Ernest"] 2 ["Katya", "Anatoliy"] +SELECT id, JSON_VALUE(json, '$.friends[0]') FROM 01889_sql_json ORDER BY id; +0 Vasily +1 Tihon +2 Katya DROP TABLE 01889_sql_json; diff --git a/tests/queries/0_stateless/01889_sql_json_functions.sql b/tests/queries/0_stateless/01889_sql_json_functions.sql index 967e21df787..e816443382c 100644 --- a/tests/queries/0_stateless/01889_sql_json_functions.sql +++ b/tests/queries/0_stateless/01889_sql_json_functions.sql @@ -55,4 +55,5 @@ INSERT INTO 01889_sql_json(id, json) VALUES(0, '{"name":"Ivan","surname":"Ivanov INSERT INTO 01889_sql_json(id, json) VALUES(1, '{"name":"Katya","surname":"Baltica","friends":["Tihon","Ernest","Innokentiy"]}'); INSERT INTO 01889_sql_json(id, json) VALUES(2, '{"name":"Vitali","surname":"Brown","friends":["Katya","Anatoliy","Ivan","Oleg"]}'); SELECT id, JSON_QUERY(json, '$.friends[0 to 2]') FROM 01889_sql_json ORDER BY id; +SELECT id, JSON_VALUE(json, '$.friends[0]') FROM 01889_sql_json ORDER BY id; DROP TABLE 01889_sql_json;