@@ -111,8 +111,8 @@ impl BatchCoalescer {
111
111
Arc :: clone ( & self . schema )
112
112
}
113
113
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.
116
116
pub fn push_batch ( & mut self , batch : RecordBatch ) -> CoalescerState {
117
117
let batch = gc_string_view_batch ( & batch) ;
118
118
if self . limit_reached ( & batch) {
@@ -129,9 +129,13 @@ impl BatchCoalescer {
129
129
self . buffer . is_empty ( )
130
130
}
131
131
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`.
135
139
fn limit_reached ( & mut self , batch : & RecordBatch ) -> bool {
136
140
match self . fetch {
137
141
Some ( fetch) if self . total_rows + batch. num_rows ( ) >= fetch => {
@@ -149,8 +153,10 @@ impl BatchCoalescer {
149
153
}
150
154
}
151
155
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`.
154
160
fn target_reached ( & mut self , batch : RecordBatch ) -> bool {
155
161
if batch. num_rows ( ) == 0 {
156
162
false
@@ -171,21 +177,31 @@ impl BatchCoalescer {
171
177
}
172
178
}
173
179
174
- /// This enumeration acts as a status indicator for the [`BatchCoalescer`] after a
180
+ /// Indicates the state of the [`BatchCoalescer`] buffer after the
175
181
/// [`BatchCoalescer::push_batch()`] operation.
182
+ ///
183
+ /// The caller should take diferent actions, depending on the variant returned.
176
184
pub enum CoalescerState {
177
185
/// Neither the limit nor the target batch size is reached.
186
+ ///
187
+ /// Action: continue pushing batches.
178
188
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.
180
193
LimitReached ,
181
194
/// 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.
182
198
TargetReached ,
183
199
}
184
200
185
201
/// Heuristically compact `StringViewArray`s to reduce memory usage, if needed
186
202
///
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.
189
205
///
190
206
/// This differs from `StringViewArray::gc` because:
191
207
/// 1. It may not compact the array depending on a heuristic.
0 commit comments