jonkeane commented on a change in pull request #11613:
URL: https://github.com/apache/arrow/pull/11613#discussion_r746611871



##########
File path: r/R/parquet.R
##########
@@ -196,7 +196,27 @@ write_parquet <- function(x,
       allow_truncated_timestamps = allow_truncated_timestamps
     )
   )
-  writer$WriteTable(x, chunk_size = chunk_size %||% x$num_rows)
+
+  # determine an approximate chunk size
+  if (is.null(chunk_size)) {
+    num_cells <- x$num_rows * x$num_columns
+    target_cells_per_group <- getOption("arrow.parquet_cells_per_group", 2.5e8)
+
+    if (num_cells < target_cells_per_group) {
+      # If the total number of cells is less than the 2.5 million, we want one 
group
+      num_chunks <- 1
+    } else {
+      # no more than 2.5 million cells (rows * cols) per group
+      num_chunks <- num_cells / target_cells_per_group
+    }
+
+    # but there are no more than 200 chunks
+    num_chunks <- min(num_chunks, getOption("arrow.parquet_max_chunks", 200))
+
+    chunk_size <- x$num_rows / num_chunks
+  }
+
+  writer$WriteTable(x, chunk_size = chunk_size)

Review comment:
       Ah good catch, I suspect we might want to do this in a few other places 
so I've created https://issues.apache.org/jira/browse/ARROW-14660




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