-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add 'Datatbase.execute_partitioned_dml' method. * Add system test which exercises PDML. both for UPDATE (with parameter) and DELETE.
- Loading branch information
Showing
4 changed files
with
380 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -730,6 +730,62 @@ def test_transaction_execute_update_then_insert_commit(self): | |
rows = list(session.read(self.TABLE, self.COLUMNS, self.ALL)) | ||
self._check_rows_data(rows) | ||
|
||
def test_execute_partitioned_dml(self): | ||
retry = RetryInstanceState(_has_all_ddl) | ||
retry(self._db.reload)() | ||
|
||
delete_statement = 'DELETE FROM {} WHERE true'.format(self.TABLE) | ||
|
||
def _setup_table(txn): | ||
txn.execute_update(delete_statement) | ||
for insert_statement in self._generate_insert_statements(): | ||
txn.execute_update(insert_statement) | ||
|
||
committed = self._db.run_in_transaction(_setup_table) | ||
|
||
with self._db.snapshot(read_timestamp=committed) as snapshot: | ||
before_pdml = list(snapshot.read( | ||
self.TABLE, self.COLUMNS, self.ALL)) | ||
|
||
self._check_rows_data(before_pdml) | ||
|
||
nonesuch = '[email protected]' | ||
target = '[email protected]' | ||
update_statement = ( | ||
'UPDATE {table} SET {table}.email = @email ' | ||
'WHERE {table}.email = @target').format( | ||
table=self.TABLE) | ||
|
||
row_count = self._db.execute_partitioned_dml( | ||
update_statement, | ||
params={ | ||
'email': nonesuch, | ||
'target': target, | ||
}, | ||
param_types={ | ||
'email': Type(code=STRING), | ||
'target': Type(code=STRING), | ||
}, | ||
) | ||
self.assertEqual(row_count, 1) | ||
|
||
row = self.ROW_DATA[0] | ||
updated = [row[:3] + (nonesuch,)] + list(self.ROW_DATA[1:]) | ||
|
||
with self._db.snapshot(read_timestamp=committed) as snapshot: | ||
after_update = list(snapshot.read( | ||
self.TABLE, self.COLUMNS, self.ALL)) | ||
self._check_rows_data(after_update, updated) | ||
|
||
row_count = self._db.execute_partitioned_dml(delete_statement) | ||
self.assertEqual(row_count, len(self.ROW_DATA)) | ||
|
||
with self._db.snapshot(read_timestamp=committed) as snapshot: | ||
after_delete = list(snapshot.read( | ||
self.TABLE, self.COLUMNS, self.ALL)) | ||
|
||
self._check_rows_data(after_delete, []) | ||
|
||
def _transaction_concurrency_helper(self, unit_of_work, pkey): | ||
INITIAL_VALUE = 123 | ||
NUM_THREADS = 3 # conforms to equivalent Java systest. | ||
|
Oops, something went wrong.