Skip to content

feat(bigquery): add bigquery_multi_statement_transaction sample to ru… - #14720

Merged
iennae merged 1 commit into
mainfrom
feat/bq-multi-statement-transaction
Nov 3, 2026
Merged

iennae merged 1 commit into
mainfrom
feat/bq-multi-statement-transaction

Conversation

@iennae

@iennae iennae commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

…n a multi-statement transaction with rollback

Problem:
The BigQuery documentation (https://cloud.google.com/bigquery/docs/transactions#example_of_a_transaction) needs a standalone, tested Python code sample demonstrating how to run a multi-statement transaction with rollback (region tag bigquery_multi_statement_transaction).

Solution:

  • Add run_multi_statement_transaction(project_id: str, dataset_id: str, source_table_id: str, target_table_id: str) -> None in bigquery/transactions/bigquery_multi_statement_transaction.py (Execute a multi-statement GoogleSQL transaction across BigQuery tables using BEGIN TRANSACTION, COMMIT TRANSACTION, and EXCEPTION WHEN ERROR THEN ROLLBACK TRANSACTION.)
  • Add unit tests (bigquery/transactions/bigquery_multi_statement_transaction_test.py) covering both the success path and API error handling (GoogleAPICallError)

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

@iennae
iennae requested review from a team and chalmerlowe as code owners November 1, 2026 20:23
@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the BigQuery API. label Nov 1, 2026
@snippet-bot

snippet-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Nov 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new BigQuery sample demonstrating how to execute a multi-statement SQL transaction with exception rollback handling using the Python client, along with corresponding unit tests and configuration files. The feedback suggests updating the ignored_versions in noxfile_config.py to ensure only the oldest and newest supported Python versions (3.10 and 3.13) are tested, ignoring intermediate versions like 3.11 and 3.12.

Comment thread bigquery/transactions/noxfile_config.py Resolved

@XrossFox XrossFox left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me, but a dependency on the requirements file is outdated.

Comment thread bigquery/transactions/requirements.txt Outdated
@@ -0,0 +1 @@
google-cloud-bigquery==3.35.1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version of bigquery is over a year old, most recent version is 3.47.0

@iennae
iennae force-pushed the feat/bq-multi-statement-transaction branch 3 times, most recently from 0e3fccb to e0a4a27 Compare November 2, 2026 23:33
…n a multi-statement transaction with rollback

Problem:
The BigQuery documentation (https://cloud.google.com/bigquery/docs/transactions#example_of_a_transaction)
needs a standalone, tested Python code sample demonstrating how to
run a multi-statement transaction with rollback (region tag `bigquery_multi_statement_transaction`).

Solution:
- Add `run_multi_statement_transaction(project_id: str, dataset_id: str, source_table_id: str, target_table_id: str) -> None` in `bigquery/transactions/bigquery_multi_statement_transaction.py`
  (Execute a multi-statement GoogleSQL transaction across BigQuery tables using BEGIN TRANSACTION, COMMIT TRANSACTION, and EXCEPTION WHEN ERROR THEN ROLLBACK TRANSACTION.)
- Add unit tests (`bigquery/transactions/bigquery_multi_statement_transaction_test.py`) covering both the success
  path and API error handling (`GoogleAPICallError`)
@iennae
iennae force-pushed the feat/bq-multi-statement-transaction branch from e0a4a27 to abc43fd Compare November 3, 2026 02:44
@iennae
iennae merged commit 74647ea into main Nov 3, 2026
14 of 22 checks passed
@iennae
iennae deleted the feat/bq-multi-statement-transaction branch November 3, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the BigQuery API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants