zhjwpku commented on code in PR #754:
URL: https://github.com/apache/iceberg-cpp/pull/754#discussion_r3435543513
##########
src/iceberg/expression/inclusive_metrics_evaluator.cc:
##########
@@ -416,6 +429,34 @@ class InclusiveMetricsVisitor : public BoundVisitor<bool> {
// TODO(xiao.dong) handle extract lower and upper bounds
}
+ /// Returns the column's single value if all rows contain the same value.
Defined as a
+ /// column with no nulls, no NaNs, and lower bound equals upper bound.
Returns
+ /// std::nullopt otherwise.
+ Result<std::optional<Literal>> UniqueValue(const std::shared_ptr<Bound>&
expr) {
+ int32_t id = expr->reference()->field().field_id();
+ if (MayContainNull(id)) {
+ return std::nullopt;
+ }
+
+ ICEBERG_ASSIGN_OR_RAISE(auto lower, LowerBound(expr));
+ ICEBERG_ASSIGN_OR_RAISE(auto upper, UpperBound(expr));
+ if (!lower.has_value() || !upper.has_value() || lower->IsNull() ||
upper->IsNull() ||
+ lower->IsNaN() || upper->IsNaN()) {
+ return std::nullopt;
+ }
+
+ auto nan_it = data_file_.nan_value_counts.find(id);
+ if (nan_it != data_file_.nan_value_counts.cend() && nan_it->second != 0) {
+ return std::nullopt;
+ }
+
+ if (!(lower.value() == upper.value())) {
Review Comment:
nit: can we simplify this?
```suggestion
if (lower.value() != upper.value()) {
```
--
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]