You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "bkietz (via GitHub)" <gi...@apache.org> on 2023/07/06 12:39:30 UTC

[GitHub] [arrow] bkietz commented on a diff in pull request #36424: GH-36423: [C++][Compute] Support "or" in `Expression::IsSatisfiable`

bkietz commented on code in PR #36424:
URL: https://github.com/apache/arrow/pull/36424#discussion_r1254376586


##########
cpp/src/arrow/compute/expression.cc:
##########
@@ -362,8 +362,20 @@ bool Expression::IsSatisfiable() const {
   }
 
   if (call->function_name == "and_kleene" || call->function_name == "and") {
-    for (const Expression& arg : call->arguments) {
-      if (!arg.IsSatisfiable()) return false;
+    bool has_unsatisfiable =
+        std::any_of(call->arguments.begin(), call->arguments.end(),
+                    [](const Expression& arg) { return !arg.IsSatisfiable(); });
+    if (has_unsatisfiable) {
+      return false;
+    }
+  }
+
+  if (call->function_name == "or_kleene" || call->function_name == "or") {
+    bool all_unsatisfiable =
+        std::all_of(call->arguments.begin(), call->arguments.end(),
+                    [](const Expression& arg) { return !arg.IsSatisfiable(); });
+    if (all_unsatisfiable) {
+      return false;

Review Comment:
   IMO, using the std algorithms in this way is less readable than the for loop, please use that instead
   ```suggestion
       for (const Expression& arg : call->arguments) {
         if (!arg.IsSatisfiable()) return false;
       }
       return true;
     }
   
     if (call->function_name == "or_kleene" || call->function_name == "or") {
       for (const Expression& arg : call->arguments) {
         if (arg.IsSatisfiable()) return true;
       }
       return false;
   ```
   
   Or alternatively rewrite to return the result of the std algorithms directly
   ```suggestion
       return std::all_of(call->arguments.begin(), call->arguments.end(),
                          [](const Expression& arg) { return arg.IsSatisfiable(); });
     }
   
     if (call->function_name == "or_kleene" || call->function_name == "or") {
       return std::any_of(call->arguments.begin(), call->arguments.end(),
                          [](const Expression& arg) { return arg.IsSatisfiable(); });
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org