DayuanX commented on code in PR #54036:
URL: https://github.com/apache/doris/pull/54036#discussion_r2325725433


##########
be/src/vec/functions/function_map.cpp:
##########
@@ -440,13 +518,400 @@ class FunctionStrToMap : public IFunction {
     }
 };
 
+class FunctionMapContainsEntry : public IFunction {
+public:
+    static constexpr auto name = "map_contains_entry";
+    static FunctionPtr create() { return 
std::make_shared<FunctionMapContainsEntry>(); }
+
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 3; }
+    bool use_default_implementation_for_nulls() const override { return false; 
}
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        DataTypePtr datatype = arguments[0];
+        if (datatype->is_nullable()) {
+            datatype = assert_cast<const 
DataTypeNullable*>(datatype.get())->get_nested_type();
+        }
+        DCHECK(datatype->get_primitive_type() == TYPE_MAP)
+                << "first argument for function: " << name << " should be 
DataTypeMap";
+
+        if (arguments[0]->is_nullable()) {
+            return make_nullable(std::make_shared<DataTypeBool>());
+        } else {
+            return std::make_shared<DataTypeBool>();
+        }
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        uint32_t result, size_t input_rows_count) const 
override {
+        return _execute_type_check_and_dispatch(block, arguments, result);
+    }
+
+private:
+    // assume result_matches is initialized to all 1s
+    template <typename ColumnType>
+    void _execute_column_comparison(const IColumn& map_entry_column, const 
UInt8* map_entry_nullmap,
+                                    const IColumn& search_column, const UInt8* 
search_nullmap,
+                                    const ColumnArray::Offsets64& map_offsets,
+                                    const UInt8* map_row_nullmap, bool 
search_is_const,
+                                    ColumnUInt8& result_matches) const {
+        auto& result_data = result_matches.get_data();
+        for (size_t row = 0; row < map_offsets.size(); ++row) {
+            if (map_row_nullmap && map_row_nullmap[row]) {
+                continue;
+            }
+            size_t map_start = row == 0 ? 0 : map_offsets[row - 1];
+            size_t map_end = map_offsets[row];
+            // const column always uses index 0
+            size_t search_idx = search_is_const ? 0 : row;
+            for (size_t i = map_start; i < map_end; ++i) {
+                result_data[i] &=
+                        compare_values<ColumnType>(map_entry_column, i, 
map_entry_nullmap,
+                                                   search_column, search_idx, 
search_nullmap)
+                                ? 1
+                                : 0;
+            }
+        }
+    }
+
+    // dispatch column comparison by type, map_entry_column is the column of 
map's key or value, search_column is the column of search key or value
+    void _dispatch_column_comparison(PrimitiveType type, const IColumn& 
map_entry_column,
+                                     const UInt8* map_entry_nullmap, const 
IColumn& search_column,
+                                     const UInt8* search_nullmap,
+                                     const ColumnArray::Offsets64& map_offsets,
+                                     const UInt8* map_row_nullmap, bool 
search_is_const,
+                                     ColumnUInt8& result_matches) const {
+        switch (type) {
+        case TYPE_BOOLEAN:

Review Comment:
   fixed



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