xiaokang commented on code in PR #24938:
URL: https://github.com/apache/doris/pull/24938#discussion_r1566598091


##########
be/src/vec/functions/function_jsonb.cpp:
##########
@@ -1287,6 +1289,157 @@ struct JsonbContainsAndPathImpl {
     }
 };
 
+template <typename Impl>
+class FunctionJsonbContainsPath : public IFunction {
+public:
+    static constexpr auto name = "json_contains_path";
+    String get_name() const override { return name; }
+    static FunctionPtr create() { return 
std::make_shared<FunctionJsonbContainsPath<Impl>>(); }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return make_nullable(std::make_shared<DataTypeUInt8>());
+    }
+
+    bool is_variadic() const override { return true; }
+
+    DataTypes get_variadic_argument_types_impl() const override {
+        if constexpr (vectorized::HasGetVariadicArgumentTypesImpl<Impl>) {
+            return Impl::get_variadic_argument_types_impl();
+        } else {
+            return {};
+        }
+    }
+    size_t get_number_of_arguments() const override {
+        return 0; // variadic
+    }
+
+    bool use_default_implementation_for_nulls() const override { return false; 
}
+
+    bool use_default_implementation_for_constants() const override { return 
false; }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) const override 
{
+        return Impl::execute_impl(context, block, arguments, result, 
input_rows_count);
+    }
+};
+
+struct JsonbContainsPathUtil {
+    static Status jsonb_contains_path_execute(FunctionContext* context, Block& 
block,
+                                              const ColumnNumbers& arguments, 
size_t result,
+                                              size_t input_rows_count) {
+        auto null_map = ColumnUInt8::create(input_rows_count, 0);
+        DCHECK_GE(arguments.size(), 3);
+
+        const auto jsonb_data_column = 
block.get_by_position(arguments[0]).column;
+        const auto one_or_all_column = 
block.get_by_position(arguments[1]).column;
+
+        std::vector<const ColumnString*> jsonb_path_columns;
+        std::vector<bool> path_const(arguments.size() - 2);
+        bool any_path_null = false;
+        for (int i = 0; i < arguments.size() - 2; ++i) {
+            ColumnPtr path_column;
+            bool is_const = false;
+            std::tie(path_column, is_const) =
+                    unpack_if_const(block.get_by_position(arguments[i + 
2]).column);
+            if (path_column->is_null_at(0)) {
+                any_path_null = true;
+            }
+            path_const[i] = is_const;
+            check_set_nullable(path_column, null_map, path_const[i]);
+            jsonb_path_columns.push_back(assert_cast<const 
ColumnString*>(path_column.get()));
+        }
+
+        std::vector<JsonbPath> json_path_list;
+        json_path_list.resize(jsonb_path_columns.size());
+
+        for (int i = 0; i < jsonb_path_columns.size(); ++i) {
+            if (path_const[i]) {
+                const auto path_value = jsonb_path_columns[i]->get_data_at(0);
+                if (!json_path_list[i].seek(path_value.data, path_value.size)) 
{
+                    return Status::InvalidArgument(
+                            "Json path error: {} for value: {}",
+                            
JsonbErrMsg::getErrMsg(JsonbErrType::E_INVALID_JSON_PATH),
+                            std::string_view(path_value.data, 
path_value.size));
+                }
+            }
+        }
+
+        const auto return_type = block.get_data_type(result);
+        MutableColumnPtr res = return_type->create_column();
+
+        for (size_t i = 0; i < input_rows_count; ++i) {
+            if (jsonb_data_column->is_null_at(i) || 
one_or_all_column->is_null_at(i) ||
+                any_path_null) {

Review Comment:
   for type 'one', if some path is null, should the result be null?



-- 
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]

Reply via email to