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


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

Review Comment:
   Thanks, reproduced and fixed in c44cb99c2. When the schema holds a string 
anywhere (including nested in arrays, maps, structs and dictionaries), each row 
now counts three times against the budget, so one column of a batch holds at 
most about 1 GiB even if every byte becomes `U+FFFD`. 
`invalid_utf8_strings_tripled_past_2_gib_do_not_overflow` (`#[ignore]`, it 
needs several GiB) rebuilds your case at full size, 8,192 distinct 96 KiB 
`0xff` strings with an 8-digit ID: it checks that the old rows-only cut 
overflows and that the new one writes every row with the expected `U+FFFD` 
value.
   
   The one case left is a single row whose string decodes past 2 GiB (about 716 
MiB of mostly invalid UTF-8): a batch always takes its first row, and the 
overflow panics inside `append_value` before there is a block to split. Fixing 
it means checking each string append before it happens, across the top-level, 
nested and dictionary builders, so I opened #7803 for it rather than widen this 
PR. If you'd prefer it here, I can do that.



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

Review Comment:
   Reproduced and fixed in c44cb99c2. `encode_batch` now checks the size of 
each encoded block: when a block of several rows passes `i32::MAX` (whether the 
block writer rejected it or not), it truncates the buffer back to where the 
block started, so nothing reaches the checksum or the file, and encodes each 
half of the rows instead, recursing as needed. The buffer gives back the 
capacity afterwards. `blocks_past_i32_max_from_null_structs_are_split` 
(`#[ignore]`) rebuilds your case at full size, 8,192 rows of 10,000 null 
four-`BIGINT` structs (665,845,760 bytes of rows) with compression off: without 
the split the writer fails with `exceeds maximum size`, with it the rows come 
out as two blocks, all 8,192 rows and every null element intact. 
`oversized_blocks_are_split_before_the_checksum_and_the_file` covers the same 
path with a small injected limit and checks that the checksum matches the file. 
I also narrowed the comment: the row size bounds what a row adds to one column, 
not the siz
 e of the encoded block.



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