2424
2525#include " config.h"
2626
27+
2728namespace DB
2829{
2930namespace ErrorCodes
@@ -33,6 +34,7 @@ extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION;
3334extern const int BAD_ARGUMENTS;
3435}
3536
37+
3638class FunctionSQLJSONHelpers
3739{
3840public:
@@ -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 ;
0 commit comments