wumeibanfa commented on code in PR #56648:
URL: https://github.com/apache/doris/pull/56648#discussion_r2425089657


##########
be/src/vec/utils/varbinaryop_subbinary.h:
##########
@@ -0,0 +1,102 @@
+// 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.
+
+#pragma once
+
+#include "vec/columns/column_const.h"
+#include "vec/columns/column_varbinary.h"
+#include "vec/core/block.h"
+#include "vec/core/types.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/data_types/data_type_varbinary.h"
+
+namespace doris::vectorized {
+#include "common/compile_check_begin.h"
+
+struct SubBinaryUtil {
+    static void sub_binary_execute(Block& block, const ColumnNumbers& 
arguments, uint32_t result,
+                                   size_t input_rows_count) {
+        DCHECK_EQ(arguments.size(), 3);
+        auto res = ColumnVarbinary::create();
+
+        bool col_const[3];
+        ColumnPtr argument_columns[3];
+        for (int i = 0; i < 3; ++i) {
+            std::tie(argument_columns[i], col_const[i]) =
+                    
unpack_if_const(block.get_by_position(arguments[i]).column);
+        }
+
+        const auto* specific_binary_column =
+                assert_cast<const ColumnVarbinary*>(argument_columns[0].get());
+        const auto* specific_start_column =
+                assert_cast<const ColumnInt32*>(argument_columns[1].get());
+        const auto* specific_len_column =
+                assert_cast<const ColumnInt32*>(argument_columns[2].get());
+
+        std::visit(
+                [&](auto binary_const, auto start_const, auto len_const) {
+                    vectors<binary_const, start_const, len_const>(
+                            specific_binary_column, specific_start_column, 
specific_len_column,
+                            res.get(), input_rows_count);
+                },
+                vectorized::make_bool_variant(col_const[0]),
+                vectorized::make_bool_variant(col_const[1]),
+                vectorized::make_bool_variant(col_const[2]));
+        block.get_by_position(result).column = std::move(res);
+    }
+
+private:
+    template <bool binary_const, bool start_const, bool len_const>
+    static void vectors(const ColumnVarbinary* binarys, const ColumnInt32* 
start,
+                        const ColumnInt32* len, ColumnVarbinary* res, size_t 
size) {
+        if constexpr (start_const && len_const) {
+            if (start->get_data()[0] == 0 || len->get_data()[0] <= 0) {

Review Comment:
   这里是模仿substring写的,如果要reserve,似乎也没必要添加这个if constexpr,可以直接reserve



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