zhjwpku commented on code in PR #1157:
URL: https://github.com/apache/iceberg-cpp/pull/1157#discussion_r4679489542
##########
src/iceberg/util/conversions.cc:
##########
@@ -158,20 +160,24 @@ Result<Literal::Value> Conversions::FromBytes(const
PrimitiveType& type,
return Literal::Value{value};
}
case TypeId::kLong:
- case TypeId::kTime:
case TypeId::kTimestamp:
- case TypeId::kTimestampTz:
case TypeId::kTimestampNs:
- case TypeId::kTimestampTzNs: {
- int64_t value;
- if (data.size() < 8) {
- // Type was promoted from int to long
- ICEBERG_ASSIGN_OR_RAISE(auto int_value,
ReadLittleEndian<int32_t>(data));
- value = static_cast<int64_t>(int_value);
- } else {
- ICEBERG_ASSIGN_OR_RAISE(auto long_value,
ReadLittleEndian<int64_t>(data));
- value = long_value;
+ if (data.size() == sizeof(int32_t)) {
+ ICEBERG_ASSIGN_OR_RAISE(auto value, ReadLittleEndian<int32_t>(data));
+ if (type_id == TypeId::kLong) {
+ return Literal::Value{static_cast<int64_t>(value)};
+ }
+ // Before date promotion, bounds were stored as days since the epoch.
+ const auto units_per_day = type_id == TypeId::kTimestamp ?
internal::kMicrosPerDay
+ :
internal::kNanosPerDay;
+ ICEBERG_ASSIGN_OR_RAISE(auto timestamp, MultiplyExact(value,
units_per_day));
Review Comment:
Bounds are now decoded through an internal `DeserializeBound()` that returns
`std::nullopt` when a four-byte date bound does not fit the promoted type.
Callers treat it as a missing bound, so planning continues and the other
bound
stays usable. `Literal::Deserialize()` still returns an error on overflow,
and
malformed bounds are still propagated as errors.
--
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]