55"""
66
77import pyarrow as pa
8- import pytest
98
109from altertable_flightsql import Client
1110from altertable_flightsql .client import IngestIncrementalOptions
@@ -23,18 +22,23 @@ def test_ingest_simple_table(self, altertable_client: Client, test_schema: Schem
2322 fully_qualified_table = f"{ test_schema .full_name } .{ table_name } "
2423
2524 # Define schema
26- schema = pa .schema ([
27- ("id" , pa .int64 ()),
28- ("name" , pa .string ()),
29- ("value" , pa .float64 ()),
30- ])
25+ schema = pa .schema (
26+ [
27+ ("id" , pa .int64 ()),
28+ ("name" , pa .string ()),
29+ ("value" , pa .float64 ()),
30+ ]
31+ )
3132
3233 # Create test data
33- data = pa .record_batch ([
34- [1 , 2 , 3 , 4 , 5 ],
35- ["Alice" , "Bob" , "Charlie" , "David" , "Eve" ],
36- [100.5 , 200.0 , 300.75 , 400.25 , 500.5 ],
37- ], schema = schema )
34+ data = pa .record_batch (
35+ [
36+ [1 , 2 , 3 , 4 , 5 ],
37+ ["Alice" , "Bob" , "Charlie" , "David" , "Eve" ],
38+ [100.5 , 200.0 , 300.75 , 400.25 , 500.5 ],
39+ ],
40+ schema = schema ,
41+ )
3842
3943 try :
4044 # Ingest data
@@ -69,10 +73,12 @@ def test_ingest_multiple_batches(self, altertable_client: Client, test_schema: S
6973 fully_qualified_table = f"{ test_schema .full_name } .{ table_name } "
7074
7175 # Define schema
72- schema = pa .schema ([
73- ("id" , pa .int64 ()),
74- ("name" , pa .string ()),
75- ])
76+ schema = pa .schema (
77+ [
78+ ("id" , pa .int64 ()),
79+ ("name" , pa .string ()),
80+ ]
81+ )
7682
7783 try :
7884 # Ingest data
@@ -106,6 +112,7 @@ def test_ingest_multiple_batches(self, altertable_client: Client, test_schema: S
106112 except Exception as e :
107113 print (f"Warning: Failed to drop table { fully_qualified_table } : { e } " )
108114
115+
109116class TestIngestWithPrimaryKey :
110117 """Test ingest with primary key specification."""
111118
@@ -117,12 +124,14 @@ def test_ingest_with_primary_key(self, altertable_client: Client, test_schema: S
117124 fully_qualified_table = f"{ test_schema .full_name } .{ table_name } "
118125
119126 # Define schema
120- schema = pa .schema ([
121- ("id" , pa .int64 ()),
122- ("email" , pa .string ()),
123- ("name" , pa .string ()),
124- ("created_at" , pa .int64 ()),
125- ])
127+ schema = pa .schema (
128+ [
129+ ("id" , pa .int64 ()),
130+ ("email" , pa .string ()),
131+ ("name" , pa .string ()),
132+ ("created_at" , pa .int64 ()),
133+ ]
134+ )
126135
127136 try :
128137 # Ingest data with primary key
@@ -131,14 +140,26 @@ def test_ingest_with_primary_key(self, altertable_client: Client, test_schema: S
131140 schema = schema ,
132141 schema_name = test_schema .schema ,
133142 catalog_name = test_schema .catalog ,
134- incremental_options = IngestIncrementalOptions (primary_key = ["id" ], cursor_field = ["created_at" ]),
143+ incremental_options = IngestIncrementalOptions (
144+ primary_key = ["id" ], cursor_field = ["created_at" ]
145+ ),
135146 ) as writer :
136- writer .write (pa .record_batch ([
137- [1 , 2 , 3 , 1 ],
138- ["alice@example.com" , "bob@example.com" , "charlie@example.com" , "alice+1@example.com" ],
139- ["Alice" , "Bob" , "Charlie" , "Alice" ],
140- [1 , 2 , 3 , 4 ],
141- ], schema = schema ))
147+ writer .write (
148+ pa .record_batch (
149+ [
150+ [1 , 2 , 3 , 1 ],
151+ [
152+ "alice@example.com" ,
153+ "bob@example.com" ,
154+ "charlie@example.com" ,
155+ "alice+1@example.com" ,
156+ ],
157+ ["Alice" , "Bob" , "Charlie" , "Alice" ],
158+ [1 , 2 , 3 , 4 ],
159+ ],
160+ schema = schema ,
161+ )
162+ )
142163
143164 # Verify data was ingested
144165 reader = altertable_client .query (f"SELECT * FROM { fully_qualified_table } ORDER BY id" )
@@ -147,12 +168,16 @@ def test_ingest_with_primary_key(self, altertable_client: Client, test_schema: S
147168 assert result .num_rows == 3
148169 result_df = result .to_pandas ()
149170 assert list (result_df ["id" ]) == [1 , 2 , 3 ]
150- assert list (result_df ["email" ]) == ["alice+1@example.com" , "bob@example.com" , "charlie@example.com" ]
171+ assert list (result_df ["email" ]) == [
172+ "alice+1@example.com" ,
173+ "bob@example.com" ,
174+ "charlie@example.com" ,
175+ ]
151176 assert list (result_df ["name" ]) == ["Alice" , "Bob" , "Charlie" ]
152177
153178 finally :
154179 # Cleanup
155180 try :
156181 altertable_client .execute (f"DROP TABLE IF EXISTS { fully_qualified_table } " )
157182 except Exception as e :
158- print (f"Warning: Failed to drop table { fully_qualified_table } : { e } " )
183+ print (f"Warning: Failed to drop table { fully_qualified_table } : { e } " )
0 commit comments