Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use DML batches in executemany() method #412

Merged
merged 25 commits into from Aug 9, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions google/cloud/spanner_dbapi/cursor.py
Expand Up @@ -38,6 +38,7 @@
from google.cloud.spanner_dbapi import parse_utils
from google.cloud.spanner_dbapi.parse_utils import get_param_types
from google.cloud.spanner_dbapi.parse_utils import sql_pyformat_args_to_spanner
from google.cloud.spanner_dbapi.parse_utils import RE_INSERT
from google.cloud.spanner_dbapi.utils import PeekIterator
from google.cloud.spanner_dbapi.utils import StreamedManyResultSets

Expand Down Expand Up @@ -258,9 +259,21 @@ def executemany(self, operation, seq_of_params):

many_result_set = StreamedManyResultSets()

for params in seq_of_params:
self.execute(operation, params)
many_result_set.add_iter(self._itr)
if classification == parse_utils.STMT_INSERT:
IlyaFaer marked this conversation as resolved.
Show resolved Hide resolved
match = RE_INSERT.search(operation)

table_name = match["table_name"].strip("`")

transaction = self.connection.transaction_checkout()
transaction.insert(
table=table_name,
columns=[col.strip('" ') for col in match["columns"].split(",")],
IlyaFaer marked this conversation as resolved.
Show resolved Hide resolved
values=seq_of_params,
)
else:
for params in seq_of_params:
self.execute(operation, params)
many_result_set.add_iter(self._itr)

self._result_set = many_result_set
self._itr = many_result_set
Expand Down