@@ -301,6 +301,68 @@ mod tests {
301301 assert_eq ! ( result. meta. size, 200 ) ;
302302 }
303303
304+ #[ test]
305+ fn test_ordering_cache_invalidation_on_file_modification ( ) {
306+ let cache = DefaultFileStatisticsCache :: default ( ) ;
307+ let path = Path :: from ( "test.parquet" ) ;
308+ let schema = Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int32 , false ) ] ) ;
309+
310+ // Cache with original metadata and ordering
311+ let meta_v1 = ObjectMeta {
312+ location : path. clone ( ) ,
313+ last_modified : DateTime :: parse_from_rfc3339 ( "2022-09-27T22:36:00+02:00" )
314+ . unwrap ( )
315+ . into ( ) ,
316+ size : 100 ,
317+ e_tag : None ,
318+ version : None ,
319+ } ;
320+ let ordering_v1 = ordering ( ) ;
321+ let cached_v1 = CachedFileMetadata :: new (
322+ meta_v1. clone ( ) ,
323+ Arc :: new ( Statistics :: new_unknown ( & schema) ) ,
324+ Some ( ordering_v1) ,
325+ ) ;
326+ cache. put ( & path, cached_v1) ;
327+
328+ // Verify cached ordering is valid
329+ let cached = cache. get ( & path) . unwrap ( ) ;
330+ assert ! ( cached. is_valid_for( & meta_v1) ) ;
331+ assert ! ( cached. ordering. is_some( ) ) ;
332+
333+ // File modified (size changed)
334+ let meta_v2 = ObjectMeta {
335+ location : path. clone ( ) ,
336+ last_modified : DateTime :: parse_from_rfc3339 ( "2022-09-28T10:00:00+02:00" )
337+ . unwrap ( )
338+ . into ( ) ,
339+ size : 200 , // Changed
340+ e_tag : None ,
341+ version : None ,
342+ } ;
343+
344+ // Cache entry exists but should be invalid for new metadata
345+ let cached = cache. get ( & path) . unwrap ( ) ;
346+ assert ! ( !cached. is_valid_for( & meta_v2) ) ;
347+
348+ // Cache new version with different ordering
349+ let ordering_v2 = ordering ( ) ; // New ordering instance
350+ let cached_v2 = CachedFileMetadata :: new (
351+ meta_v2. clone ( ) ,
352+ Arc :: new ( Statistics :: new_unknown ( & schema) ) ,
353+ Some ( ordering_v2) ,
354+ ) ;
355+ cache. put ( & path, cached_v2) ;
356+
357+ // Old metadata should be invalid
358+ let cached = cache. get ( & path) . unwrap ( ) ;
359+ assert ! ( !cached. is_valid_for( & meta_v1) ) ;
360+
361+ // New metadata should be valid
362+ assert ! ( cached. is_valid_for( & meta_v2) ) ;
363+ assert ! ( cached. ordering. is_some( ) ) ;
364+ }
365+
304366 #[ test]
305367 fn test_list_entries ( ) {
306368 let cache = DefaultFileStatisticsCache :: default ( ) ;
0 commit comments