comphead commented on code in PR #7742:
URL: https://github.com/apache/datafusion-comet/pull/7742#discussion_r4762659022


##########
docs/source/contributor-guide/memory_management.md:
##########
@@ -528,8 +528,9 @@ the executor.
 
 - `ParquetWriterExec` writes one file per task and reserves parquet-rs's 
estimate of the file's
   in-progress row group (`ArrowWriter::memory_size`). The estimate counts 
encoded pages, encoder
-  buffers, dictionaries and Bloom filters. The writer keeps parquet-rs's 
default row-group limit of
-  1Mi rows and sets no byte limit, so a wide schema can hold a large row group
+  buffers, dictionaries and Bloom filters. A row group is flushed at 1Mi rows 
or once its
+  estimated encoded size reaches `parquet.block.size` (128 MiB by default). 
The reservation counts
+  more than the encoded size, so with many string columns it can reach several 
times that size
   ([#5304](https://github.com/apache/datafusion-comet/issues/5304)). A file 
that is neither local

Review Comment:
   "Flushed once its estimated encoded size reaches `parquet.block.size`" is 
the rule after a batch is written. With parquet 59.3.2 the first batch of a row 
group is never split (see the `buffered_rows > 0` condition in 
`ArrowWriter::write`), so a row group can exceed the limit by up to one whole 
input batch, and the reservation counts more than the encoded size on top of 
that. For a wide schema this is the case the limit is meant to bound, so the 
text should say the limit is checked per batch. Please also say it applies to 
local files and the Hadoop output stream path only, see the next comment.



##########
native/core/src/execution/operators/parquet_writer.rs:
##########
@@ -922,6 +933,38 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn test_parquet_writer_bounds_row_groups_by_max_row_group_bytes() -> 
Result<()> {
+        let schema = Arc::new(Schema::new(vec![Field::new("id", 
DataType::Int32, true)]));
+        let batch = RecordBatch::try_new(
+            Arc::clone(&schema),
+            vec![Arc::new(Int32Array::from_iter_values(0..100_000))],
+        )?;
+        let memory_source = MemorySourceConfig::try_new(&[vec![batch]], 
Arc::clone(&schema), None)?;

Review Comment:
   By my trace of parquet 59.3.2 this test writes a single row group, so 
`num_row_groups() > 1` fails. I did not run it. `MemorySourceConfig` emits the 
one 100,000-row batch unsplit, and `ArrowWriter::write` in 
`arrow/arrow_writer/mod.rs` only applies the byte limit when 
`in_progress.buffered_rows > 0`. The first batch into an empty row group is 
therefore encoded whole, and the flush check after it closes that one group. 
The upstream tests for the limit feed 10 batches of 10 rows. The parquet 60.2.0 
copy in the cargo registry changed this to write a single row first, so the 
test would pass after an arrow bump but not at the current pin. Please feed 
several batches, for example 10 batches of 10,000 rows, which also matches how 
rows reach the writer from the JVM.



##########
docs/source/user-guide/latest/parquet.md:
##########
@@ -340,8 +340,8 @@ With `spark.comet.write.parquet.enabled=true`:
   after a write: file index refresh, cache refresh, partition refresh and 
statistics update. Later
   queries can return the table's previous contents until `REFRESH TABLE`
   ([#6315](https://github.com/apache/datafusion-comet/issues/6315)).
-- **Spark's Parquet writer properties are ignored.** `parquet.block.size`, 
page size, dictionary,
-  writer version and statistics settings never reach the native writer
+- **Most of Spark's Parquet writer properties are ignored.** Page size, 
dictionary, writer
+  version and statistics settings never reach the native writer
   ([#5304](https://github.com/apache/datafusion-comet/issues/5304)).

Review Comment:
   `parquet.block.size` is still ignored for HDFS destinations. 
`ParquetWriter::Remote` in `parquet_writer.rs` calls `arrow_writer.flush()` 
after every batch, so each batch becomes its own row group whatever 
`max_row_group_bytes` is. That path is taken whenever `is_hdfs_scheme` matches 
in `create_arrow_writer`. The PR title and this list now say the property is 
honored, so the HDFS exception belongs here, or the Remote arm should stop 
flushing per batch if that is in scope for 
https://github.com/apache/datafusion-comet/issues/5304.



##########
native/core/src/execution/planner/write.rs:
##########
@@ -117,6 +117,13 @@ impl OperatorBuilder for ParquetWriterBuilder {
                 object_store_options,
             )?
             .with_spark_version(writer.spark_version.clone())
+            // `set_max_row_group_bytes` panics on zero, and a panic must not 
escape to the JVM.
+            .with_max_row_group_bytes(
+                writer
+                    .block_size
+                    .and_then(|bytes| usize::try_from(bytes).ok())
+                    .filter(|&bytes| bytes > 0),
+            )

Review Comment:
   The zero and negative guard that keeps `set_max_row_group_bytes(Some(0))` 
from panicking has no test. Both the Rust test and the Scala test only use a 
positive size. The guard also lives only in this builder, so any other caller 
of `ParquetWriterExec::with_max_row_group_bytes` can still pass `Some(0)` and 
panic inside `execute`. Moving the `filter(|&bytes| bytes > 0)` into 
`with_max_row_group_bytes` puts it at the one place that feeds the parquet-rs 
setter, and a unit test with `Some(0)` would then cover it.



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