warrenzhu25 commented on code in PR #7787:
URL: https://github.com/apache/datafusion-comet/pull/7787#discussion_r4745437718


##########
native/shuffle/src/spark_unsafe/row.rs:
##########
@@ -1245,6 +1245,27 @@ impl<'a> SortedRowEncoder<'a> {
     }
 }
 
+/// The bytes one batch's rows may add up to. Arrow indexes the values of a 
string or binary
+/// column with `i32` offsets, and a row's size bounds the bytes it adds to 
any one column,
+/// including strings nested in arrays, maps and structs. Each Arrow buffer is 
also no larger than
+/// the part of the rows it comes from, so the batch's encoded block stays 
close to its row bytes.
+/// The reader rejects a block past `Integer.MAX_VALUE` bytes 
(`NativeBatchDecoderIterator`), and
+/// data that does not compress, or the `none` codec, keeps a block that 
large, so the budget
+/// leaves half of that as headroom rather than stopping at `i32::MAX`.
+const MAX_BATCH_ROW_BYTES: usize = 1 << 30;
+
+/// Whether a batch of `rows` rows adding up to `bytes` bytes can take a row 
of `row_size` bytes.
+/// It always takes its first row, which is at most `i32::MAX` bytes, as every 
`UnsafeRow` is.
+fn batch_has_room(
+    rows: usize,
+    bytes: usize,
+    row_size: usize,
+    batch_size: usize,
+    max_batch_bytes: usize,
+) -> bool {
+    rows == 0 || (rows < batch_size && bytes + row_size <= max_batch_bytes)
+}

Review Comment:
   Done in 2c24fc5a6: step 5 of the Write Path in `jvm_shuffle.md` now says a 
batch also ends before its rows add up to 1 GiB, both tables call the config 
the maximum rows per batch, the Batch Size section of `memory.md` mentions the 
byte cut, and so does the `.doc(...)` of `COMET_SHUFFLE_JVM_BATCH_SIZE`.



##########
native/shuffle/src/spark_unsafe/row.rs:
##########
@@ -1922,4 +2049,149 @@ mod test {
             assert!(lists.is_null(1) && lists.is_null(2));
         }
     }
+
+    #[test]
+    fn batch_has_room_takes_the_first_row_then_respects_both_limits() {
+        assert!(batch_has_room(0, 0, 100, 1, 10));
+        assert!(batch_has_room(1, 40, 60, 8, 100));
+        assert!(!batch_has_room(1, 40, 61, 8, 100));
+        assert!(!batch_has_room(8, 0, 0, 8, 100));
+    }
+

Review Comment:
   Agreed, removed in 2c24fc5a6. The table test covers each case through the 
real entry point.



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