linrrzqqq commented on code in PR #60412:
URL: https://github.com/apache/doris/pull/60412#discussion_r3056692196


##########
be/src/exprs/function/function_hamming_distance.cpp:
##########
@@ -0,0 +1,278 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <algorithm>
+#include <cstring>
+#include <vector>
+
+#include "common/status.h"
+#include "core/column/column_nullable.h"
+#include "core/column/column_string.h"
+#include "core/data_type/data_type_number.h"
+#include "core/string_ref.h"
+#include "exprs/function/simple_function_factory.h"
+#include "util/simd/vstring_function.h"
+
+namespace doris {
+#include "common/compile_check_begin.h"
+
+class FunctionHammingDistance : public IFunction {
+public:
+    using ResultDataType = DataTypeInt64;
+    using ResultPaddedPODArray = PaddedPODArray<Int64>;
+    using ResultColumnType = ColumnVector<ResultDataType::PType>;
+
+    static constexpr auto name = "hamming_distance";
+
+    static FunctionPtr create() { return 
std::make_shared<FunctionHammingDistance>(); }
+
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 2; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        const bool has_nullable = std::ranges::any_of(
+                arguments, [](const DataTypePtr& type) { return 
type->is_nullable(); });
+        if (has_nullable) {
+            return make_nullable(std::make_shared<ResultDataType>());
+        }
+        return std::make_shared<ResultDataType>();
+    }
+
+    bool use_default_implementation_for_nulls() const override { return false; 
}
+
+    Status execute_impl(FunctionContext* /*context*/, Block& block, const 
ColumnNumbers& arguments,
+                        uint32_t result, size_t input_rows_count) const 
override {
+        const auto& [left_col, left_const] =
+                unpack_if_const(block.get_by_position(arguments[0]).column);
+        const auto& [right_col, right_const] =
+                unpack_if_const(block.get_by_position(arguments[1]).column);
+
+        const auto* left_nullable = 
check_and_get_column<ColumnNullable>(left_col.get());
+        const auto* right_nullable = 
check_and_get_column<ColumnNullable>(right_col.get());
+
+        const IColumn* left_nested =
+                left_nullable ? &left_nullable->get_nested_column() : 
left_col.get();
+        const IColumn* right_nested =
+                right_nullable ? &right_nullable->get_nested_column() : 
right_col.get();
+
+        const auto* left_str_col = 
check_and_get_column<ColumnString>(left_nested);
+        const auto* right_str_col = 
check_and_get_column<ColumnString>(right_nested);
+        if (!left_str_col || !right_str_col) {
+            return Status::NotSupported("Illegal columns {}, {} of argument of 
function {}",
+                                        left_col->get_name(), 
right_col->get_name(), get_name());
+        }
+
+        auto res_col = ResultColumnType::create(input_rows_count);
+        auto& res_data = res_col->get_data();
+
+        const NullMap* left_null_map =
+                left_nullable ? &left_nullable->get_null_map_data() : nullptr;
+        const NullMap* right_null_map =
+                right_nullable ? &right_nullable->get_null_map_data() : 
nullptr;
+        const bool has_nullable = left_null_map != nullptr || right_null_map 
!= nullptr;
+
+        if (!has_nullable) {

Review Comment:
   ```cpp
       if (left_const) {
           if (left_null[0]) {
               auto res_null_map = ColumnUint8::create(input_rows_count, 1);
               block.replace_by_position(result, 
ColumnNullable::create(res_col), std::move(res_null_map));
               return Status::OK();
           }
           // const_vector
       } else if (right_const) {
           if (right_null[0]) {
               ...
           }
           // vec_const
       } else {
           // vec_vec
       }
   ```



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