timothyw553 commented on code in PR #1157:
URL: https://github.com/apache/iceberg-cpp/pull/1157#discussion_r4745295551
##########
src/iceberg/expression/aggregate.cc:
##########
@@ -56,17 +58,57 @@ class SingleValueStructLike : public StructLike {
Literal literal_;
};
-Result<Literal> EvaluateBoundTerm(const BoundTerm& term,
- const std::optional<std::vector<uint8_t>>&
bound) {
- auto ptype = GetPrimitiveType(term);
- if (!bound.has_value()) {
- SingleValueStructLike data(Literal::Null(ptype));
- return term.Evaluate(data);
+// A disengaged optional means the file metrics cannot determine the extremum.
+Result<std::optional<Literal>> EvaluateFileExtremum(const BoundAggregate&
aggregate,
+ const DataFile& file) {
+ const auto& term = *aggregate.term();
+ bool preserves_order = term.kind() == Term::Kind::kReference;
+ if (term.kind() == Term::Kind::kTransform) {
+ const auto& transform =
+ internal::checked_cast<const BoundTransform&>(term).transform();
+ if (transform->transform_type() == TransformType::kVoid) {
+ return Literal::Null(GetPrimitiveType(term));
+ }
+ preserves_order = transform->PreservesOrder();
Review Comment:
can `hour` overflow `int32_t` here for large microsecond timestamps? e.g.
`0` and `7730941132800000000` give hour `0` and `-2147483648`, so
`MAX(hour(ts))` returns `-2147483648` instead of `0`. could we disable this
shortcut for `kHour` on `timestamp` / `timestamp_tz` (or guard both bounds) and
add MIN/MAX tests?
```diff
preserves_order = transform->PreservesOrder();
+ const auto source_type = term.reference()->type()->type_id();
+ if (transform->transform_type() == TransformType::kHour &&
+ (source_type == TypeId::kTimestamp ||
+ source_type == TypeId::kTimestampTz)) {
+ preserves_order = false;
+ }
```
--
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]