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


##########
src/iceberg/expression/expression_visitor.h:
##########
@@ -329,4 +329,52 @@ Result<R> Visit(const std::shared_ptr<Expression>& expr, 
V& visitor) {
   }
 }
 
+/// \brief Traverse an expression tree with a boolean visitor, 
short-circuiting And/Or.
+///
+/// Like Visit, but skips the right child of an And when the left child is 
false and of
+/// an Or when the left child is true, so errors from a skipped child are not 
reported.
+/// Mirrors Java's ExpressionVisitors.visitEvaluator.
+///
+/// \tparam V The visitor type (must derive from ExpressionVisitor<bool>)
+/// \param expr The expression to traverse
+/// \param visitor The visitor to use for traversal
+/// \return The result produced by the visitor for the root expression node
+template <typename V>
+  requires std::derived_from<V, ExpressionVisitor<bool>>
+Result<bool> VisitEvaluator(const std::shared_ptr<Expression>& expr, V& 
visitor) {
+  ICEBERG_DCHECK(expr != nullptr, "Expression cannot be null");
+
+  switch (expr->op()) {

Review Comment:
   Please dispatch bound and unbound predicates before switching on `op()`, as 
both `Visit` and Java's `visitEvaluator` do. That preserves the existing 
`InvalidExpression` result for an inconsistent predicate.



##########
src/iceberg/expression/evaluator.cc:
##########
@@ -153,7 +153,7 @@ Result<std::unique_ptr<Evaluator>> Evaluator::Make(const 
Schema& schema,
 
 Result<bool> Evaluator::Evaluate(const StructLike& row) const {
   EvalVisitor visitor(row);
-  return Visit<bool, EvalVisitor>(bound_expr_, visitor);
+  return VisitEvaluator(bound_expr_, visitor);

Review Comment:
   Since #1166 merged, row evaluation runs compiled `AndNode` and `OrNode` 
instances. Please add short-circuiting to both nodes when rebasing, and update 
`CompoundExpressionsKeepErrorsFromBothSides` to verify that a skipped right 
operand is never read and a required one still propagates its error.



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