You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "Mryange (via GitHub)" <gi...@apache.org> on 2023/04/07 02:47:24 UTC

[GitHub] [doris] Mryange opened a new pull request, #18452: [refactor](planner)Add new parameter to the trim function;

Mryange opened a new pull request, #18452:
URL: https://github.com/apache/doris/pull/18452

   # Proposed changes
   Support new parameter similar to mysql.
   SELECT TRIM('appleaa', 'a'); -> pple
   
   
   ## Checklist(Required)
   
   * [ ] Does it affect the original behavior
   * [ ] Has unit tests been added
   * [ ] Has document been added or modified
   * [ ] Does it need to update dependencies
   * [ ] Is this PR support rollback (If NO, please explain WHY)
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   
   


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] Mryange closed pull request #18452: [refactor](planner)Add new parameter to the trim function;

Posted by "Mryange (via GitHub)" <gi...@apache.org>.
Mryange closed pull request #18452:  [refactor](planner)Add  new parameter to the trim function;
URL: https://github.com/apache/doris/pull/18452


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] HappenLee commented on a diff in pull request #18452: [refactor](planner)Add new parameter to the trim function;

Posted by "HappenLee (via GitHub)" <gi...@apache.org>.
HappenLee commented on code in PR #18452:
URL: https://github.com/apache/doris/pull/18452#discussion_r1160399775


##########
be/src/vec/functions/function_string.cpp:
##########
@@ -342,6 +330,133 @@ struct TrimImpl {
     }
 };
 
+// This is an implementation of two parameters for the Trim function.
+template <bool is_ltrim, bool is_rtrim>
+struct TrimImpl2 {
+    static Status vector(const ColumnString::Chars& str_data,
+                         const ColumnString::Offsets& str_offsets,
+                         const ColumnString::Chars& rhs_data,
+                         const ColumnString::Offsets& rhs_offsets, ColumnString::Chars& res_data,
+                         ColumnString::Offsets& res_offsets) {
+        DCHECK_EQ(str_offsets.size(), rhs_offsets.size());
+        size_t offset_size = str_offsets.size();
+        res_offsets.resize(str_offsets.size());
+        for (size_t i = 0; i < offset_size; ++i) {
+            const char* raw_str = reinterpret_cast<const char*>(&str_data[str_offsets[i - 1]]);
+            ColumnString::Offset size = str_offsets[i] - str_offsets[i - 1];
+            StringRef str(raw_str, size);
+            const char* raw_rhs = reinterpret_cast<const char*>(&rhs_data[rhs_offsets[i - 1]]);
+            ColumnString::Offset rhs_size = rhs_offsets[i] - rhs_offsets[i - 1];
+            StringRef rhs(raw_rhs, rhs_size);
+            if constexpr (is_ltrim) {
+                str = simd::VStringFunctions::ltrim(str, rhs);
+            }
+            if constexpr (is_rtrim) {
+                str = simd::VStringFunctions::rtrim(str, rhs);
+            }
+            StringOP::push_value_string(std::string_view((char*)str.data, str.size), i, res_data,
+                                        res_offsets);
+        }
+        return Status::OK();
+    }
+};
+// Choose a specific name for the trim function.
+template <bool is_ltrim, bool is_rtrim>
+struct TrimNameChoose;
+
+template <>
+struct TrimNameChoose<true, false> {
+    static constexpr auto name = "ltrim";
+};
+
+template <>
+struct TrimNameChoose<false, true> {
+    static constexpr auto name = "rtrim";
+};
+
+template <>
+struct TrimNameChoose<true, true> {
+    static constexpr auto name = "trim";
+};
+
+template <bool is_ltrim, bool is_rtrim, bool has_Second_Parameter>
+class FunctionTrimBase : public IFunction {
+public:
+    static constexpr auto name = TrimNameChoose<is_ltrim, is_rtrim>::name;
+    using Impl1 = TrimImpl<is_ltrim, is_rtrim>;
+    using Impl2 = TrimImpl2<is_ltrim, is_rtrim>;
+    static FunctionPtr create() {
+        return std::make_shared<FunctionTrimBase<is_ltrim, is_rtrim, has_Second_Parameter>>();
+    }
+
+    String get_name() const override { return name; }
+
+    size_t get_number_of_arguments() const override {
+        if constexpr (has_Second_Parameter) {
+            return 2;
+        } else {
+            return 1;
+        }
+    }
+
+    bool get_is_injective(const Block&) override { return false; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
+        return make_nullable(std::make_shared<DataTypeString>());
+    }
+
+    bool use_default_implementation_for_constants() const override { return true; }
+
+    DataTypes get_variadic_argument_types_impl() const override {
+        if constexpr (has_Second_Parameter) {
+            return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>()};
+        } else {
+            return {std::make_shared<DataTypeString>()};
+        }
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,

Review Comment:
   know how to impl function have mult args



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] github-actions[bot] commented on pull request #18452: [refactor](planner)Add new parameter to the trim function;

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #18452:
URL: https://github.com/apache/doris/pull/18452#issuecomment-1499875347

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] github-actions[bot] commented on pull request #18452: [refactor](planner)Add new parameter to the trim function;

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #18452:
URL: https://github.com/apache/doris/pull/18452#issuecomment-1499906088

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org