zclllyybb commented on code in PR #34258:
URL: https://github.com/apache/doris/pull/34258#discussion_r1590318427


##########
be/src/vec/functions/function_string.h:
##########
@@ -356,6 +357,174 @@ class FunctionStrcmp : public IFunction {
     }
 };
 
+class FunctionAutoPartitionName : public IFunction {
+public:
+    static constexpr auto name = "auto_partition_name";
+    static FunctionPtr create() { return 
std::make_shared<FunctionAutoPartitionName>(); }
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 0; }
+    bool is_variadic() const override { return true; }
+
+    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 
{
+        DCHECK_GE(arguments.size(), 2);
+
+        int argument_size = arguments.size();
+        std::vector<const ColumnString::Chars*> chars_list(argument_size);
+
+        for (int i = 0; i < argument_size; ++i) {
+            const auto& [col, is_const] =
+                    
unpack_if_const(block.get_by_position(arguments[i]).column);
+
+            const auto* col_str = assert_cast<const ColumnString*>(col.get());
+            chars_list[i] = &col_str->get_chars();
+        }
+
+        auto res = ColumnString::create();
+        auto& res_data = res->get_chars();
+        auto& res_offset = res->get_offsets();
+        res_offset.resize(input_rows_count);
+
+        auto compare_str = [&](const char* str1, const char* str2, size_t n) {
+            for (int i = 0; i < n; i++) {
+                if (str1[i] != str2[i]) {
+                    return 0;
+                }
+            }
+            return 1;
+        };
+        if (compare_str(chars_list[0]->raw_data(), "list", 4)) {
+            std::string res_p = "p";
+            for (int i = 0; i < input_rows_count; i++) {
+                int curr_size = 0;
+                for (int j = 1; j < argument_size; j++) {
+                    const std::string 
string_to_unicode(chars_list[j]->raw_data(),
+                                                        chars_list[j]->size());
+                    auto unicode_to_string = 
string_to_u16string(string_to_unicode);
+                    res_p += StringToUnicode(unicode_to_string) +
+                             std::to_string(unicode_to_string.size());
+                }
+                int len = res_p.size();
+                res_data.resize(len + curr_size);
+                std::memcpy(&res_data[res_offset[i - 1]], res_p.c_str(), len);
+                res_offset[i] = res_offset[i - 1] + len;
+            }
+
+            block.get_by_position(result).column = std::move(res);
+            return Status::OK();
+        } else if (compare_str(chars_list[0]->raw_data(), "range", 5)) {
+            if (argument_size != 3) {
+                return Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                        "partition type is range, the argument of size must be 
3");
+            }
+            const auto& [col_partition_type, is_const_col_partition_type] =
+                    
unpack_if_const(block.get_by_position(arguments[1]).column);
+
+            const auto* col_str_partition_type_str =
+                    assert_cast<const ColumnString*>(col_partition_type.get());
+
+            std::string to_split_s(chars_list[2]->raw_data(), 
chars_list[2]->size());
+            std::vector<std::string> str_v;
+            if (to_split_s.size() == input_rows_count * 19) {
+                for (int i = 0; i < to_split_s.size(); i += 19) {
+                    auto vec_res = split(to_split_s.substr(i, 10), "-");
+                    for (const auto& s : vec_res) {
+                        str_v.emplace_back(s);
+                    }
+                }
+            } else {
+                for (int i = 0; i < to_split_s.size(); i += 10) {
+                    auto vec_res = split(to_split_s.substr(i, 10), "-");
+                    for (const auto& s : vec_res) {
+                        str_v.emplace_back(s);
+                    }
+                }
+            }
+            res_data.resize(15 * input_rows_count);
+            for (int i = 0; i < input_rows_count; i++) {
+                int curr_len = 1;
+
+                res_data[res_offset[i - 1]] = 'p';
+                if 
(compare_str(col_str_partition_type_str->get_chars().raw_data(), "day", 3)) {
+                    for (int j = i * 3; j < i * 3 + 3; j++) {
+                        std::memcpy(&res_data[res_offset[i - 1]] + curr_len, 
str_v[j].c_str(),
+                                    str_v[j].size());
+                        curr_len += str_v[j].size();
+                    }
+                } else if 
(compare_str(col_str_partition_type_str->get_chars().raw_data(), "month",
+                                       5)) {
+                    for (int j = i * 3; j < i * 3 + 2; j++) {
+                        std::memcpy(&res_data[res_offset[i - 1]] + curr_len, 
str_v[j].c_str(),
+                                    str_v[j].size());
+                        curr_len += str_v[j].size();
+                    }
+                    std::memcpy(&res_data[res_offset[i - 1]] + curr_len, "01", 
2);
+                    curr_len += 2;
+                } else if 
(compare_str(col_str_partition_type_str->get_chars().raw_data(), "year",
+                                       4)) {
+                    std::memcpy(&res_data[res_offset[i - 1]] + curr_len, 
str_v[i * 3].c_str(),
+                                str_v[i * 3].size());
+                    curr_len += str_v[i * 3].size();
+                    std::memcpy(&res_data[res_offset[i - 1]] + curr_len, 
"0101", 4);
+                    curr_len += 4;
+                } else {
+                    return Status::Error<ErrorCode::INTERNAL_ERROR>(

Review Comment:
   use `Status::INVALID_ARGUMENT` instead



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