alamb commented on code in PR #9357:
URL: https://github.com/apache/arrow-rs/pull/9357#discussion_r2790427629


##########
parquet/src/arrow/arrow_writer/mod.rs:
##########
@@ -331,18 +341,58 @@ impl<W: Write + Send> ArrowWriter<W> {
             ),
         };
 
-        // If would exceed max_row_group_size, split batch
-        if in_progress.buffered_rows + batch.num_rows() > 
self.max_row_group_size {
-            let to_write = self.max_row_group_size - in_progress.buffered_rows;
-            let a = batch.slice(0, to_write);
-            let b = batch.slice(to_write, batch.num_rows() - to_write);
-            self.write(&a)?;
-            return self.write(&b);
+        if let Some(max_rows) = self.max_row_group_row_count {
+            if in_progress.buffered_rows + batch.num_rows() > max_rows {
+                let to_write = max_rows - in_progress.buffered_rows;
+                let a = batch.slice(0, to_write);
+                let b = batch.slice(to_write, batch.num_rows() - to_write);
+                self.write(&a)?;
+                return self.write(&b);

Review Comment:
   here is a reproducer (I will file a follow on ticket)
   
   ```rust
       #[test]
       fn test_row_group_limit_rows_only_pathological_stack_overflow_demo() {
           let schema = Arc::new(Schema::new(vec![Field::new(
               "int",
               ArrowDataType::Int32,
               false,
           )]));
           let array = Int32Array::from((0..1_000_000_i32).collect::<Vec<_>>());
           let batch = RecordBatch::try_new(schema.clone(), 
vec![Arc::new(array)]).unwrap();
   
           let props = WriterProperties::builder()
               .set_max_row_group_row_count(Some(1))
               .set_max_row_group_bytes(None)
               .build();
   
           let file = tempfile::tempfile().unwrap();
           let mut writer = ArrowWriter::try_new(file, schema, 
Some(props)).unwrap();
   
           // This currently recurses once per row-group split and can overflow 
the stack.
           writer.write(&batch).unwrap();
       }
   ```



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