github-actions[bot] commented on code in PR #24965:
URL: https://github.com/apache/doris/pull/24965#discussion_r1370265356
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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;
Review Comment:
warning: 8 is a magic number; consider replacing it with a named constant
[readability-magic-numbers]
```cpp
count += 8 - count;
^
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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>(
Review Comment:
warning: 8 is a magic number; consider replacing it with a named constant
[readability-magic-numbers]
```cpp
if (count > 8) {
^
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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>(
Review Comment:
warning: 8 is a magic number; consider replacing it with a named constant
[readability-magic-numbers]
```cpp
if (count < 8) {
^
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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);
Review Comment:
warning: 112 is a magic number; consider replacing it with a named constant
[readability-magic-numbers]
```cpp
uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) &
0xFFFF);
^
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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);
Review Comment:
warning: use auto when initializing with a cast to avoid duplicating the
type name [modernize-use-auto]
```suggestion
auto part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) &
0xFFFF);
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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);
Review Comment:
warning: 8 is a magic number; consider replacing it with a named constant
[readability-magic-numbers]
```cpp
for (int i = 0; i < 8; i++) {
^
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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++;
Review Comment:
warning: 16 is a magic number; consider replacing it with a named constant
[readability-magic-numbers]
```cpp
result = (result << 16) | value;
^
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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);
Review Comment:
warning: 16 is a magic number; consider replacing it with a named constant
[readability-magic-numbers]
```cpp
uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) &
0xFFFF);
^
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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>(999999999999999999LL) *
100000000000000000ll * 1000ll +
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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: 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,101 @@ 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);
Review Comment:
warning: 0xFFFF is a magic number; consider replacing it with a named
constant [readability-magic-numbers]
```cpp
uint16_t part = static_cast<uint16_t>((ipv6 >> (112 - i * 16)) &
0xFFFF);
^
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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 << ":";
Review Comment:
warning: 7 is a magic number; consider replacing it with a named constant
[readability-magic-numbers]
```cpp
if (i != 7) {
^
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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: 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,101 @@ 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>(999999999999999999ll) *
100000000000000000ll * 1000ll +
^
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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>(999999999999999999ll) *
100000000000000000LL * 1000ll +
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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,101 @@ 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>(999999999999999999ll) *
100000000000000000ll * 1000LL +
```
##########
be/src/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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,101 @@ 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,101 @@ 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: 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/olap/types.h:
##########
@@ -957,6 +969,101 @@ 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: 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,101 @@ 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,101 @@ 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,101 @@ 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: 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,101 @@ 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>(999999999999999999LL) *
100000000000000000ll * 1000ll +
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]