liutang123 commented on code in PR #50151:
URL: https://github.com/apache/doris/pull/50151#discussion_r2055448794
##########
be/src/vec/functions/function_jsonb.cpp:
##########
@@ -1758,16 +1834,31 @@ class FunctionJsonSearch : public IFunction {
}
// an error occurs if any path argument is not a valid path
expression.
+ // root_path_str = get_start_string(i);
Review Comment:
remove unused code.
##########
be/src/vec/functions/function_jsonb.cpp:
##########
@@ -1919,38 +1983,232 @@ class FunctionJsonSearch : public IFunction {
};
}
- // search_str
ColumnPtr col_search;
- bool search_is_const = false;
- std::tie(col_search, search_is_const) =
- unpack_if_const(block.get_by_position(arguments[2]).column);
+ *search_is_const = false;
- const ColumnString* col_search_string =
- check_and_get_column<ColumnString>(col_search.get());
- if (auto* nullable =
check_and_get_column<ColumnNullable>(col_search.get())) {
- col_search_string =
-
check_and_get_column<ColumnString>(*nullable->get_nested_column_ptr());
- }
- if (!col_search_string) {
- return Status::RuntimeError("Illegal arg pattern {} should be
ColumnString",
- col_search->get_name());
- }
- if (search_is_const) {
- CheckNullFun search_null_check = always_not_null;
+ RETURN_IF_ERROR(parse_column_args(context, block, arguments, 2,
search_is_const, col_search,
+ col_search_string));
+
+ if (*search_is_const) {
+ search_null_check = always_not_null;
if (col_search->is_null_at(0)) {
search_null_check = always_null;
}
- RETURN_IF_ERROR(execute_vector<true>(
+ } else {
+ search_null_check = [col_search](size_t i) { return
col_search->is_null_at(i); };
+ }
+
+ return Status::OK();
+ }
+};
+
+template <typename Impl>
+class FunctionJsonSearch : public IFunction {
+public:
+ static constexpr auto name = "json_search";
+ static FunctionPtr create() { return
std::make_shared<FunctionJsonSearch<Impl>>(); }
+
+ String get_name() const override { return name; }
+ bool is_variadic() const override { return true; }
+ DataTypes get_variadic_argument_types_impl() const override {
+ return Impl::get_variadic_argument_types();
+ }
+ size_t get_number_of_arguments() const override {
+ return get_variadic_argument_types_impl().size();
+ }
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
+ return make_nullable(std::make_shared<DataTypeJsonb>());
+ }
+ bool use_default_implementation_for_nulls() const override { return false;
}
+
+ Status open(FunctionContext* context, FunctionContext::FunctionStateScope
scope) override {
+ if (scope != FunctionContext::THREAD_LOCAL) {
+ return Status::OK();
+ }
+ if (context->is_col_constant(2)) {
+ std::shared_ptr<LikeState> state = std::make_shared<LikeState>();
+ state->is_like_pattern = true;
+ const auto pattern_col = context->get_constant_col(2)->column_ptr;
+ const auto& pattern = pattern_col->get_data_at(0);
+ RETURN_IF_ERROR(
+ FunctionLike::construct_like_const_state(context, pattern,
state, false));
+ context->set_function_state(scope, state);
Review Comment:
The escape char of `state` should be inited here.
##########
be/src/vec/functions/function_jsonb.cpp:
##########
@@ -1758,16 +1834,31 @@ class FunctionJsonSearch : public IFunction {
}
// an error occurs if any path argument is not a valid path
expression.
+ // root_path_str = get_start_string(i);
std::string root_path_str = "$";
+ if (!start_null_check(i)) {
+ root_path_str = get_start_string(i);
+ }
JsonbPath root_path;
- root_path.seek(root_path_str.c_str(), root_path_str.size());
+ if (!root_path.seek(root_path_str.c_str(), root_path_str.size())) {
+ return Status::InvalidArgument(
+ "the start_path argument {} is not a valid json path",
root_path_str);
+ }
std::vector<JsonbPath*> paths;
paths.push_back(&root_path);
if (!search_is_const) {
state_ptr = std::make_shared<LikeState>();
state_ptr->is_like_pattern = true;
const auto& search_str = col_search_string->get_data_at(i);
+
+ // The default is \ if the escape_char argument is missing or
NULL.
Review Comment:
`escape_char` must be a const column, you should check it and optimize the
`get_escape_string` logic.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]