@@ -149,6 +149,52 @@ def _test_errors(
149
149
maybe_await (cur .execute_scheme ("DROP TABLE test" ))
150
150
maybe_await (cur .close ())
151
151
152
+ def _test_bulk_upsert (self , connection : dbapi .Connection ):
153
+ cursor = connection .cursor ()
154
+ maybe_await (cursor .execute_scheme (
155
+ """
156
+ CREATE TABLE pet (
157
+ pet_id INT,
158
+ name TEXT NOT NULL,
159
+ pet_type TEXT NOT NULL,
160
+ birth_date TEXT NOT NULL,
161
+ owner TEXT NOT NULL,
162
+ PRIMARY KEY (pet_id)
163
+ );
164
+ """
165
+ ))
166
+
167
+ column_types = (
168
+ ydb .BulkUpsertColumns ()
169
+ .add_column ("pet_id" , ydb .OptionalType (ydb .PrimitiveType .Int32 ))
170
+ .add_column ("name" , ydb .PrimitiveType .Utf8 )
171
+ .add_column ("pet_type" , ydb .PrimitiveType .Utf8 )
172
+ .add_column ("birth_date" , ydb .PrimitiveType .Utf8 )
173
+ .add_column ("owner" , ydb .PrimitiveType .Utf8 )
174
+ )
175
+
176
+ rows = [
177
+ {
178
+ "pet_id" : 3 ,
179
+ "name" : "Lester" ,
180
+ "pet_type" : "Hamster" ,
181
+ "birth_date" : "2020-06-23" ,
182
+ "owner" : "Lily"
183
+ },
184
+ {
185
+ "pet_id" : 4 ,
186
+ "name" : "Quincy" ,
187
+ "pet_type" : "Parrot" ,
188
+ "birth_date" : "2013-08-11" ,
189
+ "owner" : "Anne"
190
+ },
191
+ ]
192
+
193
+ maybe_await (connection .bulk_upsert ("pet" , rows , column_types ))
194
+
195
+ maybe_await (cursor .execute ("SELECT * FROM pet" ))
196
+ assert cursor .rowcount == 2
197
+
152
198
153
199
class TestConnection (BaseDBApiTestSuit ):
154
200
@pytest .fixture
@@ -191,6 +237,9 @@ def test_cursor_raw_query(self, connection: dbapi.Connection) -> None:
191
237
def test_errors (self , connection : dbapi .Connection ) -> None :
192
238
self ._test_errors (connection )
193
239
240
+ def test_bulk_upsert (self , connection : dbapi .Connection ) -> None :
241
+ self ._test_bulk_upsert (connection )
242
+
194
243
195
244
class TestAsyncConnection (BaseDBApiTestSuit ):
196
245
@pytest_asyncio .fixture
@@ -244,3 +293,9 @@ async def test_cursor_raw_query(
244
293
@pytest .mark .asyncio
245
294
async def test_errors (self , connection : dbapi .AsyncConnection ) -> None :
246
295
await greenlet_spawn (self ._test_errors , connection )
296
+
297
+ @pytest .mark .asyncio
298
+ async def test_bulk_upsert (
299
+ self , connection : dbapi .AsyncConnection
300
+ ) -> None :
301
+ await greenlet_spawn (self ._test_bulk_upsert , connection )
0 commit comments