@@ -747,6 +747,48 @@ def cast_dataset(dataset):
747747 needs_setup = True
748748
749749 if not needs_setup :
750+ # Ensure a pair of convenience test tables exist even if catalog is already
751+ # initialized by a prior run. These are used in battery tests.
752+ from pyiceberg .exceptions import NoSuchTableError as _NoSuchTableError
753+ import pyarrow as _pa
754+ from freezegun import freeze_time as _freeze_time
755+
756+ def _ensure_table_empty (identifier ):
757+ try :
758+ catalog .load_table (identifier )
759+ except _NoSuchTableError :
760+ schema = _pa .schema ([_pa .field ("id" , _pa .int64 ()), _pa .field ("name" , _pa .string ())])
761+ catalog .create_table (identifier , schema = schema )
762+
763+ def _ensure_single_snapshot (identifier ):
764+ try :
765+ catalog .load_table (identifier )
766+ except _NoSuchTableError :
767+ schema = _pa .schema ([_pa .field ("id" , _pa .int64 ()), _pa .field ("name" , _pa .string ())])
768+ table = catalog .create_table (identifier , schema = schema )
769+ data = _pa .Table .from_arrays ([_pa .array ([1 , 2 , 3 ]), _pa .array (["a" , "b" , "c" ])], schema = schema )
770+ commit_time = datetime .datetime (2023 , 1 , 1 , 12 , 0 , 0 )
771+ with _freeze_time (commit_time ):
772+ table .append (data )
773+
774+ def _ensure_two_snapshots (identifier ):
775+ try :
776+ catalog .load_table (identifier )
777+ except _NoSuchTableError :
778+ schema = _pa .schema ([_pa .field ("id" , _pa .int64 ()), _pa .field ("name" , _pa .string ())])
779+ table = catalog .create_table (identifier , schema = schema )
780+ data1 = _pa .Table .from_arrays ([_pa .array ([1 , 2 ]), _pa .array (["a" , "b" ])], schema = schema )
781+ commit_time1 = datetime .datetime (2021 , 1 , 1 , 12 , 0 , 0 )
782+ with _freeze_time (commit_time1 ):
783+ table .append (data1 )
784+ data2 = _pa .Table .from_arrays ([_pa .array ([1 , 2 , 3 ]), _pa .array (["a" , "b" , "c" ])], schema = schema )
785+ commit_time2 = datetime .datetime (2022 , 1 , 1 , 12 , 0 , 0 )
786+ with _freeze_time (commit_time2 ):
787+ table .overwrite (data2 )
788+
789+ _ensure_table_empty ("opteryx.empty_battery" )
790+ _ensure_single_snapshot ("opteryx.single_snap_battery" )
791+ _ensure_two_snapshots ("opteryx.two_snap_battery" )
750792 return catalog
751793
752794 with contextlib .suppress (NamespaceAlreadyExistsError ):
@@ -830,4 +872,46 @@ def load_planet_snapshot(cutoff):
830872 del iceberged # Free memory immediately
831873
832874
875+ # Create additional tables that tests rely on (empty and single snapshot)
876+ from pyiceberg .exceptions import NoSuchTableError as _NoSuchTableError
877+ import pyarrow as _pa
878+ from freezegun import freeze_time as _freeze_time
879+
880+ def _ensure_table_empty (identifier ):
881+ try :
882+ catalog .load_table (identifier )
883+ except _NoSuchTableError :
884+ schema = _pa .schema ([_pa .field ("id" , _pa .int64 ()), _pa .field ("name" , _pa .string ())])
885+ catalog .create_table (identifier , schema = schema )
886+
887+ def _ensure_single_snapshot (identifier ):
888+ try :
889+ catalog .load_table (identifier )
890+ except _NoSuchTableError :
891+ schema = _pa .schema ([_pa .field ("id" , _pa .int64 ()), _pa .field ("name" , _pa .string ())])
892+ table = catalog .create_table (identifier , schema = schema )
893+ data = _pa .Table .from_arrays ([_pa .array ([1 , 2 , 3 ]), _pa .array (["a" , "b" , "c" ])], schema = schema )
894+ commit_time = datetime .datetime (2023 , 1 , 1 , 12 , 0 , 0 )
895+ with _freeze_time (commit_time ):
896+ table .append (data )
897+
898+ def _ensure_two_snapshots (identifier ):
899+ try :
900+ catalog .load_table (identifier )
901+ except _NoSuchTableError :
902+ schema = _pa .schema ([_pa .field ("id" , _pa .int64 ()), _pa .field ("name" , _pa .string ())])
903+ table = catalog .create_table (identifier , schema = schema )
904+ data1 = _pa .Table .from_arrays ([_pa .array ([1 , 2 ]), _pa .array (["a" , "b" ])], schema = schema )
905+ commit_time1 = datetime .datetime (2021 , 1 , 1 , 12 , 0 , 0 )
906+ with _freeze_time (commit_time1 ):
907+ table .append (data1 )
908+ data2 = _pa .Table .from_arrays ([_pa .array ([1 , 2 , 3 ]), _pa .array (["a" , "b" , "c" ])], schema = schema )
909+ commit_time2 = datetime .datetime (2022 , 1 , 1 , 12 , 0 , 0 )
910+ with _freeze_time (commit_time2 ):
911+ table .overwrite (data2 )
912+
913+ _ensure_table_empty ("opteryx.empty_battery" )
914+ _ensure_single_snapshot ("opteryx.single_snap_battery" )
915+ _ensure_two_snapshots ("opteryx.two_snap_battery" )
916+
833917 return catalog
0 commit comments