zhjwpku commented on code in PR #289:
URL: https://github.com/apache/iceberg-cpp/pull/289#discussion_r3254149600
##########
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:
Also, if the number of code points in the literal is greater than
`TruncateTransform.width()`, we can rewrite it as `AlwaysFalse`. I created PR
[1] for the Java implementation to do this.
[1] https://github.com/apache/iceberg/pull/16383
--
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]