@@ -149,6 +149,57 @@ 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 ) -> None :
153
+ cursor = connection .cursor ()
154
+ with suppress (dbapi .DatabaseError ):
155
+ maybe_await (cursor .execute_scheme ("DROP TABLE pet" ))
156
+
157
+ maybe_await (cursor .execute_scheme (
158
+ """
159
+ CREATE TABLE pet (
160
+ pet_id INT,
161
+ name TEXT NOT NULL,
162
+ pet_type TEXT NOT NULL,
163
+ birth_date TEXT NOT NULL,
164
+ owner TEXT NOT NULL,
165
+ PRIMARY KEY (pet_id)
166
+ );
167
+ """
168
+ ))
169
+
170
+ column_types = (
171
+ ydb .BulkUpsertColumns ()
172
+ .add_column ("pet_id" , ydb .OptionalType (ydb .PrimitiveType .Int32 ))
173
+ .add_column ("name" , ydb .PrimitiveType .Utf8 )
174
+ .add_column ("pet_type" , ydb .PrimitiveType .Utf8 )
175
+ .add_column ("birth_date" , ydb .PrimitiveType .Utf8 )
176
+ .add_column ("owner" , ydb .PrimitiveType .Utf8 )
177
+ )
178
+
179
+ rows = [
180
+ {
181
+ "pet_id" : 3 ,
182
+ "name" : "Lester" ,
183
+ "pet_type" : "Hamster" ,
184
+ "birth_date" : "2020-06-23" ,
185
+ "owner" : "Lily"
186
+ },
187
+ {
188
+ "pet_id" : 4 ,
189
+ "name" : "Quincy" ,
190
+ "pet_type" : "Parrot" ,
191
+ "birth_date" : "2013-08-11" ,
192
+ "owner" : "Anne"
193
+ },
194
+ ]
195
+
196
+ maybe_await (connection .bulk_upsert ("pet" , rows , column_types ))
197
+
198
+ maybe_await (cursor .execute ("SELECT * FROM pet" ))
199
+ assert cursor .rowcount == 2
200
+
201
+ maybe_await (cursor .execute_scheme ("DROP TABLE pet" ))
202
+
152
203
153
204
class TestConnection (BaseDBApiTestSuit ):
154
205
@pytest .fixture
@@ -191,6 +242,9 @@ def test_cursor_raw_query(self, connection: dbapi.Connection) -> None:
191
242
def test_errors (self , connection : dbapi .Connection ) -> None :
192
243
self ._test_errors (connection )
193
244
245
+ def test_bulk_upsert (self , connection : dbapi .Connection ) -> None :
246
+ self ._test_bulk_upsert (connection )
247
+
194
248
195
249
class TestAsyncConnection (BaseDBApiTestSuit ):
196
250
@pytest_asyncio .fixture
@@ -244,3 +298,9 @@ async def test_cursor_raw_query(
244
298
@pytest .mark .asyncio
245
299
async def test_errors (self , connection : dbapi .AsyncConnection ) -> None :
246
300
await greenlet_spawn (self ._test_errors , connection )
301
+
302
+ @pytest .mark .asyncio
303
+ async def test_bulk_upsert (
304
+ self , connection : dbapi .AsyncConnection
305
+ ) -> None :
306
+ await greenlet_spawn (self ._test_bulk_upsert , connection )
0 commit comments