zhjwpku commented on code in PR #289:
URL: https://github.com/apache/iceberg-cpp/pull/289#discussion_r3254097766


##########
src/iceberg/expression/predicate.cc:
##########
@@ -286,7 +289,52 @@ Result<std::shared_ptr<Expression>> 
UnboundPredicate<B>::BindLiteralOperation(
     }
   }
 
-  // TODO(gangwu): translate truncate(col) == value to startsWith(value)
+  if (BASE::op() == Expression::Operation::kEq &&
+      bound_term->kind() == Term::Kind::kTransform) {
+    // Safe to cast after kind check confirms it's a transform
+    auto* transform_term = dynamic_cast<BoundTransform*>(bound_term.get());
+    if (!transform_term) {
+      return BoundLiteralPredicate::Make(BASE::op(), std::move(bound_term),
+                                         std::move(literal));
+    }
+
+    if (transform_term->transform()->transform_type() == 
TransformType::kTruncate &&
+        literal.type()->type_id() == TypeId::kString &&
+        !literal.IsNull()) {  // Null safety: skip null literals
+
+      // Apply truncate transform to the literal and check if result matches
+      // This verifies the literal is compatible with the truncate operation
+      auto transformed_result = 
transform_term->transform_func()->Transform(literal);

Review Comment:
   I'm wondering whether we can simply count the code points in the literal and 
compare that with `TruncateTransform.width()`. If they match, we can rewrite it 
as a `StartsWith`. We don't need to transform the extended_literal then.



-- 
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