felipecrv commented on code in PR #15083:
URL: https://github.com/apache/arrow/pull/15083#discussion_r1070144979


##########
cpp/src/arrow/compute/exec.cc:
##########
@@ -164,13 +171,43 @@ Result<ExecBatch> ExecBatch::Make(std::vector<Datum> 
values) {
     }
 
     if (length != value.length()) {
-      return Status::Invalid(
-          "Arrays used to construct an ExecBatch must have equal length");
+      // all the arrays should have the same length
+      return kInvalidValues;
     }
   }
 
-  if (length == -1) {
-    length = 1;
+  return length == -1 ? 1 : length;
+}
+
+}  // namespace
+
+std::optional<int64_t> ExecBatch::InferLength(const std::vector<Datum>& 
values) {
+  const int64_t length = DoInferLength(values);
+  if (length < 0) {
+    return std::nullopt;
+  }
+  return {length};
+}
+
+Result<ExecBatch> ExecBatch::Make(std::vector<Datum> values, int64_t length) {
+  // Infer the length again and/or validate the given length.
+  const int64_t inferred_length = DoInferLength(values);
+  switch (inferred_length) {
+    case kEmptyInput:
+      if (length < 0) {
+        return Status::Invalid(
+            "Cannot infer ExecBatch length without at least one value");
+      }
+      break;
+
+    case kInvalidValues:
+      return Status::Invalid(
+          "Arrays used to construct an ExecBatch must have equal length");
+
+    default:
+      DCHECK(length < 0 || length == inferred_length);

Review Comment:
   Makes sense as the caller could proceed using the mistaken `length` for 
other things. I will add a commit changing this.



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

Reply via email to