suxiaogang223 commented on code in PR #40567:
URL: https://github.com/apache/doris/pull/40567#discussion_r1759334123


##########
be/src/vec/functions/function_string.h:
##########
@@ -2642,6 +2632,53 @@ class FunctionUrlDecode : public IFunction {
     }
 };
 
+class FunctionUrlEncode : public IFunction {
+public:
+    static constexpr auto name = "url_encode";
+    static FunctionPtr create() { return 
std::make_shared<FunctionUrlEncode>(); }
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 1; }
+    bool is_variadic() const override { return false; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return std::make_shared<DataTypeString>();
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) const override 
{
+        auto res = ColumnString::create();
+        auto& res_offsets = res->get_offsets();
+        auto& res_chars = res->get_chars();
+        res_offsets.resize(input_rows_count);
+
+        ColumnPtr argument_column =
+                
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        const auto* url_col = 
check_and_get_column<ColumnString>(argument_column.get());
+
+        if (!url_col) {
+            return Status::InternalError("Not supported input argument type");
+        }
+
+        std::string encoded_url;
+
+        for (size_t i = 0; i < input_rows_count; ++i) {
+            auto source = url_col->get_data_at(i);
+            StringRef url_val(const_cast<char*>(source.data), source.size);
+
+            if (!url_encode(url_val.to_string(), &encoded_url)) {

Review Comment:
   We use the Percent-encoding to encode url, the main difference is that 
spaces are encoded with %20 instead of +. See 
https://stackoverflow.com/a/1634293/2751619. But whether it is %20 or +, it can 
be decoded correctly.



-- 
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-unsubscr...@doris.apache.org

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


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

Reply via email to