Skip to content

Commit 8434074

Browse files
Backport #60738 to 23.3: Remove nonsense from SQL/JSON
1 parent 6220a88 commit 8434074

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

src/Functions/FunctionSQLJSON.h

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

2525
#include "config.h"
2626

27+
2728
namespace DB
2829
{
2930
namespace ErrorCodes
@@ -33,6 +34,7 @@ extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION;
3334
extern const int BAD_ARGUMENTS;
3435
}
3536

37+
3638
class FunctionSQLJSONHelpers
3739
{
3840
public:
@@ -72,25 +74,11 @@ class FunctionSQLJSONHelpers
7274
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Second argument (JSONPath) must be constant string");
7375
}
7476

75-
const ColumnPtr & arg_jsonpath = json_path_column.column;
76-
const auto * arg_jsonpath_const = typeid_cast<const ColumnConst *>(arg_jsonpath.get());
77-
const auto * arg_jsonpath_string = typeid_cast<const ColumnString *>(arg_jsonpath_const->getDataColumnPtr().get());
78-
79-
const ColumnPtr & arg_json = json_column.column;
80-
const auto * col_json_const = typeid_cast<const ColumnConst *>(arg_json.get());
81-
const auto * col_json_string
82-
= typeid_cast<const ColumnString *>(col_json_const ? col_json_const->getDataColumnPtr().get() : arg_json.get());
83-
84-
/// Get data and offsets for 1 argument (JSONPath)
85-
const ColumnString::Chars & chars_path = arg_jsonpath_string->getChars();
86-
const ColumnString::Offsets & offsets_path = arg_jsonpath_string->getOffsets();
87-
8877
/// Prepare to parse 1 argument (JSONPath)
89-
const char * query_begin = reinterpret_cast<const char *>(&chars_path[0]);
90-
const char * query_end = query_begin + offsets_path[0] - 1;
78+
String query = typeid_cast<const ColumnConst &>(*json_path_column.column).getValue<String>();
9179

92-
/// Tokenize query
93-
Tokens tokens(query_begin, query_end);
80+
/// Tokenize the query
81+
Tokens tokens(query.data(), query.data() + query.size());
9482
/// Max depth 0 indicates that depth is not limited
9583
IParser::Pos token_iterator(tokens, parse_depth);
9684

@@ -104,10 +92,6 @@ class FunctionSQLJSONHelpers
10492
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unable to parse JSONPath");
10593
}
10694

107-
/// Get data and offsets for 2 argument (JSON)
108-
const ColumnString::Chars & chars_json = col_json_string->getChars();
109-
const ColumnString::Offsets & offsets_json = col_json_string->getOffsets();
110-
11195
JSONParser json_parser;
11296
using Element = typename JSONParser::Element;
11397
Element document;
@@ -116,10 +100,9 @@ class FunctionSQLJSONHelpers
116100
/// Parse JSON for every row
117101
Impl<JSONParser> impl;
118102

119-
for (const auto i : collections::range(0, input_rows_count))
103+
for (size_t i = 0; i < input_rows_count; ++i)
120104
{
121-
std::string_view json{
122-
reinterpret_cast<const char *>(&chars_json[offsets_json[i - 1]]), offsets_json[i] - offsets_json[i - 1] - 1};
105+
std::string_view json = json_column.column->getDataAt(i).toView();
123106
document_ok = json_parser.parse(json, document);
124107

125108
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)