@@ -80,7 +80,6 @@ use bytes::Bytes;
80
80
use chrono:: Utc ;
81
81
use conflict_checker:: ConflictChecker ;
82
82
use futures:: future:: BoxFuture ;
83
- use itertools:: Itertools ;
84
83
use object_store:: path:: Path ;
85
84
use object_store:: Error as ObjectStoreError ;
86
85
use serde_json:: Value ;
@@ -269,37 +268,22 @@ pub struct CommitData {
269
268
impl CommitData {
270
269
/// Create new data to be committed
271
270
pub fn new (
272
- actions : Vec < Action > ,
271
+ mut actions : Vec < Action > ,
273
272
operation : DeltaOperation ,
274
273
mut app_metadata : HashMap < String , Value > ,
275
274
app_transactions : Vec < Transaction > ,
276
275
) -> Self {
277
- // When in-commit-timestamps are enabled, we need to ensure that the commit info is the first action
278
- // in the commit log. If it is not present, we need to add it.
279
- // https://github.com/delta-io/delta/blob/master/PROTOCOL.md#writer-requirements-for-in-commit-timestamps
280
- let mut commit_info = None :: < Action > ;
281
- let mut actions = actions
282
- . into_iter ( )
283
- . inspect ( |a| {
284
- if matches ! ( a, Action :: CommitInfo ( ..) ) {
285
- commit_info = Some ( a. clone ( ) )
286
- }
287
- } )
288
- . filter ( |a| matches ! ( a, Action :: CommitInfo ( ..) ) )
289
- . collect_vec ( ) ;
290
- if !commit_info. is_some ( ) {
291
- let mut cm = operation. get_commit_info ( ) ;
292
- cm. timestamp = Some ( Utc :: now ( ) . timestamp_millis ( ) ) ;
276
+ if !actions. iter ( ) . any ( |a| matches ! ( a, Action :: CommitInfo ( ..) ) ) {
277
+ let mut commit_info = operation. get_commit_info ( ) ;
278
+ commit_info. timestamp = Some ( Utc :: now ( ) . timestamp_millis ( ) ) ;
293
279
app_metadata. insert (
294
280
"clientVersion" . to_string ( ) ,
295
281
Value :: String ( format ! ( "delta-rs.{}" , crate_version( ) ) ) ,
296
282
) ;
297
- app_metadata. extend ( cm . info ) ;
298
- cm . info = app_metadata. clone ( ) ;
299
- commit_info = Some ( Action :: CommitInfo ( cm ) ) ;
283
+ app_metadata. extend ( commit_info . info ) ;
284
+ commit_info . info = app_metadata. clone ( ) ;
285
+ actions . push ( Action :: CommitInfo ( commit_info ) )
300
286
}
301
- // safety: we assured commit_info is Some just above.
302
- actions. insert ( 0 , commit_info. unwrap ( ) ) ;
303
287
304
288
for txn in & app_transactions {
305
289
actions. push ( Action :: Txn ( txn. clone ( ) ) )
0 commit comments