github-actions[bot] commented on code in PR #25327:
URL: https://github.com/apache/doris/pull/25327#discussion_r1355132365
##########
be/src/vec/common/format_ip.h:
##########
@@ -95,4 +95,40 @@ inline void formatIPv4(const unsigned char* src, char*& dst,
uint8_t mask_tail_o
formatIPv4(src, 4, dst, mask_tail_octets, mask_string);
}
+inline bool parseIPv4(const char* begin, const char* end, uint32_t& value) {
+ value = 0;
+ int num_dots = 0;
+ int num_digits = 0;
+ uint32_t octet_value = 0;
+
+ for (const char* p = begin; p != end; ++p) {
+ if (*p == '.') {
+ if (num_digits == 0 || num_digits > 3 || num_dots >= 3) {
+ return false;
+ }
+ value = (value << 8) + octet_value;
+ octet_value = 0;
+ num_digits = 0;
+ ++num_dots;
+ } else if (*p >= '0' && *p <= '9') {
+ octet_value = octet_value * 10 + (*p - '0');
+ if (octet_value > 255) {
+ return false;
+ }
+ ++num_digits;
+ } else {
+ return false;
+ }
+ }
+
+ if (num_digits == 0 || num_digits > 3 || num_dots != 3) {
+ return false;
+ }
+
+ value = (value << 8) + octet_value;
+ return true;
+ }
+
+inline bool parseIPv4(const char* begin, const char* end, uint32_t& value);
Review Comment:
warning: redundant 'parseIPv4' declaration
[readability-redundant-declaration]
```suggestion
```
<details>
<summary>Additional context</summary>
**be/src/vec/common/format_ip.h:97:** previously declared here
```cpp
inline bool parseIPv4(const char* begin, const char* end, uint32_t& value) {
^
```
</details>
##########
be/src/vec/functions/function_ip.h:
##########
@@ -117,4 +117,67 @@ class FunctionIPv4NumToString : public IFunction {
argument.name, get_name());
}
};
+
+template <typename Name>
+class FunctionIPv4StringToNum : public IFunction {
+private:
+ template <typename ResType>
+ Status execute_type(Block& block, const ColumnWithTypeAndName& argument,
size_t result) const {
+ using ColumnType = ColumnString;
+ const ColumnPtr& column = argument.column;
+
+ if (const ColumnType* col = typeid_cast<const
ColumnType*>(column.get())) {
+ const typename ColumnType::Chars& vec_in = col->get_chars();
+ const typename ColumnType::Offsets& offsets_in =
col->get_offsets();
+ auto col_res = ColumnVector<ResType>::create();
+
+ typename ColumnVector<ResType>::Container& vec_res =
col_res->get_data();
+ vec_res.resize(offsets_in.size());
+
+ for (size_t i = 0; i < offsets_in.size(); ++i) {
+ StringRef str_ref = col->get_string(i);
+ const char* begin = str_ref.data;
+ const char* end = begin + str_ref.size;
+
+ uint32_t value = 0;
+ if (parseIPv4(begin, end, value)) {
+ vec_res[i] = value;
+ } else {
+ return Status::RuntimeError("Invalid IPv4 address: {}",
String(begin, end));
+ }
+ }
+
+ block.replace_by_position(result, std::move(col_res));
+ return Status::OK();
+ } else
+ return Status::RuntimeError("Illegal column {} of argument of
function {}",
Review Comment:
warning: statement should be inside braces
[readability-braces-around-statements]
```suggestion
} else {
r
}eturn Status::RuntimeError("Illegal column {} of argument of function {}",
```
##########
be/src/vec/functions/function_ip.h:
##########
@@ -117,4 +117,67 @@ class FunctionIPv4NumToString : public IFunction {
argument.name, get_name());
}
};
+
+template <typename Name>
+class FunctionIPv4StringToNum : public IFunction {
+private:
+ template <typename ResType>
+ Status execute_type(Block& block, const ColumnWithTypeAndName& argument,
size_t result) const {
+ using ColumnType = ColumnString;
+ const ColumnPtr& column = argument.column;
+
+ if (const ColumnType* col = typeid_cast<const
ColumnType*>(column.get())) {
+ const typename ColumnType::Chars& vec_in = col->get_chars();
+ const typename ColumnType::Offsets& offsets_in =
col->get_offsets();
+ auto col_res = ColumnVector<ResType>::create();
+
+ typename ColumnVector<ResType>::Container& vec_res =
col_res->get_data();
+ vec_res.resize(offsets_in.size());
+
+ for (size_t i = 0; i < offsets_in.size(); ++i) {
+ StringRef str_ref = col->get_string(i);
+ const char* begin = str_ref.data;
+ const char* end = begin + str_ref.size;
+
+ uint32_t value = 0;
+ if (parseIPv4(begin, end, value)) {
+ vec_res[i] = value;
+ } else {
+ return Status::RuntimeError("Invalid IPv4 address: {}",
String(begin, end));
+ }
+ }
+
+ block.replace_by_position(result, std::move(col_res));
+ return Status::OK();
+ } else
+ return Status::RuntimeError("Illegal column {} of argument of
function {}",
+ argument.column->get_name(),
get_name());
+ }
+
+public:
+ static constexpr auto name = "ipv4stringtonum";
+ static FunctionPtr create() { return
std::make_shared<FunctionIPv4StringToNum<Name>>(); }
+
+ String get_name() const override { return name; }
Review Comment:
warning: function 'get_name' should be marked [[nodiscard]]
[modernize-use-nodiscard]
```suggestion
[[nodiscard]] String get_name() const override { return name; }
```
##########
be/src/vec/functions/function_ip.h:
##########
@@ -117,4 +117,67 @@ class FunctionIPv4NumToString : public IFunction {
argument.name, get_name());
}
};
+
+template <typename Name>
+class FunctionIPv4StringToNum : public IFunction {
+private:
+ template <typename ResType>
+ Status execute_type(Block& block, const ColumnWithTypeAndName& argument,
size_t result) const {
+ using ColumnType = ColumnString;
+ const ColumnPtr& column = argument.column;
+
+ if (const ColumnType* col = typeid_cast<const
ColumnType*>(column.get())) {
+ const typename ColumnType::Chars& vec_in = col->get_chars();
+ const typename ColumnType::Offsets& offsets_in =
col->get_offsets();
+ auto col_res = ColumnVector<ResType>::create();
+
+ typename ColumnVector<ResType>::Container& vec_res =
col_res->get_data();
+ vec_res.resize(offsets_in.size());
+
+ for (size_t i = 0; i < offsets_in.size(); ++i) {
+ StringRef str_ref = col->get_string(i);
+ const char* begin = str_ref.data;
+ const char* end = begin + str_ref.size;
+
+ uint32_t value = 0;
+ if (parseIPv4(begin, end, value)) {
+ vec_res[i] = value;
+ } else {
+ return Status::RuntimeError("Invalid IPv4 address: {}",
String(begin, end));
+ }
+ }
+
+ block.replace_by_position(result, std::move(col_res));
+ return Status::OK();
+ } else
+ return Status::RuntimeError("Illegal column {} of argument of
function {}",
+ argument.column->get_name(),
get_name());
+ }
+
+public:
+ static constexpr auto name = "ipv4stringtonum";
+ static FunctionPtr create() { return
std::make_shared<FunctionIPv4StringToNum<Name>>(); }
+
+ 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 {
+ return std::make_shared<DataTypeUInt32>();
+ }
+
+ bool use_default_implementation_for_nulls() const override { return true; }
Review Comment:
warning: function 'use_default_implementation_for_nulls' should be marked
[[nodiscard]] [modernize-use-nodiscard]
```suggestion
[[nodiscard]] bool use_default_implementation_for_nulls() const override
{ return true; }
```
##########
be/src/vec/functions/function_ip.h:
##########
@@ -117,4 +117,67 @@ class FunctionIPv4NumToString : public IFunction {
argument.name, get_name());
}
};
+
+template <typename Name>
+class FunctionIPv4StringToNum : public IFunction {
+private:
+ template <typename ResType>
+ Status execute_type(Block& block, const ColumnWithTypeAndName& argument,
size_t result) const {
+ using ColumnType = ColumnString;
+ const ColumnPtr& column = argument.column;
+
+ if (const ColumnType* col = typeid_cast<const
ColumnType*>(column.get())) {
+ const typename ColumnType::Chars& vec_in = col->get_chars();
+ const typename ColumnType::Offsets& offsets_in =
col->get_offsets();
+ auto col_res = ColumnVector<ResType>::create();
+
+ typename ColumnVector<ResType>::Container& vec_res =
col_res->get_data();
+ vec_res.resize(offsets_in.size());
+
+ for (size_t i = 0; i < offsets_in.size(); ++i) {
+ StringRef str_ref = col->get_string(i);
+ const char* begin = str_ref.data;
+ const char* end = begin + str_ref.size;
+
+ uint32_t value = 0;
+ if (parseIPv4(begin, end, value)) {
+ vec_res[i] = value;
+ } else {
+ return Status::RuntimeError("Invalid IPv4 address: {}",
String(begin, end));
+ }
+ }
+
+ block.replace_by_position(result, std::move(col_res));
+ return Status::OK();
+ } else
+ return Status::RuntimeError("Illegal column {} of argument of
function {}",
+ argument.column->get_name(),
get_name());
+ }
+
+public:
+ static constexpr auto name = "ipv4stringtonum";
+ static FunctionPtr create() { return
std::make_shared<FunctionIPv4StringToNum<Name>>(); }
+
+ String get_name() const override { return name; }
+
+ size_t get_number_of_arguments() const override { return 1; }
Review Comment:
warning: function 'get_number_of_arguments' should be marked [[nodiscard]]
[modernize-use-nodiscard]
```suggestion
[[nodiscard]] size_t get_number_of_arguments() const override { return
1; }
```
##########
be/src/vec/functions/function_ip.h:
##########
@@ -117,4 +117,67 @@ class FunctionIPv4NumToString : public IFunction {
argument.name, get_name());
}
};
+
+template <typename Name>
+class FunctionIPv4StringToNum : public IFunction {
+private:
+ template <typename ResType>
+ Status execute_type(Block& block, const ColumnWithTypeAndName& argument,
size_t result) const {
+ using ColumnType = ColumnString;
+ const ColumnPtr& column = argument.column;
+
+ if (const ColumnType* col = typeid_cast<const
ColumnType*>(column.get())) {
+ const typename ColumnType::Chars& vec_in = col->get_chars();
+ const typename ColumnType::Offsets& offsets_in =
col->get_offsets();
+ auto col_res = ColumnVector<ResType>::create();
+
+ typename ColumnVector<ResType>::Container& vec_res =
col_res->get_data();
+ vec_res.resize(offsets_in.size());
+
+ for (size_t i = 0; i < offsets_in.size(); ++i) {
+ StringRef str_ref = col->get_string(i);
+ const char* begin = str_ref.data;
+ const char* end = begin + str_ref.size;
+
+ uint32_t value = 0;
+ if (parseIPv4(begin, end, value)) {
+ vec_res[i] = value;
+ } else {
+ return Status::RuntimeError("Invalid IPv4 address: {}",
String(begin, end));
+ }
+ }
+
+ block.replace_by_position(result, std::move(col_res));
+ return Status::OK();
+ } else
+ return Status::RuntimeError("Illegal column {} of argument of
function {}",
+ argument.column->get_name(),
get_name());
+ }
+
+public:
+ static constexpr auto name = "ipv4stringtonum";
+ static FunctionPtr create() { return
std::make_shared<FunctionIPv4StringToNum<Name>>(); }
+
+ 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: function 'get_return_type_impl' should be marked [[nodiscard]]
[modernize-use-nodiscard]
```suggestion
[[nodiscard]] DataTypePtr get_return_type_impl(const DataTypes&
arguments) const 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: [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]