Skip to content

Commit 6e9a036

Browse files
committed
refine docs
1 parent 74fdebc commit 6e9a036

File tree

1 file changed

+27
-11
lines changed
  • datafusion/physical-plan/src/coalesce

1 file changed

+27
-11
lines changed

datafusion/physical-plan/src/coalesce/mod.rs

+27-11
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ impl BatchCoalescer {
111111
Arc::clone(&self.schema)
112112
}
113113

114-
/// Given a batch, it updates the buffer of [`BatchCoalescer`]. It returns
115-
/// a variant of [`CoalescerState`] indicating the final state of the buffer.
114+
/// Push next batch, and returns [`CoalescerState`] indicating the current
115+
/// state of the buffer.
116116
pub fn push_batch(&mut self, batch: RecordBatch) -> CoalescerState {
117117
let batch = gc_string_view_batch(&batch);
118118
if self.limit_reached(&batch) {
@@ -129,9 +129,13 @@ impl BatchCoalescer {
129129
self.buffer.is_empty()
130130
}
131131

132-
/// The function checks if the buffer can reach the specified limit after getting `batch`.
133-
/// If it does, it slices the received batch as needed, updates the buffer with it, and
134-
/// finally returns `true`. Otherwise; the function does nothing and returns `false`.
132+
/// Checks if the buffer will reach the specified limit after getting
133+
/// `batch`.
134+
///
135+
/// If fetch would be exceeded, slices the received batch, updates the
136+
/// buffer with it, and returns `true`.
137+
///
138+
/// Otherwise: does nothing and returns `false`.
135139
fn limit_reached(&mut self, batch: &RecordBatch) -> bool {
136140
match self.fetch {
137141
Some(fetch) if self.total_rows + batch.num_rows() >= fetch => {
@@ -149,8 +153,10 @@ impl BatchCoalescer {
149153
}
150154
}
151155

152-
/// Updates the buffer with the given batch. If the target batch size is reached,
153-
/// the function returns `true`. Otherwise, it returns `false`.
156+
/// Updates the buffer with the given batch.
157+
///
158+
/// If the target batch size is reached, returns `true`. Otherwise, returns
159+
/// `false`.
154160
fn target_reached(&mut self, batch: RecordBatch) -> bool {
155161
if batch.num_rows() == 0 {
156162
false
@@ -171,21 +177,31 @@ impl BatchCoalescer {
171177
}
172178
}
173179

174-
/// This enumeration acts as a status indicator for the [`BatchCoalescer`] after a
180+
/// Indicates the state of the [`BatchCoalescer`] buffer after the
175181
/// [`BatchCoalescer::push_batch()`] operation.
182+
///
183+
/// The caller should take diferent actions, depending on the variant returned.
176184
pub enum CoalescerState {
177185
/// Neither the limit nor the target batch size is reached.
186+
///
187+
/// Action: continue pushing batches.
178188
Continue,
179-
/// The sufficient row count to produce a complete query result is reached.
189+
/// The limit has been reached.
190+
///
191+
/// Action: call [`BatchCoalescer::finish_batch()`] to get the final
192+
/// buffered results as a batch and finish the query.
180193
LimitReached,
181194
/// The specified minimum number of rows a batch should have is reached.
195+
///
196+
/// Action: call [`BatchCoalescer::finish_batch()`] to get the current
197+
/// buffered results as a batch and then continue pushing batches.
182198
TargetReached,
183199
}
184200

185201
/// Heuristically compact `StringViewArray`s to reduce memory usage, if needed
186202
///
187-
/// This function decides when to consolidate the StringView into a new buffer
188-
/// to reduce memory usage and improve string locality for better performance.
203+
/// Decides when to consolidate the StringView into a new buffer to reduce
204+
/// memory usage and improve string locality for better performance.
189205
///
190206
/// This differs from `StringViewArray::gc` because:
191207
/// 1. It may not compact the array depending on a heuristic.

0 commit comments

Comments
 (0)