github-actions[bot] commented on code in PR #24965: URL: https://github.com/apache/doris/pull/24965#discussion_r1368895463
########## be/src/vec/data_types/serde/data_type_ipv4_serde.h: ########## @@ -0,0 +1,53 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <glog/logging.h> +#include <stddef.h> Review Comment: warning: inclusion of deprecated C++ header 'stddef.h'; consider using 'cstddef' instead [modernize-deprecated-headers] ```suggestion #include <cstddef> ``` ########## be/src/vec/data_types/serde/data_type_ipv6_serde.h: ########## @@ -0,0 +1,56 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <glog/logging.h> Review Comment: warning: 'glog/logging.h' file not found [clang-diagnostic-error] ```cpp #include <glog/logging.h> ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { + return false; + } + + octets[octet_index++] = val; + } + + if (octet_index != 4) { + return false; + } + + value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; Review Comment: warning: 24 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { + return false; + } + + octets[octet_index++] = val; + } + + if (octet_index != 4) { + return false; + } + + value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; + return true; + } + + static std::string to_string(vectorized::IPv4 value) { + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' Review Comment: warning: 8 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp << ((value >> 8) & 0xFF) << '.' ^ ``` ########## be/src/vec/data_types/serde/data_type_ipv6_serde.cpp: ########## @@ -0,0 +1,51 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "data_type_ipv6_serde.h" +#include <arrow/builder.h> +#include "vec/columns/column_const.h" + +namespace doris { +namespace vectorized { Review Comment: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces] ```suggestion namespace doris::vectorized { ``` be/src/vec/data_types/serde/data_type_ipv6_serde.cpp:49: ```diff - } // namespace vectorized - } // namespace doris + } // namespace doris ``` ########## be/src/vec/data_types/serde/data_type_ipv4_serde.h: ########## @@ -0,0 +1,53 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <glog/logging.h> +#include <stddef.h> +#include <stdint.h> + +#include <ostream> +#include <string> + +#include "common/status.h" +#include "data_type_number_serde.h" +#include "olap/olap_common.h" +#include "util/jsonb_document.h" +#include "util/jsonb_writer.h" +#include "vec/columns/column.h" +#include "vec/columns/column_vector.h" +#include "vec/common/string_ref.h" +#include "vec/core/types.h" +#include "vec/runtime/ipv4_value.h" + +namespace doris { +namespace vectorized { Review Comment: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces] ```suggestion namespace doris::vectorized { ``` be/src/vec/data_types/serde/data_type_ipv4_serde.h:51: ```diff - } // namespace vectorized - } // namespace doris + } // namespace doris ``` ########## be/src/vec/data_types/serde/data_type_ipv4_serde.h: ########## @@ -0,0 +1,53 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <glog/logging.h> Review Comment: warning: 'glog/logging.h' file not found [clang-diagnostic-error] ```cpp #include <glog/logging.h> ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; Review Comment: warning: do not declare C-style arrays, use std::array<> instead [modernize-avoid-c-arrays] ```cpp vectorized::IPv4 octets[4] = {0}; ^ ``` ########## be/src/vec/data_types/serde/data_type_ipv6_serde.cpp: ########## @@ -0,0 +1,51 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "data_type_ipv6_serde.h" +#include <arrow/builder.h> +#include "vec/columns/column_const.h" + +namespace doris { +namespace vectorized { + +template <bool is_binary_format> +Status DataTypeIPv6SerDe::_write_column_to_mysql(const IColumn& column, + MysqlRowBuffer<is_binary_format>& result, + int row_idx, bool col_const) const { + auto& data = assert_cast<const ColumnVector<IPv6>&>(column).get_data(); + auto col_index = index_check_const(row_idx, col_const); + IPv6Value ipv6_val(data[col_index]); + if (UNLIKELY(0 != result.push_ipv6(ipv6_val))) { + return Status::InternalError("pack mysql buffer failed."); + } + return Status::OK(); +} + +Status DataTypeIPv6SerDe::write_column_to_mysql(const IColumn& column, Review Comment: warning: method 'write_column_to_mysql' can be made static [readability-convert-member-functions-to-static] be/src/vec/data_types/serde/data_type_ipv6_serde.cpp:39: ```diff - bool col_const) const { + bool col_const) { ``` be/src/vec/data_types/serde/data_type_ipv6_serde.h:44: ```diff - Status write_column_to_mysql(const IColumn& column, MysqlRowBuffer<true>& row_buffer, - int row_idx, bool col_const) const override; + static Status write_column_to_mysql(const IColumn& column, MysqlRowBuffer<true>& row_buffer, + int row_idx, bool col_const) override; ``` ########## be/src/vec/data_types/serde/data_type_ipv4_serde.h: ########## @@ -0,0 +1,53 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <glog/logging.h> +#include <stddef.h> +#include <stdint.h> Review Comment: warning: inclusion of deprecated C++ header 'stdint.h'; consider using 'cstdint' instead [modernize-deprecated-headers] ```suggestion #include <cstdint> ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { Review Comment: warning: 255 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp if (result != StringParser::PARSE_SUCCESS || val > 255) { ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { Review Comment: warning: 7 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp if (ipv4.size() < 7 || !is_valid_string(ipv4)) { ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { + return false; + } + + octets[octet_index++] = val; + } + + if (octet_index != 4) { + return false; + } + + value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; Review Comment: warning: 16 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> Review Comment: warning: inclusion of deprecated C++ header 'stdint.h'; consider using 'cstdint' instead [modernize-deprecated-headers] ```suggestion #include <cstdint> ``` ########## be/src/vec/data_types/serde/data_type_ipv6_serde.cpp: ########## @@ -0,0 +1,51 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "data_type_ipv6_serde.h" +#include <arrow/builder.h> +#include "vec/columns/column_const.h" + +namespace doris { +namespace vectorized { + +template <bool is_binary_format> +Status DataTypeIPv6SerDe::_write_column_to_mysql(const IColumn& column, + MysqlRowBuffer<is_binary_format>& result, + int row_idx, bool col_const) const { + auto& data = assert_cast<const ColumnVector<IPv6>&>(column).get_data(); + auto col_index = index_check_const(row_idx, col_const); + IPv6Value ipv6_val(data[col_index]); + if (UNLIKELY(0 != result.push_ipv6(ipv6_val))) { + return Status::InternalError("pack mysql buffer failed."); + } + return Status::OK(); +} + +Status DataTypeIPv6SerDe::write_column_to_mysql(const IColumn& column, + MysqlRowBuffer<true>& row_buffer, int row_idx, + bool col_const) const { + return _write_column_to_mysql(column, row_buffer, row_idx, col_const); +} + +Status DataTypeIPv6SerDe::write_column_to_mysql(const IColumn& column, Review Comment: warning: method 'write_column_to_mysql' can be made static [readability-convert-member-functions-to-static] be/src/vec/data_types/serde/data_type_ipv6_serde.cpp:45: ```diff - bool col_const) const { - return _write_column_to_mysql(column, row_buffer, row_idx, col_const); - } + bool col_const) static bool col_const) const { + return _write_column_to_mysql(column, row_buffer, row_idx, col_const); + } ``` ########## be/src/vec/data_types/serde/data_type_ipv6_serde.h: ########## @@ -0,0 +1,56 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <glog/logging.h> +#include <stddef.h> +#include <stdint.h> Review Comment: warning: inclusion of deprecated C++ header 'stdint.h'; consider using 'cstdint' instead [modernize-deprecated-headers] ```suggestion #include <cstdint> ``` ########## be/src/vec/data_types/serde/data_type_ipv6_serde.h: ########## @@ -0,0 +1,56 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <glog/logging.h> +#include <stddef.h> Review Comment: warning: inclusion of deprecated C++ header 'stddef.h'; consider using 'cstddef' instead [modernize-deprecated-headers] ```suggestion #include <cstddef> ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { + return false; + } + + octets[octet_index++] = val; + } + + if (octet_index != 4) { + return false; + } + + value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; Review Comment: warning: 8 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { + return false; + } + + octets[octet_index++] = val; + } + + if (octet_index != 4) { + return false; + } + + value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; + return true; + } + + static std::string to_string(vectorized::IPv4 value) { + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' Review Comment: warning: 0xFF is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp << ((value >> 16) & 0xFF) << '.' ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { + return false; + } + + octets[octet_index++] = val; + } + + if (octet_index != 4) { + return false; + } + + value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; + return true; + } + + static std::string to_string(vectorized::IPv4 value) { + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' Review Comment: warning: 24 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp ss << ((value >> 24) & 0xFF) << '.' ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { + return false; + } + + octets[octet_index++] = val; + } + + if (octet_index != 4) { + return false; + } + + value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; + return true; + } + + static std::string to_string(vectorized::IPv4 value) { + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' Review Comment: warning: 16 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp << ((value >> 16) & 0xFF) << '.' ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { + return false; + } + + octets[octet_index++] = val; + } + + if (octet_index != 4) { + return false; + } + + value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; + return true; + } + + static std::string to_string(vectorized::IPv4 value) { + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' Review Comment: warning: 0xFF is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp ss << ((value >> 24) & 0xFF) << '.' ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { + return false; + } + + octets[octet_index++] = val; + } + + if (octet_index != 4) { + return false; + } + + value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; + return true; + } + + static std::string to_string(vectorized::IPv4 value) { + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' Review Comment: warning: 0xFF is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp << ((value >> 8) & 0xFF) << '.' ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { + return false; + } + + octets[octet_index++] = val; + } + + if (octet_index != 4) { + return false; + } + + value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; + return true; + } + + static std::string to_string(vectorized::IPv4 value) { + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); Review Comment: warning: 0xFF is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp << (value & 0xFF); ^ ``` ########## be/src/vec/runtime/ipv4_value.h: ########## @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <regex> +#include <stdint.h> + +#include <sstream> +#include <string> + +#include "util/string_parser.hpp" + +namespace doris { + +class IPv4Value { +public: + IPv4Value() = default; + + explicit IPv4Value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + explicit IPv4Value(std::string ipv4) { + + } + + [[nodiscard]] const vectorized::IPv4& value() const { + return _value; + } + + vectorized::IPv4& value() { + return _value; + } + + void set_value(vectorized::IPv4 ipv4) { + _value = ipv4; + } + + bool from_string(std::string ipv4) { + return from_string(_value, ipv4); + } + + [[nodiscard]] std::string to_string() const { + return to_string(_value); + } + + static bool from_string(vectorized::IPv4& value, std::string ipv4) { + remove_ipv4_space(ipv4); + + // shortest ipv4 string is `0.0.0.0` whose length is 7 + if (ipv4.size() < 7 || !is_valid_string(ipv4)) { + return false; + } + + vectorized::IPv4 octets[4] = {0}; + std::istringstream iss(ipv4); + std::string octet; + uint8_t octet_index = 0; + + while (getline(iss, octet, '.')) { + if (octet_index >= 4) { + return false; + } + + StringParser::ParseResult result; + vectorized::IPv4 val = StringParser::string_to_unsigned_int<vectorized::IPv4>(octet.c_str(), octet.length(), &result); + if (result != StringParser::PARSE_SUCCESS || val > 255) { + return false; + } + + octets[octet_index++] = val; + } + + if (octet_index != 4) { + return false; + } + + value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3]; + return true; + } + + static std::string to_string(vectorized::IPv4 value) { + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } + + static void remove_ipv4_space(std::string& ipv4) { + if (ipv4.empty()) { + return; + } + + std::string special_chars = "\r\n\t "; + + size_t pos = ipv4.find_first_not_of(special_chars); + if (pos != std::string::npos) { + ipv4.erase(0, pos); + } + + pos = ipv4.find_last_not_of(special_chars); + if (pos != std::string::npos) { + ipv4.erase(pos + 1); + } + } + + static bool is_valid_string(std::string ipv4) { + static std::regex IPV4_STD_REGEX("^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"); + if (ipv4.size() > 15 || !std::regex_match(ipv4, IPV4_STD_REGEX)) { Review Comment: warning: 15 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp if (ipv4.size() > 15 || !std::regex_match(ipv4, IPV4_STD_REGEX)) { ^ ``` -- 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