HappenLee commented on code in PR #54928:
URL: https://github.com/apache/doris/pull/54928#discussion_r2284981956


##########
be/src/vec/functions/function_string.h:
##########
@@ -2236,91 +2236,114 @@ class FunctionSplitByString : public IFunction {
     }
 };
 
+enum class FunctionCountSubStringType { TWO_ARGUMENTS, THREE_ARGUMENTS };
+
+template <FunctionCountSubStringType type>
 class FunctionCountSubString : public IFunction {
 public:
     static constexpr auto name = "count_substrings";
+    static constexpr auto arg_count = (type == 
FunctionCountSubStringType::TWO_ARGUMENTS) ? 2 : 3;
 
     static FunctionPtr create() { return 
std::make_shared<FunctionCountSubString>(); }
     using NullMapType = PaddedPODArray<UInt8>;
 
     String get_name() const override { return name; }
 
-    size_t get_number_of_arguments() const override { return 2; }
+    size_t get_number_of_arguments() const override { return arg_count; }
 
     DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
-        DCHECK(is_string_type(arguments[0]->get_primitive_type()))
-                << "first argument for function: " << name << " should be 
string"
-                << " and arguments[0] is " << arguments[0]->get_name();
-        DCHECK(is_string_type(arguments[1]->get_primitive_type()))
-                << "second argument for function: " << name << " should be 
string"
-                << " and arguments[1] is " << arguments[1]->get_name();
         return std::make_shared<DataTypeInt32>();
     }
 
+    DataTypes get_variadic_argument_types_impl() const override {
+        if constexpr (type == FunctionCountSubStringType::TWO_ARGUMENTS) {
+            return {std::make_shared<DataTypeString>(), 
std::make_shared<DataTypeString>()};
+        } else {
+            return {std::make_shared<DataTypeString>(), 
std::make_shared<DataTypeString>(),
+                    std::make_shared<DataTypeInt32>()};
+        }
+    }
+
+    bool is_variadic() const override { return true; }
+
     Status execute_impl(FunctionContext* /*context*/, Block& block, const 
ColumnNumbers& arguments,
                         uint32_t result, size_t input_rows_count) const 
override {
-        DCHECK_EQ(arguments.size(), 2);
-        const auto& [src_column, left_const] =
-                unpack_if_const(block.get_by_position(arguments[0]).column);
-        const auto& [right_column, right_const] =
-                unpack_if_const(block.get_by_position(arguments[1]).column);
-
-        const auto* col_left = 
check_and_get_column<ColumnString>(src_column.get());
-        if (!col_left) {
-            return Status::InternalError("Left operator of function {} can not 
be {}", get_name(),
-                                         
block.get_by_position(arguments[0]).type->get_name());
+        DCHECK(arguments.size() == 2 || arguments.size() == 3);

Review Comment:
   only need `dcheck(argmuments.size() == arg_count);`



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