|
25 | 25 | #include <algorithm> |
26 | 26 | #include <bit> |
27 | 27 | #include <boost/locale.hpp> |
| 28 | +#include <cctype> |
28 | 29 | #include <climits> |
29 | 30 | #include <cstddef> |
30 | 31 | #include <cstdint> |
@@ -141,9 +142,11 @@ class FunctionAutoPartitionName : public IFunction { |
141 | 142 | auto& res_offset = res->get_offsets(); |
142 | 143 | res_offset.resize(input_rows_count); |
143 | 144 |
|
144 | | - const char* partition_type = chars_list[0]->raw_data(); |
| 145 | + std::string partition_type(chars_list[0]->raw_data(), (*offsets_list[0])[0]); |
| 146 | + std::transform(partition_type.begin(), partition_type.end(), partition_type.begin(), |
| 147 | + [](unsigned char c) { return static_cast<char>(std::tolower(c)); }); |
145 | 148 | // partition type is list|range |
146 | | - if (std::strncmp(partition_type, "list", 4) == 0) { |
| 149 | + if (partition_type == "list") { |
147 | 150 | return _auto_partition_type_of_list(chars_list, offsets_list, is_const_args, null_list, |
148 | 151 | res_data, res_offset, input_rows_count, |
149 | 152 | argument_size, block, result, res); |
@@ -256,7 +259,9 @@ class FunctionAutoPartitionName : public IFunction { |
256 | 259 | auto& res_offset, size_t input_rows_count, |
257 | 260 | size_t argument_size, Block& block, uint32_t result, |
258 | 261 | auto& res) const { |
259 | | - const char* range_type = chars_list[1]->raw_data(); |
| 262 | + std::string range_type(chars_list[1]->raw_data(), (*offsets_list[1])[0]); |
| 263 | + std::transform(range_type.begin(), range_type.end(), range_type.begin(), |
| 264 | + [](unsigned char c) { return static_cast<char>(std::tolower(c)); }); |
260 | 265 |
|
261 | 266 | res_data.resize(15 * input_rows_count); |
262 | 267 | for (int i = 0; i < input_rows_count; i++) { |
@@ -292,21 +297,21 @@ class FunctionAutoPartitionName : public IFunction { |
292 | 297 | // minute => 2022 12 11 30 00 |
293 | 298 | // second => 2022 12 12 12 30 20 |
294 | 299 |
|
295 | | - if (!strncmp(range_type, "year", 4)) { |
| 300 | + if (range_type == "year") { |
296 | 301 | curr_len += _copy_date_str_of_len_to_res_data(res_data, res_offset, date_str, i, 1); |
297 | 302 | memcpy(&res_data[res_offset[i - 1]] + curr_len, "0101", 4); |
298 | 303 | curr_len += 4; |
299 | | - } else if (!strncmp(range_type, "month", 5)) { |
| 304 | + } else if (range_type == "month") { |
300 | 305 | curr_len += _copy_date_str_of_len_to_res_data(res_data, res_offset, date_str, i, 2); |
301 | 306 | memcpy(&res_data[res_offset[i - 1]] + curr_len, "01", 2); |
302 | 307 | curr_len += 2; |
303 | | - } else if (!strncmp(range_type, "day", 3)) { |
| 308 | + } else if (range_type == "day") { |
304 | 309 | curr_len += _copy_date_str_of_len_to_res_data(res_data, res_offset, date_str, i, 3); |
305 | | - } else if (!strncmp(range_type, "hour", 4)) { |
| 310 | + } else if (range_type == "hour") { |
306 | 311 | curr_len += _copy_date_str_of_len_to_res_data(res_data, res_offset, date_str, i, 4); |
307 | | - } else if (!strncmp(range_type, "minute", 6)) { |
| 312 | + } else if (range_type == "minute") { |
308 | 313 | curr_len += _copy_date_str_of_len_to_res_data(res_data, res_offset, date_str, i, 5); |
309 | | - } else if (!strncmp(range_type, "second", 6)) { |
| 314 | + } else if (range_type == "second") { |
310 | 315 | curr_len += _copy_date_str_of_len_to_res_data(res_data, res_offset, date_str, i, 6); |
311 | 316 | } |
312 | 317 |
|
|
0 commit comments