github-actions[bot] commented on code in PR #27342: URL: https://github.com/apache/doris/pull/27342#discussion_r1400103921
########## be/src/vec/common/format_ip.cpp: ########## @@ -75,4 +76,125 @@ /// This will generate static array of pair<const char *, size_t> for [0..255] at compile time extern constexpr std::array<std::pair<const char*, size_t>, 256> one_byte_to_string_lookup_table = str_make_array<256>(); + +/// integer logarithm, return ceil(log(value, base)) (the smallest integer greater or equal than log(value, base) +static constexpr UInt32 intLog(const UInt32 value, const UInt32 base, const bool carry) { + return value >= base ? 1 + intLog(value / base, base, value % base || carry) + : value % base > 1 || carry; +} + +/// Print integer in desired base, faster than sprintf. +/// NOTE This is not the best way. See https://github.com/miloyip/itoa-benchmark +/// But it doesn't matter here. +template <UInt32 base, typename T> +static void print_integer(char*& out, T value) { + if (value == 0) + *out++ = '0'; + else { + constexpr size_t buffer_size = sizeof(T) * intLog(256, base, false); + + char buf[buffer_size]; + auto ptr = buf; + + while (value > 0) { + *ptr = hex_digit_lowercase(value % base); + ++ptr; + value /= base; + } + + /// Copy to out reversed. + while (ptr != buf) { + --ptr; + *out = *ptr; + ++out; + } + } +} + +void formatIPv6(const unsigned char* src, char*& dst, uint8_t zeroed_tail_bytes_count) { Review Comment: warning: function 'formatIPv6' exceeds recommended size/complexity thresholds [readability-function-size] ```cpp void formatIPv6(const unsigned char* src, char*& dst, uint8_t zeroed_tail_bytes_count) { ^ ``` <details> <summary>Additional context</summary> **be/src/vec/common/format_ip.cpp:113:** 84 lines including whitespace and comments (threshold 80) ```cpp void formatIPv6(const unsigned char* src, char*& dst, uint8_t zeroed_tail_bytes_count) { ^ ``` </details> ########## be/src/vec/functions/function_ip.h: ########## @@ -250,4 +252,87 @@ } }; +class FunctionIPv6NumToString : public IFunction { +public: + static constexpr auto name = "ipv6numtostring"; + static FunctionPtr create() { return std::make_shared<FunctionIPv6NumToString>(); } + + String get_name() const override { return name; } + + size_t get_number_of_arguments() const override { return 1; } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + const auto* arg_string = check_and_get_data_type<DataTypeString>(arguments[0].get()); + const auto* arg_ipv6 = check_and_get_data_type<DataTypeIPv6>(arguments[0].get()); + if (!arg_ipv6 && !(arg_string)) + throw Exception(ErrorCode::INVALID_ARGUMENT, + "Illegal type {} of argument of function {}, expected IPv6 or String", + arguments[0]->get_name(), get_name()); + + return make_nullable(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 { Review Comment: warning: method 'execute_impl' can be made static [readability-convert-member-functions-to-static] ```suggestion static Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) override { ``` ########## be/src/vec/common/format_ip.cpp: ########## @@ -75,4 +76,125 @@ consteval std::array<std::pair<const char*, size_t>, N> str_make_array() { /// This will generate static array of pair<const char *, size_t> for [0..255] at compile time extern constexpr std::array<std::pair<const char*, size_t>, 256> one_byte_to_string_lookup_table = str_make_array<256>(); + +/// integer logarithm, return ceil(log(value, base)) (the smallest integer greater or equal than log(value, base) +static constexpr UInt32 intLog(const UInt32 value, const UInt32 base, const bool carry) { + return value >= base ? 1 + intLog(value / base, base, value % base || carry) + : value % base > 1 || carry; +} + +/// Print integer in desired base, faster than sprintf. +/// NOTE This is not the best way. See https://github.com/miloyip/itoa-benchmark +/// But it doesn't matter here. +template <UInt32 base, typename T> +static void print_integer(char*& out, T value) { + if (value == 0) Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion if (value == 0) { ``` be/src/vec/common/format_ip.cpp:92: ```diff - else { + } else { ``` ########## be/src/vec/functions/function_ip.h: ########## @@ -250,4 +252,87 @@ class FunctionIPv4StringToNum : public IFunction { } }; +class FunctionIPv6NumToString : public IFunction { +public: + static constexpr auto name = "ipv6numtostring"; + static FunctionPtr create() { return std::make_shared<FunctionIPv6NumToString>(); } + + String get_name() const override { return name; } + + size_t get_number_of_arguments() const override { return 1; } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { Review Comment: warning: method 'get_return_type_impl' can be made static [readability-convert-member-functions-to-static] ```suggestion static DataTypePtr get_return_type_impl(const DataTypes& arguments) override { ``` -- 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