Skip to content

Commit c48e331

Browse files
Backport #60738 to 24.2: Remove nonsense from SQL/JSON
1 parent 2d35fb4 commit c48e331

3 files changed

Lines changed: 8 additions & 26 deletions

File tree

src/Functions/FunctionSQLJSON.h

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "config.h"
2828

29+
2930
namespace DB
3031
{
3132
namespace ErrorCodes
@@ -114,8 +115,6 @@ class JSONStringSerializer
114115

115116
};
116117

117-
class EmptyJSONStringSerializer{};
118-
119118

120119
class FunctionSQLJSONHelpers
121120
{
@@ -156,25 +155,11 @@ class FunctionSQLJSONHelpers
156155
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Second argument (JSONPath) must be constant string");
157156
}
158157

159-
const ColumnPtr & arg_jsonpath = json_path_column.column;
160-
const auto * arg_jsonpath_const = typeid_cast<const ColumnConst *>(arg_jsonpath.get());
161-
const auto * arg_jsonpath_string = typeid_cast<const ColumnString *>(arg_jsonpath_const->getDataColumnPtr().get());
162-
163-
const ColumnPtr & arg_json = json_column.column;
164-
const auto * col_json_const = typeid_cast<const ColumnConst *>(arg_json.get());
165-
const auto * col_json_string
166-
= typeid_cast<const ColumnString *>(col_json_const ? col_json_const->getDataColumnPtr().get() : arg_json.get());
167-
168-
/// Get data and offsets for 1 argument (JSONPath)
169-
const ColumnString::Chars & chars_path = arg_jsonpath_string->getChars();
170-
const ColumnString::Offsets & offsets_path = arg_jsonpath_string->getOffsets();
171-
172158
/// Prepare to parse 1 argument (JSONPath)
173-
const char * query_begin = reinterpret_cast<const char *>(&chars_path[0]);
174-
const char * query_end = query_begin + offsets_path[0] - 1;
159+
String query = typeid_cast<const ColumnConst &>(*json_path_column.column).getValue<String>();
175160

176-
/// Tokenize query
177-
Tokens tokens(query_begin, query_end);
161+
/// Tokenize the query
162+
Tokens tokens(query.data(), query.data() + query.size());
178163
/// Max depth 0 indicates that depth is not limited
179164
IParser::Pos token_iterator(tokens, parse_depth);
180165

@@ -188,10 +173,6 @@ class FunctionSQLJSONHelpers
188173
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unable to parse JSONPath");
189174
}
190175

191-
/// Get data and offsets for 2 argument (JSON)
192-
const ColumnString::Chars & chars_json = col_json_string->getChars();
193-
const ColumnString::Offsets & offsets_json = col_json_string->getOffsets();
194-
195176
JSONParser json_parser;
196177
using Element = typename JSONParser::Element;
197178
Element document;
@@ -200,10 +181,9 @@ class FunctionSQLJSONHelpers
200181
/// Parse JSON for every row
201182
Impl impl;
202183
GeneratorJSONPath<JSONParser> generator_json_path(res);
203-
for (const auto i : collections::range(0, input_rows_count))
184+
for (size_t i = 0; i < input_rows_count; ++i)
204185
{
205-
std::string_view json{
206-
reinterpret_cast<const char *>(&chars_json[offsets_json[i - 1]]), offsets_json[i] - offsets_json[i - 1] - 1};
186+
std::string_view json = json_column.column->getDataAt(i).toView();
207187
document_ok = json_parser.parse(json, document);
208188

209189
bool added_to_column = false;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT JSON_QUERY('{"x":1}', '$[\'hello\']', materialize(toLowCardinality('x')));

0 commit comments

Comments
 (0)