Kristofferjoha commented on code in PR #27994:
URL: https://github.com/apache/datafusion/pull/27994#discussion_r4803240585


##########
datafusion/physical-plan/src/repartition/mod.rs:
##########
@@ -1327,6 +1354,60 @@ impl BatchPartitioner {
         }
     }
 
+    fn partition_take(
+        batch: &RecordBatch,
+        indices: &mut [Vec<u32>],
+        timer: &metrics::Time,
+        unshared_output: bool,
+    ) -> Result<Vec<Result<(usize, RecordBatch)>>> {
+        if unshared_output {
+            Self::partition_unshared_take(batch, indices, timer)
+        } else {
+            Self::partition_grouped_take(batch, indices, timer)
+        }
+    }
+
+    /// Like [`Self::partition_grouped_take`], but takes each partition
+    /// separately. See [`Self::with_unshared_output`].
+    fn partition_unshared_take(
+        batch: &RecordBatch,
+        indices: &mut [Vec<u32>],
+        timer: &metrics::Time,
+    ) -> Result<Vec<Result<(usize, RecordBatch)>>> {
+        let _timer = timer.timer();
+        let compact = batch
+            .schema()
+            .fields()
+            .iter()
+            .any(|field| may_compact(field.data_type()));
+        let mut batches = vec![];
+        for (partition, p_indices) in indices.iter_mut().enumerate() {
+            if p_indices.is_empty() {
+                continue;
+            }
+            if p_indices.len() == batch.num_rows() {
+                p_indices.clear();
+                batches.push(Ok((partition, batch.clone())));
+                continue;
+            }
+
+            let indices_array =
+                
PrimitiveArray::<UInt32Type>::from_iter_values(p_indices.drain(..));
+            let columns = take_arrays(batch.columns(), &indices_array, None)?;
+            let options =
+                
RecordBatchOptions::new().with_row_count(Some(indices_array.len()));
+            let taken =
+                RecordBatch::try_new_with_options(batch.schema(), columns, 
&options)?;
+            let taken = if compact {
+                gc_view_arrays(&taken)?
+            } else {

Review Comment:
   A partition is never charged more than before, since compaction never makes 
the data bigger. You're right that a string repeated within a partition is 
copied once per row. Deduplicating would need a hash lookup per row, which 
slows down the common case of mostly distinct strings, and it belongs in the 
compaction code that spilling shares. idk if it should be done in this PR.



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