@@ -55,8 +55,8 @@ mod private {
5555 pub trait Key : Eq + std:: hash:: Hash { }
5656 impl < K > Key for K where K : Eq + std:: hash:: Hash { }
5757
58- pub trait Row : Default { }
59- impl < R > Row for R where R : Default { }
58+ pub trait Row : Eq + Default { }
59+ impl < R > Row for R where R : Eq + Default { }
6060}
6161
6262/// A buffer that accumulates changes and produce compacted changes.
@@ -175,6 +175,17 @@ where
175175 Op :: Delete | Op :: UpdateDelete => self . delete ( key, row) ,
176176 }
177177 }
178+
179+ /// Consume the buffer and produce a list of change records.
180+ ///
181+ /// No-op updates are filtered out.
182+ pub fn into_records ( self ) -> impl Iterator < Item = Record < R > > {
183+ self . buffer . into_values ( ) . filter ( |record| match record {
184+ Record :: Insert { .. } => true ,
185+ Record :: Delete { .. } => true ,
186+ Record :: Update { old_row, new_row } => old_row != new_row,
187+ } )
188+ }
178189}
179190
180191impl < K , R > ChangeBuffer < K , R > {
@@ -206,19 +217,18 @@ impl<K, R> ChangeBuffer<K, R> {
206217 pub fn is_empty ( & self ) -> bool {
207218 self . buffer . is_empty ( )
208219 }
209-
210- /// Consume the buffer and produce a list of change records.
211- pub fn into_records ( self ) -> impl ExactSizeIterator < Item = Record < R > > {
212- self . buffer . into_values ( )
213- }
214220}
215221
216- impl < K , R : Row > ChangeBuffer < K , R > {
222+ impl < K , R > ChangeBuffer < K , R >
223+ where
224+ K : private:: Key ,
225+ R : private:: Row + Row ,
226+ {
217227 /// Consume the buffer and produce a single compacted chunk.
218228 pub fn into_chunk ( self , data_types : Vec < DataType > ) -> Option < StreamChunk > {
219229 let mut builder = StreamChunkBuilder :: unlimited ( data_types, Some ( self . buffer . len ( ) ) ) ;
220230 for record in self . into_records ( ) {
221- let none = builder. append_record_eliminate_noop_update ( record) ;
231+ let none = builder. append_record ( record) ;
222232 debug_assert ! ( none. is_none( ) ) ;
223233 }
224234 builder. take ( )
@@ -229,7 +239,7 @@ impl<K, R: Row> ChangeBuffer<K, R> {
229239 let mut res = Vec :: new ( ) ;
230240 let mut builder = StreamChunkBuilder :: new ( chunk_size, data_types) ;
231241 for record in self . into_records ( ) {
232- if let Some ( chunk) = builder. append_record_eliminate_noop_update ( record) {
242+ if let Some ( chunk) = builder. append_record ( record) {
233243 res. push ( chunk) ;
234244 }
235245 }
0 commit comments