Skip to content

Commit bb2fc80

Browse files
committed
feat: test rows_affected
1 parent 6d23a44 commit bb2fc80

3 files changed

Lines changed: 102 additions & 7 deletions

File tree

adbc_drivers_validation/model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class DriverFeatures:
9393
statement_execute_schema: bool = False
9494
statement_get_parameter_schema: bool = False
9595
statement_prepare: bool = True
96+
statement_rows_affected: bool = False
9697
_current_catalog: str | FromEnv | None = None
9798
_current_schema: str | FromEnv | None = None
9899
_secondary_schema: str | FromEnv | None = None

adbc_drivers_validation/tests/ingest.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ def test_create(
115115
raise
116116

117117
with setup_statement(query, cursor):
118-
cursor.adbc_ingest(table_name, data, mode="create")
118+
modified = cursor.adbc_ingest(table_name, data, mode="create")
119+
if driver.features.statement_rows_affected:
120+
assert modified == len(data)
121+
else:
122+
assert modified == -1
119123

120124
idx = driver.quote_identifier("idx")
121125
value = driver.quote_identifier("value")
@@ -158,8 +162,17 @@ def test_append(
158162
# Some databases have no way to do DROP IF EXISTS
159163
if not driver.is_table_not_found(table_name=table_name, error=e):
160164
raise
161-
cursor.adbc_ingest(table_name, data, mode="create")
162-
cursor.adbc_ingest(table_name, data2, mode="append")
165+
modified = cursor.adbc_ingest(table_name, data, mode="create")
166+
if driver.features.statement_rows_affected:
167+
assert modified == len(data)
168+
else:
169+
assert modified == -1
170+
171+
modified = cursor.adbc_ingest(table_name, data2, mode="append")
172+
if driver.features.statement_rows_affected:
173+
assert modified == len(data2)
174+
else:
175+
assert modified == -1
163176

164177
idx = driver.quote_identifier("idx")
165178
value = driver.quote_identifier("value")
@@ -234,8 +247,17 @@ def test_createappend(
234247
# Some databases have no way to do DROP IF EXISTS
235248
if not driver.is_table_not_found(table_name=table_name, error=e):
236249
raise
237-
cursor.adbc_ingest(table_name, data, mode="create_append")
238-
cursor.adbc_ingest(table_name, data2, mode="create_append")
250+
modified = cursor.adbc_ingest(table_name, data, mode="create_append")
251+
if driver.features.statement_rows_affected:
252+
assert modified == len(data)
253+
else:
254+
assert modified == -1
255+
256+
modified = cursor.adbc_ingest(table_name, data2, mode="create_append")
257+
if driver.features.statement_rows_affected:
258+
assert modified == len(data2)
259+
else:
260+
assert modified == -1
239261

240262
idx = driver.quote_identifier("idx")
241263
value = driver.quote_identifier("value")
@@ -280,10 +302,20 @@ def test_replace(
280302
if not driver.is_table_not_found(table_name=table_name, error=e):
281303
raise
282304
cursor.adbc_ingest(table_name, data, mode="replace")
305+
modified = cursor.adbc_ingest(table_name, data, mode="replace")
306+
if driver.features.statement_rows_affected:
307+
assert modified == len(data)
308+
else:
309+
assert modified == -1
310+
283311
if driver.name == "bigquery":
284312
# BigQuery rate-limits metadata operations
285313
time.sleep(5)
286-
cursor.adbc_ingest(table_name, data2, mode="replace")
314+
modified = cursor.adbc_ingest(table_name, data2, mode="replace")
315+
if driver.features.statement_rows_affected:
316+
assert modified == len(data2)
317+
else:
318+
assert modified == -1
287319

288320
idx = driver.quote_identifier("idx")
289321
value = driver.quote_identifier("value")
@@ -316,7 +348,11 @@ def test_replace_noop(
316348
# Some databases have no way to do DROP IF EXISTS
317349
if not driver.is_table_not_found(table_name=table_name, error=e):
318350
raise
319-
cursor.adbc_ingest(table_name, data, mode="replace")
351+
modified = cursor.adbc_ingest(table_name, data, mode="replace")
352+
if driver.features.statement_rows_affected:
353+
assert modified == len(data)
354+
else:
355+
assert modified == -1
320356

321357
idx = driver.quote_identifier("idx")
322358
value = driver.quote_identifier("value")

adbc_drivers_validation/tests/statement.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,61 @@ def test_transaction_toggle(
144144

145145
conn.adbc_connection.set_options(**{"adbc.connection.autocommit": True})
146146
assert conn.adbc_connection.get_option("adbc.connection.autocommit") == "true"
147+
148+
def test_rows_affected(
149+
self,
150+
driver: model.DriverQuirks,
151+
conn: adbc_driver_manager.dbapi.Connection,
152+
) -> None:
153+
table_name = "test_rows_affected"
154+
with conn.cursor() as cursor:
155+
cursor.adbc_statement.set_sql_query(
156+
driver.drop_table(table_name="test_rows_affected")
157+
)
158+
try:
159+
cursor.adbc_statement.execute_update()
160+
except adbc_driver_manager.Error as e:
161+
# Some databases have no way to do DROP IF EXISTS
162+
if not driver.is_table_not_found(table_name=table_name, error=e):
163+
raise
164+
165+
cursor.adbc_statement.set_sql_query(f"CREATE TABLE {table_name} (id INT)")
166+
rows_affected = cursor.adbc_statement.execute_update()
167+
168+
if driver.features.statement_rows_affected:
169+
assert rows_affected == 0
170+
else:
171+
assert rows_affected == -1
172+
173+
cursor.adbc_statement.set_sql_query(
174+
f"INSERT INTO {table_name} (id) VALUES (1)"
175+
)
176+
rows_affected = cursor.adbc_statement.execute_update()
177+
if driver.features.statement_rows_affected:
178+
assert rows_affected == 1
179+
else:
180+
assert rows_affected == -1
181+
182+
cursor.adbc_statement.set_sql_query(f"UPDATE {table_name} SET id = id + 1")
183+
rows_affected = cursor.adbc_statement.execute_update()
184+
if driver.features.statement_rows_affected:
185+
assert rows_affected == 1
186+
else:
187+
assert rows_affected == -1
188+
189+
cursor.adbc_statement.set_sql_query(f"DELETE FROM {table_name}")
190+
rows_affected = cursor.adbc_statement.execute_update()
191+
if driver.features.statement_rows_affected:
192+
assert rows_affected == 1
193+
else:
194+
assert rows_affected == -1
195+
196+
cursor.adbc_statement.set_sql_query(
197+
driver.drop_table(table_name="test_rows_affected")
198+
)
199+
try:
200+
cursor.adbc_statement.execute_update()
201+
except adbc_driver_manager.Error as e:
202+
# Some databases have no way to do DROP IF EXISTS
203+
if not driver.is_table_not_found(table_name=table_name, error=e):
204+
raise

0 commit comments

Comments
 (0)