github-actions[bot] commented on code in PR #24965: URL: https://github.com/apache/doris/pull/24965#discussion_r1366675497
########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; Review Comment: warning: 1000ll is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; ^ ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; Review Comment: warning: integer literal has suffix 'll', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion static_cast<int128_t>(99999999999999999ll) * 1000ll + 999LL; ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + Review Comment: warning: 999999999999999999ll is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + ^ ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + Review Comment: warning: integer literal has suffix 'll', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000LL + ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll); Review Comment: warning: 999ll is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll); ^ ``` ########## be/src/vec/data_types/data_type_ipv4.cpp: ########## @@ -0,0 +1,95 @@ +// 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 "vec/data_types/data_type_ipv4.h" + + +#include "util/binary_cast.hpp" +#include "util/string_parser.hpp" +#include "vec/columns/column.h" +#include "vec/columns/column_const.h" +#include "vec/columns/column_vector.h" +#include "vec/common/assert_cast.h" +#include "vec/common/string_buffer.hpp" +#include "vec/data_types/data_type.h" +#include "vec/io/io_helper.h" +#include "vec/io/reader_buffer.h" + +namespace doris::vectorized { +bool DataTypeIPv4::equals(const IDataType& rhs) const { + return typeid(rhs) == typeid(*this); +} + +std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) const { + auto result = check_column_const_set_readability(column, row_num); + ColumnPtr ptr = result.first; + row_num = result.second; + IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num); + return convert_ipv4_to_string(value); +} + +void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) const { + std::string value = to_string(column, row_num); + ostr.write(value.data(), value.size()); +} + +Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const { + auto* column_data = static_cast<ColumnIPv4*>(column); + StringParser::ParseResult result; + IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), rb.count(), &result); + column_data->insert_value(val); + return Status::OK(); +} + +std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) { + std::stringstream ss; + ss << ((ipv4 >> 24) & 0xFF) << '.' Review Comment: warning: 24 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp ss << ((ipv4 >> 24) & 0xFF) << '.' ^ ``` ########## be/src/vec/data_types/data_type_ipv4.cpp: ########## @@ -0,0 +1,95 @@ +// 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 "vec/data_types/data_type_ipv4.h" + + +#include "util/binary_cast.hpp" +#include "util/string_parser.hpp" +#include "vec/columns/column.h" +#include "vec/columns/column_const.h" +#include "vec/columns/column_vector.h" +#include "vec/common/assert_cast.h" +#include "vec/common/string_buffer.hpp" +#include "vec/data_types/data_type.h" +#include "vec/io/io_helper.h" +#include "vec/io/reader_buffer.h" + +namespace doris::vectorized { +bool DataTypeIPv4::equals(const IDataType& rhs) const { + return typeid(rhs) == typeid(*this); +} + +std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) const { + auto result = check_column_const_set_readability(column, row_num); + ColumnPtr ptr = result.first; + row_num = result.second; + IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num); + return convert_ipv4_to_string(value); +} + +void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) const { + std::string value = to_string(column, row_num); + ostr.write(value.data(), value.size()); +} + +Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const { + auto* column_data = static_cast<ColumnIPv4*>(column); + StringParser::ParseResult result; + IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), rb.count(), &result); + column_data->insert_value(val); + return Status::OK(); +} + +std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) { + std::stringstream ss; + ss << ((ipv4 >> 24) & 0xFF) << '.' + << ((ipv4 >> 16) & 0xFF) << '.' Review Comment: warning: 16 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp << ((ipv4 >> 16) & 0xFF) << '.' ^ ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + Review Comment: warning: 1000ll is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + ^ ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; Review Comment: warning: 999ll is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; ^ ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + Review Comment: warning: 100000000000000000ll is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + ^ ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll); Review Comment: warning: 1000ll is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll); ^ ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; Review Comment: warning: integer literal has suffix 'll', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion static_cast<int128_t>(99999999999999999ll) * 1000LL + 999ll; ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + Review Comment: warning: integer literal has suffix 'll', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000LL * 1000ll + ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + Review Comment: warning: integer literal has suffix 'll', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion -(static_cast<int128_t>(999999999999999999LL) * 100000000000000000ll * 1000ll + ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll); Review Comment: warning: integer literal has suffix 'll', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion static_cast<int128_t>(99999999999999999ll) * 1000ll + 999LL); ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll); Review Comment: warning: integer literal has suffix 'll', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion static_cast<int128_t>(99999999999999999ll) * 1000LL + 999ll); ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll); Review Comment: warning: 99999999999999999ll is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll); ^ ``` ########## be/src/vec/common/uint128.h: ########## @@ -103,6 +103,12 @@ struct UInt128 { high = 0; return *this; } + + operator uint128_t() const { + uint128_t value = static_cast<uint128_t>(high) << 64; Review Comment: warning: 64 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp uint128_t value = static_cast<uint128_t>(high) << 64; ^ ``` ########## be/src/olap/types.h: ########## @@ -957,6 +969,103 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT> } }; +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + StringParser::ParseResult result = StringParser::PARSE_SUCCESS; + uint32_t value = StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(), scan_key.size(), &result); + + if (result == StringParser::PARSE_FAILURE) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet PARSE_FAILURE"); + } + *reinterpret_cast<uint32_t*>(buf) = value; + return Status::OK(); + } + + static std::string to_string(const void* src) { + uint32_t value = *reinterpret_cast<const uint32_t*>(src); + std::stringstream ss; + ss << ((value >> 24) & 0xFF) << '.' + << ((value >> 16) & 0xFF) << '.' + << ((value >> 8) & 0xFF) << '.' + << (value & 0xFF); + return ss.str(); + } +}; + + +template <> +struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> + : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV6> { + static Status from_string(void* buf, const std::string& scan_key, const int precision, + const int scale) { + std::istringstream iss(scan_key); + std::string token; + uint128_t result = 0; + int count = 0; + + while (std::getline(iss, token, ':')) { + if (token.empty()) { + count += 8 - count; + break; + } + + if (count > 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + uint16_t value = 0; + std::istringstream ss(token); + if (!(ss >> std::hex >> value)) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + result = (result << 16) | value; + count++; + } + + if (count < 8) { + return Status::Error<ErrorCode::INVALID_ARGUMENT>( + "FieldTypeTraits<OLAP_FIELD_TYPE_IPV6>::from_string meet PARSE_FAILURE"); + } + + *reinterpret_cast<uint128_t*>(buf) = result; + return Status::OK(); + } + + static std::string to_string(const void* src) { + std::stringstream result; + uint128_t ipv6 = *reinterpret_cast<const uint128_t*>(src); + + for (int i = 0; i < 8; i++) { + uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) & 0xFFFF); + result << std::to_string(part); + if (i != 7) { + result << ":"; + } + } + + return result.str(); + } + + static void set_to_max(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll; + } + + static void set_to_min(void* buf) { + *reinterpret_cast<PackedInt128*>(buf) = + -(static_cast<int128_t>(999999999999999999ll) * 100000000000000000ll * 1000ll + + static_cast<int128_t>(99999999999999999ll) * 1000ll + 999ll); Review Comment: warning: integer literal has suffix 'll', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion static_cast<int128_t>(99999999999999999LL) * 1000ll + 999ll); ``` ########## be/src/vec/data_types/data_type_ipv4.cpp: ########## @@ -0,0 +1,95 @@ +// 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 "vec/data_types/data_type_ipv4.h" + + +#include "util/binary_cast.hpp" +#include "util/string_parser.hpp" +#include "vec/columns/column.h" +#include "vec/columns/column_const.h" +#include "vec/columns/column_vector.h" +#include "vec/common/assert_cast.h" +#include "vec/common/string_buffer.hpp" +#include "vec/data_types/data_type.h" +#include "vec/io/io_helper.h" +#include "vec/io/reader_buffer.h" + +namespace doris::vectorized { +bool DataTypeIPv4::equals(const IDataType& rhs) const { + return typeid(rhs) == typeid(*this); +} + +std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) const { + auto result = check_column_const_set_readability(column, row_num); + ColumnPtr ptr = result.first; + row_num = result.second; + IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num); + return convert_ipv4_to_string(value); +} + +void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) const { Review Comment: warning: method 'to_string' can be made static [readability-convert-member-functions-to-static] ```suggestion void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) { ``` be/src/vec/data_types/data_type_ipv4.h:56: ```diff - void to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) const override; + static void to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) override; ``` ########## be/src/vec/data_types/data_type_ipv4.cpp: ########## @@ -0,0 +1,95 @@ +// 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 "vec/data_types/data_type_ipv4.h" + + +#include "util/binary_cast.hpp" +#include "util/string_parser.hpp" +#include "vec/columns/column.h" +#include "vec/columns/column_const.h" +#include "vec/columns/column_vector.h" +#include "vec/common/assert_cast.h" +#include "vec/common/string_buffer.hpp" +#include "vec/data_types/data_type.h" +#include "vec/io/io_helper.h" +#include "vec/io/reader_buffer.h" + +namespace doris::vectorized { +bool DataTypeIPv4::equals(const IDataType& rhs) const { + return typeid(rhs) == typeid(*this); +} + +std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) const { + auto result = check_column_const_set_readability(column, row_num); + ColumnPtr ptr = result.first; + row_num = result.second; + IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num); + return convert_ipv4_to_string(value); +} + +void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) const { + std::string value = to_string(column, row_num); + ostr.write(value.data(), value.size()); +} + +Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const { + auto* column_data = static_cast<ColumnIPv4*>(column); + StringParser::ParseResult result; + IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), rb.count(), &result); + column_data->insert_value(val); + return Status::OK(); +} + +std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) { + std::stringstream ss; + ss << ((ipv4 >> 24) & 0xFF) << '.' Review Comment: warning: 0xFF is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp ss << ((ipv4 >> 24) & 0xFF) << '.' ^ ``` ########## be/src/vec/data_types/data_type_ipv4.cpp: ########## @@ -0,0 +1,95 @@ +// 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 "vec/data_types/data_type_ipv4.h" + + +#include "util/binary_cast.hpp" +#include "util/string_parser.hpp" +#include "vec/columns/column.h" +#include "vec/columns/column_const.h" +#include "vec/columns/column_vector.h" +#include "vec/common/assert_cast.h" +#include "vec/common/string_buffer.hpp" +#include "vec/data_types/data_type.h" +#include "vec/io/io_helper.h" +#include "vec/io/reader_buffer.h" + +namespace doris::vectorized { +bool DataTypeIPv4::equals(const IDataType& rhs) const { + return typeid(rhs) == typeid(*this); +} + +std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) const { + auto result = check_column_const_set_readability(column, row_num); + ColumnPtr ptr = result.first; + row_num = result.second; + IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num); + return convert_ipv4_to_string(value); +} + +void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) const { + std::string value = to_string(column, row_num); + ostr.write(value.data(), value.size()); +} + +Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const { + auto* column_data = static_cast<ColumnIPv4*>(column); + StringParser::ParseResult result; + IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), rb.count(), &result); + column_data->insert_value(val); + return Status::OK(); +} + +std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) { + std::stringstream ss; + ss << ((ipv4 >> 24) & 0xFF) << '.' + << ((ipv4 >> 16) & 0xFF) << '.' + << ((ipv4 >> 8) & 0xFF) << '.' Review Comment: warning: 8 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp << ((ipv4 >> 8) & 0xFF) << '.' ^ ``` ########## be/src/vec/data_types/data_type_ipv4.cpp: ########## @@ -0,0 +1,95 @@ +// 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 "vec/data_types/data_type_ipv4.h" + + +#include "util/binary_cast.hpp" +#include "util/string_parser.hpp" +#include "vec/columns/column.h" +#include "vec/columns/column_const.h" +#include "vec/columns/column_vector.h" +#include "vec/common/assert_cast.h" +#include "vec/common/string_buffer.hpp" +#include "vec/data_types/data_type.h" +#include "vec/io/io_helper.h" +#include "vec/io/reader_buffer.h" + +namespace doris::vectorized { +bool DataTypeIPv4::equals(const IDataType& rhs) const { + return typeid(rhs) == typeid(*this); +} + +std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) const { + auto result = check_column_const_set_readability(column, row_num); + ColumnPtr ptr = result.first; + row_num = result.second; + IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num); + return convert_ipv4_to_string(value); +} + +void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) const { + std::string value = to_string(column, row_num); + ostr.write(value.data(), value.size()); +} + +Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const { Review Comment: warning: method 'from_string' can be made static [readability-convert-member-functions-to-static] ```suggestion Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) { ``` be/src/vec/data_types/data_type_ipv4.h:57: ```diff - Status from_string(ReadBuffer& rb, IColumn* column) const override; + static Status from_string(ReadBuffer& rb, IColumn* column) override; ``` ########## be/src/vec/data_types/data_type_ipv4.cpp: ########## @@ -0,0 +1,95 @@ +// 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 "vec/data_types/data_type_ipv4.h" + + +#include "util/binary_cast.hpp" +#include "util/string_parser.hpp" +#include "vec/columns/column.h" +#include "vec/columns/column_const.h" +#include "vec/columns/column_vector.h" +#include "vec/common/assert_cast.h" +#include "vec/common/string_buffer.hpp" +#include "vec/data_types/data_type.h" +#include "vec/io/io_helper.h" +#include "vec/io/reader_buffer.h" + +namespace doris::vectorized { +bool DataTypeIPv4::equals(const IDataType& rhs) const { + return typeid(rhs) == typeid(*this); +} + +std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) const { + auto result = check_column_const_set_readability(column, row_num); + ColumnPtr ptr = result.first; + row_num = result.second; + IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num); + return convert_ipv4_to_string(value); +} + +void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) const { + std::string value = to_string(column, row_num); + ostr.write(value.data(), value.size()); +} + +Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const { + auto* column_data = static_cast<ColumnIPv4*>(column); + StringParser::ParseResult result; + IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), rb.count(), &result); + column_data->insert_value(val); + return Status::OK(); +} + +std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) { + std::stringstream ss; + ss << ((ipv4 >> 24) & 0xFF) << '.' + << ((ipv4 >> 16) & 0xFF) << '.' + << ((ipv4 >> 8) & 0xFF) << '.' Review Comment: warning: 0xFF is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp << ((ipv4 >> 8) & 0xFF) << '.' ^ ``` ########## be/src/vec/data_types/data_type_ipv4.cpp: ########## @@ -0,0 +1,95 @@ +// 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 "vec/data_types/data_type_ipv4.h" + + +#include "util/binary_cast.hpp" +#include "util/string_parser.hpp" +#include "vec/columns/column.h" +#include "vec/columns/column_const.h" +#include "vec/columns/column_vector.h" +#include "vec/common/assert_cast.h" +#include "vec/common/string_buffer.hpp" +#include "vec/data_types/data_type.h" +#include "vec/io/io_helper.h" +#include "vec/io/reader_buffer.h" + +namespace doris::vectorized { +bool DataTypeIPv4::equals(const IDataType& rhs) const { + return typeid(rhs) == typeid(*this); +} + +std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) const { + auto result = check_column_const_set_readability(column, row_num); + ColumnPtr ptr = result.first; + row_num = result.second; + IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num); + return convert_ipv4_to_string(value); +} + +void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) const { + std::string value = to_string(column, row_num); + ostr.write(value.data(), value.size()); +} + +Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const { + auto* column_data = static_cast<ColumnIPv4*>(column); + StringParser::ParseResult result; + IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), rb.count(), &result); + column_data->insert_value(val); + return Status::OK(); +} + +std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) { + std::stringstream ss; + ss << ((ipv4 >> 24) & 0xFF) << '.' + << ((ipv4 >> 16) & 0xFF) << '.' Review Comment: warning: 0xFF is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp << ((ipv4 >> 16) & 0xFF) << '.' ^ ``` -- 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