@@ -45,6 +45,7 @@ def test_example():
4545 run_tests()
4646"""
4747
48+ import datetime
4849import os
4950import platform
5051from functools import wraps
@@ -615,12 +616,12 @@ def create_duck_db(): # pragma: no cover
615616
616617 worker_id = os .environ .get ('PYTEST_XDIST_WORKER' , 'gw0' )
617618
618- if os .path .exists (f"planets-{ worker_id } .duckdb" ):
619+ if os .path .exists (f"tmp/ planets-{ worker_id } .duckdb" ):
619620 return
620621
621622 import duckdb
622623
623- conn = duckdb .connect (database = f"planets-{ worker_id } .duckdb" )
624+ conn = duckdb .connect (database = f"tmp/ planets-{ worker_id } .duckdb" )
624625 cur = conn .cursor ()
625626 try :
626627 cur .execute (CREATE_DATABASE )
@@ -736,6 +737,48 @@ def cast_dataset(dataset):
736737 opteryx .register_store ("iceberg" , IcebergConnector , catalog = catalog )
737738
738739 for dataset in ('planets' , 'satellites' , 'missions' , 'astronauts' ):
740+ if dataset == 'planets' :
741+ from opteryx .virtual_datasets import planet_data
742+
743+ def snapshot_props (label , cutoff ):
744+ props = {"temporal_version" : label }
745+ if cutoff is not None :
746+ props ["end_date" ] = cutoff .isoformat ()
747+ else :
748+ props ["end_date" ] = "current"
749+ return props
750+
751+ def load_planet_snapshot (cutoff ):
752+ table_data = planet_data .read () if cutoff is None else planet_data .read (end_date = cutoff )
753+ return cast_dataset (table_data )
754+
755+ snapshots = [
756+ ("pre_uranus" , datetime .datetime (1781 , 4 , 25 )),
757+ ("pre_neptune" , datetime .datetime (1846 , 11 , 12 )),
758+ ("pre_pluto" , datetime .datetime (1930 , 3 , 12 )),
759+ ("modern" , None ),
760+ ]
761+
762+ snapshot_label , cutoff = snapshots [0 ]
763+ snapshot_data = load_planet_snapshot (cutoff )
764+ table = catalog .create_table ("iceberg.planets" , schema = snapshot_data .schema )
765+ table .append (snapshot_data , snapshot_properties = snapshot_props (snapshot_label , cutoff ))
766+
767+ latest_snapshot = snapshot_data
768+ for snapshot_label , cutoff in snapshots [1 :]:
769+ snapshot_data = load_planet_snapshot (cutoff )
770+ table .overwrite (snapshot_data , snapshot_properties = snapshot_props (snapshot_label , cutoff ))
771+ latest_snapshot = snapshot_data
772+
773+ expected_rows = latest_snapshot .num_rows
774+ del latest_snapshot
775+ del snapshot_data
776+
777+ iceberged = opteryx .query ("SELECT * FROM iceberg.planets" )
778+ assert iceberged .rowcount == expected_rows
779+ del iceberged # Free memory immediately
780+ continue
781+
739782 data = opteryx .query_to_arrow (f"SELECT * FROM ${ dataset } " )
740783 data = cast_dataset (data )
741784
@@ -751,4 +794,4 @@ def cast_dataset(dataset):
751794 del iceberged # Free memory immediately
752795
753796
754- return catalog
797+ return catalog
0 commit comments