comphead commented on code in PR #7787:
URL: https://github.com/apache/datafusion-comet/pull/7787#discussion_r4743956504
##########
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:
This changes behavior the docs describe, and no doc is updated.
`docs/source/contributor-guide/jvm_shuffle.md` lists
`spark.comet.shuffle.jvm.batchSize` as "Rows per Arrow batch",
`native_shuffle.md` lists it as "Target rows per batch", and
`docs/source/user-guide/latest/tuning/memory.md` (Batch Size section) only
mentions the row count. Could step 5 of the Write Path in `jvm_shuffle.md` say
that a batch also ends before its rows pass the byte budget, with the two
tables saying the config is the maximum rows per batch? The `.doc(...)` string
of `COMET_SHUFFLE_JVM_BATCH_SIZE` in `CometConf.scala` could say the same. The
user-facing `configs.md` is generated from it.
##########
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:
The table in `sorted_row_partition_ends_batches_at_the_byte_budget` already
covers each case here through the real entry point. `(8192, row_bytes - 1, 10)`
tests that the first row is always taken. `3 * row_bytes` giving 4 blocks tests
that the limit is inclusive. `(4, MAX_BATCH_ROW_BYTES, 3)` and `(2, 3 *
row_bytes, 5)` test the row limit. This unit test can be removed.
--
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]