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


##########
be/src/exprs/function/function_hamming_distance.cpp:
##########
@@ -0,0 +1,345 @@
+// 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 {
+
+class FunctionHammingDistance : public IFunction {

Review Comment:
   I checked both templates, but using them would change the semantics.
   
   `FunctionBinaryToType` is not enough because `hamming_distance` has a 
row-level error path. For example, `hamming_distance('abc', 'ab')` must return 
`InvalidArgument` for unequal character length. The normal binary-to-type 
template is for pure value calculation and does not cover this custom 
validation/null ordering well.
   
   `FunctionBinaryStringOperateToNullType` is also not suitable because it 
always returns Nullable and uses a result null map. That would be wrong for 
`hamming_distance('abc', 'abd')`, which should return non-nullable Int64 `1` 
when both inputs are non-nullable. It would also blur the difference between 
invalid input and NULL: `hamming_distance('abc', 'ab')` should be an error, 
while `hamming_distance(NULL, 'abc')` should be NULL.
   
   This function also needs custom const/null fast paths, e.g. 
`hamming_distance(NULL, col)` can return all NULL directly, and 
`hamming_distance('abc', nullable_col)` should keep the scalar-vector path 
instead of falling back to generic row-by-row processing.
   



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