HuaHuaY commented on code in PR #311:
URL: https://github.com/apache/iceberg-cpp/pull/311#discussion_r2525982492


##########
src/iceberg/expression/expression.cc:
##########
@@ -120,6 +120,24 @@ Result<std::unique_ptr<Not>> 
Not::Make(std::shared_ptr<Expression> child) {
   return std::unique_ptr<Not>(new Not(std::move(child)));
 }
 
+Result<std::shared_ptr<Expression>> 
Not::MakeFolded(std::shared_ptr<Expression> child) {
+  if (child->op() == Expression::Operation::kTrue) {
+    return False::Instance();
+  }
+
+  if (child->op() == Expression::Operation::kFalse) {
+    return True::Instance();
+  }
+
+  // not(not(x)) = x
+  if (child->op() == Expression::Operation::kNot) {
+    const auto& not_expr = internal::checked_cast<const 
::iceberg::Not&>(*child);
+    return not_expr.child();
+  }
+
+  return ::iceberg::Not::Make(std::move(child));

Review Comment:
   
   ```suggestion
     return Not::Make(std::move(child));
   ```



##########
src/iceberg/expression/expression.h:
##########
@@ -175,6 +220,44 @@ class ICEBERG_EXPORT Or : public Expression {
   static Result<std::unique_ptr<Or>> Make(std::shared_ptr<Expression> left,
                                           std::shared_ptr<Expression> right);
 
+  /// \brief Creates a folded Or expression from two sub-expressions.
+  ///
+  /// \param left The left operand of the OR expression
+  /// \param right The right operand of the OR expression
+  /// \param args Additional operands of the OR expression
+  /// \return A Result containing a shared pointer to the folded Or 
expression, or an
+  /// error if left or right is nullptr
+  /// \note A folded Or expression is an expression that is equivalent to the 
original
+  /// that is equivalent to the original expression, but with the Or operation 
removed.
+  /// For example, (false or x) = x.

Review Comment:
   
   ```suggestion
     /// \note A folded Or expression is an expression that is equivalent to 
the original
     /// expression, but with the Or operation removed. For example, (false or 
x) = x.
   ```



##########
src/iceberg/expression/expression.h:
##########
@@ -211,6 +294,16 @@ class ICEBERG_EXPORT Not : public Expression {
   /// \return A Result containing a unique pointer to Not, or an error if 
child is nullptr
   static Result<std::unique_ptr<Not>> Make(std::shared_ptr<Expression> child);
 
+  /// \brief Creates a folded Not expression from a child expression.
+  ///
+  /// \param child The expression to negate
+  /// \return A Result containing a shared pointer to the folded Not 
expression, or an
+  /// error if child is nullptr \note A folded Not expression is an expression 
that is
+  /// equivalent to the original expression, but with the Not operation 
removed. For
+  /// example, not(not(x)) = x.

Review Comment:
   
   ```suggestion
     /// error if child is nullptr
     /// \note A folded Not expression is an expression that is equivalent to 
the original
     /// expression, but with the Not operation removed. For example, 
not(not(x)) = x.
   ```



##########
src/iceberg/expression/expression.h:
##########
@@ -137,6 +143,45 @@ class ICEBERG_EXPORT And : public Expression {
   static Result<std::unique_ptr<And>> Make(std::shared_ptr<Expression> left,
                                            std::shared_ptr<Expression> right);
 
+  /// \brief Creates a folded And expression from two sub-expressions.
+  ///
+  /// \param left The left operand of the AND expression
+  /// \param right The right operand of the AND expression
+  /// \param args Additional operands of the AND expression
+  /// \return A Result containing a shared pointer to the folded And 
expression, or an
+  /// error if left or right is nullptr
+  /// \note A folded And expression is an expression that is equivalent to the 
original
+  /// that is equivalent to the original expression, but with the And 
operation removed.
+  /// For example, (true and x) = x.

Review Comment:
   ```suggestion
     /// \note A folded And expression is an expression that is equivalent to 
the original
     /// expression, but with the And operation removed. For example, (true and 
x) = x.
   ```



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