@@ -415,6 +415,58 @@ def test_time_travel_row_filter_after_drop_and_readd(catalog: Catalog, arrow_tab
415415 assert table .scan (row_filter = "bar IS NULL" ).count () == 3
416416
417417
418+ def test_branch_row_filter_after_drop_and_readd (catalog : Catalog , arrow_table_simple : pa .Table ) -> None :
419+ catalog .create_namespace ("default" )
420+ table = catalog .create_table ("default.branch_column_replacement" , schema = arrow_table_simple .schema )
421+ table .append (arrow_table_simple )
422+ snapshot = table .current_snapshot ()
423+ assert snapshot is not None
424+ table .manage_snapshots ().create_branch (snapshot .snapshot_id , "audit" ).create_tag (snapshot .snapshot_id , "before" ).commit ()
425+
426+ with table .update_schema () as update :
427+ update .delete_column ("bar" )
428+ with table .update_schema () as update :
429+ update .add_column ("bar" , IntegerType ())
430+
431+ expected = {"foo" : ["a" , "b" , "c" ], "baz" : [True , False , True ], "bar" : [None , None , None ]}
432+ for branch in (MAIN_BRANCH , "audit" ):
433+ scan = table .scan ().use_ref (branch )
434+ filtered = scan .with_case_sensitive (False ).filter ("BAR >= 2" ).select ("foo" )
435+ assert filtered .to_arrow ().to_pydict () == {"foo" : []}
436+ assert filtered .to_arrow_batch_reader ().read_all ().to_pydict () == {"foo" : []}
437+ assert filtered .count () == 0
438+ assert scan .projection () == table .schema ()
439+ assert scan .to_arrow ().to_pydict () == expected
440+ assert scan .to_arrow_batch_reader ().read_all ().to_pydict () == expected
441+ assert scan .filter ("bar IS NULL" ).count () == 3
442+
443+ for scan in (table .scan (snapshot_id = snapshot .snapshot_id ), table .scan ().use_ref ("before" )):
444+ assert scan .to_arrow ().to_pydict () == arrow_table_simple .to_pydict ()
445+ assert scan .filter ("bar >= 2" ).select ("foo" ).to_arrow ().to_pydict () == {"foo" : ["b" , "c" ]}
446+
447+
448+ def test_branch_row_filter_after_column_rename (catalog : Catalog , arrow_table_simple : pa .Table ) -> None :
449+ catalog .create_namespace ("default" )
450+ table = catalog .create_table ("default.branch_column_rename" , schema = arrow_table_simple .schema )
451+ table .append (arrow_table_simple )
452+ snapshot = table .current_snapshot ()
453+ assert snapshot is not None
454+ table .manage_snapshots ().create_branch (snapshot .snapshot_id , "audit" ).commit ()
455+ with table .update_schema () as update :
456+ update .rename_column ("bar" , "score" )
457+
458+ for branch in (MAIN_BRANCH , "audit" ):
459+ scan = table .scan ().use_ref (branch )
460+ filtered = scan .with_case_sensitive (False ).filter ("SCORE >= 2" ).select ("foo" )
461+ assert filtered .to_arrow ().to_pydict () == {"foo" : ["b" , "c" ]}
462+ assert filtered .to_arrow_batch_reader ().read_all ().to_pydict () == {"foo" : ["b" , "c" ]}
463+ assert filtered .count () == 2
464+ assert scan .projection () == table .schema ()
465+ assert scan .to_arrow ().to_pydict () == {"foo" : ["a" , "b" , "c" ], "score" : [1 , 2 , 3 ], "baz" : [True , False , True ]}
466+ with pytest .raises (ValueError , match = "Could not find field with name bar" ):
467+ scan .filter ("bar >= 2" ).to_arrow ()
468+
469+
418470def test_time_travel_row_filter_after_partition_column_rename (catalog : Catalog , arrow_table_simple : pa .Table ) -> None :
419471 catalog .create_namespace ("default" )
420472 table = catalog .create_table ("default.renamed_partition_column" , schema = arrow_table_simple .schema )
0 commit comments