github-actions[bot] commented on code in PR #31833:
URL: https://github.com/apache/doris/pull/31833#discussion_r1513758571


##########
be/src/vec/functions/function_string.h:
##########
@@ -351,10 +508,83 @@
         ColumnPtr str_col;
         bool str_const;
         std::tie(str_col, str_const) = 
unpack_if_const(block.get_by_position(arguments[0]).column);
-        if (auto* nullable = check_and_get_column<const 
ColumnNullable>(*str_col)) {
+
+        const auto& str_offset = assert_cast<const 
ColumnString*>(str_col.get())->get_offsets();
+
+        if (str_const) {
+            std::fill(strlen_data.begin(), strlen_data.end(), str_offset[0] - 
str_offset[-1]);
+        } else {
+            for (int i = 0; i < input_rows_count; ++i) {
+                strlen_data[i] = str_offset[i] - str_offset[i - 1];
+            }
+        }
+
+        // we complete the column2(strlen) with the default value - each row's 
strlen.
+        block.insert({std::move(col_len), std::make_shared<DataTypeInt32>(), 
"strlen"});
+        ColumnNumbers temp_arguments = {arguments[0], arguments[1], 
block.columns() - 1};
+
+        SubstringUtil::substring_execute(block, temp_arguments, result, 
input_rows_count);
+        return Status::OK();
+    }
+};
+
+template <typename Impl>
+class FunctionSubstringOld : public IFunction {
+public:
+    static constexpr auto name = SubstringUtilOld::name;
+    String get_name() const override { return name; }
+    static FunctionPtr create() { return 
std::make_shared<FunctionSubstringOld<Impl>>(); }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return make_nullable(std::make_shared<DataTypeString>());
+    }
+    DataTypes get_variadic_argument_types_impl() const override {
+        return Impl::get_variadic_argument_types();
+    }
+    size_t get_number_of_arguments() const override {

Review Comment:
   warning: function 'get_number_of_arguments' should be marked [[nodiscard]] 
[modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] size_t get_number_of_arguments() const override {
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -315,7 +472,7 @@ class FunctionSubstring : public IFunction {
         return get_variadic_argument_types_impl().size();
     }
 
-    bool use_default_implementation_for_nulls() const override { return false; 
}
+    bool use_default_implementation_for_nulls() const override { return true; }

Review Comment:
   warning: function 'use_default_implementation_for_nulls' should be marked 
[[nodiscard]] [modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] bool use_default_implementation_for_nulls() const override 
{ return true; }
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -567,6 +797,34 @@
     static FunctionPtr create() { return std::make_shared<FunctionLeft>(); }
     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 {
+        return std::make_shared<DataTypeString>();
+    }
+
+    bool use_default_implementation_for_nulls() const override { return true; }

Review Comment:
   warning: function 'use_default_implementation_for_nulls' should be marked 
[[nodiscard]] [modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] bool use_default_implementation_for_nulls() const override 
{ return true; }
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -351,10 +508,83 @@
         ColumnPtr str_col;
         bool str_const;
         std::tie(str_col, str_const) = 
unpack_if_const(block.get_by_position(arguments[0]).column);
-        if (auto* nullable = check_and_get_column<const 
ColumnNullable>(*str_col)) {
+
+        const auto& str_offset = assert_cast<const 
ColumnString*>(str_col.get())->get_offsets();
+
+        if (str_const) {
+            std::fill(strlen_data.begin(), strlen_data.end(), str_offset[0] - 
str_offset[-1]);
+        } else {
+            for (int i = 0; i < input_rows_count; ++i) {
+                strlen_data[i] = str_offset[i] - str_offset[i - 1];
+            }
+        }
+
+        // we complete the column2(strlen) with the default value - each row's 
strlen.
+        block.insert({std::move(col_len), std::make_shared<DataTypeInt32>(), 
"strlen"});
+        ColumnNumbers temp_arguments = {arguments[0], arguments[1], 
block.columns() - 1};
+
+        SubstringUtil::substring_execute(block, temp_arguments, result, 
input_rows_count);
+        return Status::OK();
+    }
+};
+
+template <typename Impl>
+class FunctionSubstringOld : public IFunction {
+public:
+    static constexpr auto name = SubstringUtilOld::name;
+    String get_name() const override { return name; }
+    static FunctionPtr create() { return 
std::make_shared<FunctionSubstringOld<Impl>>(); }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return make_nullable(std::make_shared<DataTypeString>());
+    }
+    DataTypes get_variadic_argument_types_impl() const override {
+        return Impl::get_variadic_argument_types();
+    }
+    size_t get_number_of_arguments() const override {
+        return get_variadic_argument_types_impl().size();
+    }
+
+    bool use_default_implementation_for_nulls() const override { return false; 
}

Review Comment:
   warning: function 'use_default_implementation_for_nulls' should be marked 
[[nodiscard]] [modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] bool use_default_implementation_for_nulls() const override 
{ return false; }
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -351,10 +508,83 @@
         ColumnPtr str_col;
         bool str_const;
         std::tie(str_col, str_const) = 
unpack_if_const(block.get_by_position(arguments[0]).column);
-        if (auto* nullable = check_and_get_column<const 
ColumnNullable>(*str_col)) {
+
+        const auto& str_offset = assert_cast<const 
ColumnString*>(str_col.get())->get_offsets();
+
+        if (str_const) {
+            std::fill(strlen_data.begin(), strlen_data.end(), str_offset[0] - 
str_offset[-1]);
+        } else {
+            for (int i = 0; i < input_rows_count; ++i) {
+                strlen_data[i] = str_offset[i] - str_offset[i - 1];
+            }
+        }
+
+        // we complete the column2(strlen) with the default value - each row's 
strlen.
+        block.insert({std::move(col_len), std::make_shared<DataTypeInt32>(), 
"strlen"});
+        ColumnNumbers temp_arguments = {arguments[0], arguments[1], 
block.columns() - 1};
+
+        SubstringUtil::substring_execute(block, temp_arguments, result, 
input_rows_count);
+        return Status::OK();
+    }
+};
+
+template <typename Impl>
+class FunctionSubstringOld : public IFunction {
+public:
+    static constexpr auto name = SubstringUtilOld::name;
+    String get_name() const override { return name; }

Review Comment:
   warning: function 'get_name' should be marked [[nodiscard]] 
[modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] String get_name() const override { return name; }
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -351,10 +508,83 @@
         ColumnPtr str_col;
         bool str_const;
         std::tie(str_col, str_const) = 
unpack_if_const(block.get_by_position(arguments[0]).column);
-        if (auto* nullable = check_and_get_column<const 
ColumnNullable>(*str_col)) {
+
+        const auto& str_offset = assert_cast<const 
ColumnString*>(str_col.get())->get_offsets();
+
+        if (str_const) {
+            std::fill(strlen_data.begin(), strlen_data.end(), str_offset[0] - 
str_offset[-1]);
+        } else {
+            for (int i = 0; i < input_rows_count; ++i) {
+                strlen_data[i] = str_offset[i] - str_offset[i - 1];
+            }
+        }
+
+        // we complete the column2(strlen) with the default value - each row's 
strlen.
+        block.insert({std::move(col_len), std::make_shared<DataTypeInt32>(), 
"strlen"});
+        ColumnNumbers temp_arguments = {arguments[0], arguments[1], 
block.columns() - 1};
+
+        SubstringUtil::substring_execute(block, temp_arguments, result, 
input_rows_count);
+        return Status::OK();
+    }
+};
+
+template <typename Impl>
+class FunctionSubstringOld : public IFunction {
+public:
+    static constexpr auto name = SubstringUtilOld::name;
+    String get_name() const override { return name; }
+    static FunctionPtr create() { return 
std::make_shared<FunctionSubstringOld<Impl>>(); }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return make_nullable(std::make_shared<DataTypeString>());
+    }
+    DataTypes get_variadic_argument_types_impl() const override {

Review Comment:
   warning: function 'get_variadic_argument_types_impl' should be marked 
[[nodiscard]] [modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] DataTypes get_variadic_argument_types_impl() const 
override {
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -567,6 +797,34 @@
     static FunctionPtr create() { return std::make_shared<FunctionLeft>(); }
     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 {

Review Comment:
   warning: function 'get_return_type_impl' should be marked [[nodiscard]] 
[modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] DataTypePtr get_return_type_impl(const DataTypes& 
arguments) const override {
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -351,10 +508,83 @@
         ColumnPtr str_col;
         bool str_const;
         std::tie(str_col, str_const) = 
unpack_if_const(block.get_by_position(arguments[0]).column);
-        if (auto* nullable = check_and_get_column<const 
ColumnNullable>(*str_col)) {
+
+        const auto& str_offset = assert_cast<const 
ColumnString*>(str_col.get())->get_offsets();
+
+        if (str_const) {
+            std::fill(strlen_data.begin(), strlen_data.end(), str_offset[0] - 
str_offset[-1]);
+        } else {
+            for (int i = 0; i < input_rows_count; ++i) {
+                strlen_data[i] = str_offset[i] - str_offset[i - 1];
+            }
+        }
+
+        // we complete the column2(strlen) with the default value - each row's 
strlen.
+        block.insert({std::move(col_len), std::make_shared<DataTypeInt32>(), 
"strlen"});
+        ColumnNumbers temp_arguments = {arguments[0], arguments[1], 
block.columns() - 1};
+
+        SubstringUtil::substring_execute(block, temp_arguments, result, 
input_rows_count);
+        return Status::OK();
+    }
+};
+
+template <typename Impl>
+class FunctionSubstringOld : public IFunction {
+public:
+    static constexpr auto name = SubstringUtilOld::name;
+    String get_name() const override { return name; }
+    static FunctionPtr create() { return 
std::make_shared<FunctionSubstringOld<Impl>>(); }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {

Review Comment:
   warning: function 'get_return_type_impl' should be marked [[nodiscard]] 
[modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] DataTypePtr get_return_type_impl(const DataTypes& 
arguments) const override {
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -594,6 +852,57 @@
     static FunctionPtr create() { return std::make_shared<FunctionRight>(); }
     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 {
+        return std::make_shared<DataTypeString>();
+    }
+
+    bool use_default_implementation_for_nulls() const override { return true; }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) const override 
{
+        auto int_type = std::make_shared<DataTypeInt32>();
+        auto params1 = ColumnInt32::create(input_rows_count);
+        auto params2 = ColumnInt32::create(input_rows_count);
+        size_t num_columns_without_result = block.columns();
+
+        // params1 = max(arg[1], -len(arg))
+        auto& index_data = params1->get_data();
+        auto& strlen_data = params2->get_data();
+
+        auto str_col =
+                
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        const auto& str_offset = assert_cast<const 
ColumnString*>(str_col.get())->get_offsets();
+
+        auto pos_col =
+                
block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
+        const auto& pos_data = assert_cast<const 
ColumnInt32*>(pos_col.get())->get_data();
+
+        for (int i = 0; i < input_rows_count; ++i) {
+            strlen_data[i] = str_offset[i] - str_offset[i - 1];
+        }
+
+        for (int i = 0; i < input_rows_count; ++i) {
+            index_data[i] = std::max(-pos_data[i], -strlen_data[i]);
+        }
+
+        block.insert({std::move(params1), int_type, "index"});
+        block.insert({std::move(params2), int_type, "strlen"});
+
+        ColumnNumbers temp_arguments(3);
+        temp_arguments[0] = arguments[0];
+        temp_arguments[1] = num_columns_without_result;
+        temp_arguments[2] = num_columns_without_result + 1;
+        SubstringUtil::substring_execute(block, temp_arguments, result, 
input_rows_count);
+        return Status::OK();
+    }
+};
+
+class FunctionRightOld : public IFunction {
+public:
+    static constexpr auto name = "right";
+    static FunctionPtr create() { return std::make_shared<FunctionRightOld>(); 
}
+    String get_name() const override { return name; }

Review Comment:
   warning: function 'get_name' should be marked [[nodiscard]] 
[modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] String get_name() const override { return name; }
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -594,6 +852,57 @@
     static FunctionPtr create() { return std::make_shared<FunctionRight>(); }
     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 {
+        return std::make_shared<DataTypeString>();
+    }
+
+    bool use_default_implementation_for_nulls() const override { return true; }

Review Comment:
   warning: function 'use_default_implementation_for_nulls' should be marked 
[[nodiscard]] [modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] bool use_default_implementation_for_nulls() const override 
{ return true; }
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -567,6 +797,34 @@
     static FunctionPtr create() { return std::make_shared<FunctionLeft>(); }
     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 {
+        return std::make_shared<DataTypeString>();
+    }
+
+    bool use_default_implementation_for_nulls() const override { return true; }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) const override 
{
+        auto int_type = std::make_shared<DataTypeInt32>();
+        size_t num_columns_without_result = block.columns();
+        block.insert({int_type->create_column_const(input_rows_count, 
to_field(1)), int_type,
+                      "const 1"});
+        ColumnNumbers temp_arguments(3);
+        temp_arguments[0] = arguments[0];
+        temp_arguments[1] = num_columns_without_result;
+        temp_arguments[2] = arguments[1];
+
+        SubstringUtil::substring_execute(block, temp_arguments, result, 
input_rows_count);
+        return Status::OK();
+    }
+};
+
+class FunctionLeftOld : public IFunction {
+public:
+    static constexpr auto name = "left";
+    static FunctionPtr create() { return std::make_shared<FunctionLeftOld>(); }
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 2; }

Review Comment:
   warning: function 'get_number_of_arguments' should be marked [[nodiscard]] 
[modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] size_t get_number_of_arguments() const override { return 
2; }
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -594,6 +852,57 @@
     static FunctionPtr create() { return std::make_shared<FunctionRight>(); }
     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 {

Review Comment:
   warning: function 'get_return_type_impl' should be marked [[nodiscard]] 
[modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] DataTypePtr get_return_type_impl(const DataTypes& 
arguments) const override {
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -567,6 +797,34 @@
     static FunctionPtr create() { return std::make_shared<FunctionLeft>(); }
     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 {
+        return std::make_shared<DataTypeString>();
+    }
+
+    bool use_default_implementation_for_nulls() const override { return true; }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) const override 
{
+        auto int_type = std::make_shared<DataTypeInt32>();
+        size_t num_columns_without_result = block.columns();
+        block.insert({int_type->create_column_const(input_rows_count, 
to_field(1)), int_type,
+                      "const 1"});
+        ColumnNumbers temp_arguments(3);
+        temp_arguments[0] = arguments[0];
+        temp_arguments[1] = num_columns_without_result;
+        temp_arguments[2] = arguments[1];
+
+        SubstringUtil::substring_execute(block, temp_arguments, result, 
input_rows_count);
+        return Status::OK();
+    }
+};
+
+class FunctionLeftOld : public IFunction {
+public:
+    static constexpr auto name = "left";
+    static FunctionPtr create() { return std::make_shared<FunctionLeftOld>(); }
+    String get_name() const override { return name; }

Review Comment:
   warning: function 'get_name' should be marked [[nodiscard]] 
[modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] String get_name() const override { return name; }
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -594,6 +852,57 @@
     static FunctionPtr create() { return std::make_shared<FunctionRight>(); }
     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 {
+        return std::make_shared<DataTypeString>();
+    }
+
+    bool use_default_implementation_for_nulls() const override { return true; }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) const override 
{
+        auto int_type = std::make_shared<DataTypeInt32>();
+        auto params1 = ColumnInt32::create(input_rows_count);
+        auto params2 = ColumnInt32::create(input_rows_count);
+        size_t num_columns_without_result = block.columns();
+
+        // params1 = max(arg[1], -len(arg))
+        auto& index_data = params1->get_data();
+        auto& strlen_data = params2->get_data();
+
+        auto str_col =
+                
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        const auto& str_offset = assert_cast<const 
ColumnString*>(str_col.get())->get_offsets();
+
+        auto pos_col =
+                
block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
+        const auto& pos_data = assert_cast<const 
ColumnInt32*>(pos_col.get())->get_data();
+
+        for (int i = 0; i < input_rows_count; ++i) {
+            strlen_data[i] = str_offset[i] - str_offset[i - 1];
+        }
+
+        for (int i = 0; i < input_rows_count; ++i) {
+            index_data[i] = std::max(-pos_data[i], -strlen_data[i]);
+        }
+
+        block.insert({std::move(params1), int_type, "index"});
+        block.insert({std::move(params2), int_type, "strlen"});
+
+        ColumnNumbers temp_arguments(3);
+        temp_arguments[0] = arguments[0];
+        temp_arguments[1] = num_columns_without_result;
+        temp_arguments[2] = num_columns_without_result + 1;
+        SubstringUtil::substring_execute(block, temp_arguments, result, 
input_rows_count);
+        return Status::OK();
+    }
+};
+
+class FunctionRightOld : public IFunction {
+public:
+    static constexpr auto name = "right";
+    static FunctionPtr create() { return std::make_shared<FunctionRightOld>(); 
}
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 2; }

Review Comment:
   warning: function 'get_number_of_arguments' should be marked [[nodiscard]] 
[modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] size_t get_number_of_arguments() const override { return 
2; }
   ```
   



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