wgtmac commented on code in PR #1154:
URL: https://github.com/apache/iceberg-cpp/pull/1154#discussion_r4657081115


##########
src/iceberg/expression/strict_metrics_evaluator.cc:
##########
@@ -429,7 +431,46 @@ class StrictMetricsVisitor : public BoundVisitor<bool> {
 
   Result<bool> StartsWith(const std::shared_ptr<Bound>& expr,
                           const Literal& lit) override {
-    return kRowsMightNotMatch;
+    RETURN_IF_NOT_REFERENCE(expr);
+
+    int32_t id = expr->reference()->field().field_id();
+
+    ICEBERG_ASSIGN_OR_RAISE(auto is_nested, IsNestedColumn(id));
+    if (is_nested) {
+      return kRowsMightNotMatch;
+    }
+
+    ICEBERG_ASSIGN_OR_RAISE(auto has_nulls, CanContainNulls(id));
+    if (has_nulls) {
+      return kRowsMightNotMatch;
+    }
+
+    auto lower_it = data_file_.lower_bounds.find(id);
+    auto upper_it = data_file_.upper_bounds.find(id);
+    if (lower_it == data_file_.lower_bounds.cend() ||
+        upper_it == data_file_.upper_bounds.cend()) {
+      return kRowsMightNotMatch;
+    }
+
+    ICEBERG_DCHECK(expr->reference()->type()->type_id() == TypeId::kString &&

Review Comment:
   Why this is a debug check? Should we be strict here?



##########
src/iceberg/test/strict_metrics_evaluator_test.cc:
##########
@@ -881,6 +920,158 @@ TEST_F(StrictMetricsEvaluatorMigratedTest, 
EvaluateOnNestedColumnWithStats) {
   ExpectShouldRead(Expressions::NotNull("struct.nested_col_with_stats"), 
false);
 }
 
+TEST_F(StrictMetricsEvaluatorMigratedTest, 
StartsWithMatchesWhenBothBoundsHavePrefix) {

Review Comment:
   Could we consolidate the `StartsWith` tests around the existing 
`ExpectShouldRead` helper? For example, the `[abc, abd]` fixture can cover the 
prefix checks in one test:
   
   ```cpp
   struct PrefixCase {
     const char* prefix;
     bool expected;
   };
   
   const PrefixCase cases[] = {
       {"ab", true},
       {"abc", false},
       {"abd", false},
       {"zzz", false},
       {"abcdef", false},
       {"", true},
   };
   
   for (const auto& [prefix, expected] : cases) {
     SCOPED_TRACE(prefix);
     ExpectShouldRead(Expressions::StartsWith("required", prefix),
                      expected, string_file_);
   }
   ```
   
   This covers both one-sided matches and the neither-matches case, so we can 
drop the wide-range fixture. For the optional-column tests, could we also reuse 
one fixture with both bounds matching `"ab"` and vary only the target column’s 
null count? A count of `0` should return `true`, while `1` and a missing entry 
should both return `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]

Reply via email to