Skip to content

feat(spanner): add DataBoost and auto_partition_mode support to DBAPI driver - #18161

Open
sakthivelmanii wants to merge 2 commits into
mainfrom
feat-spanner-dbapi-databoost
Open

feat(spanner): add DataBoost and auto_partition_mode support to DBAPI driver#18161
sakthivelmanii wants to merge 2 commits into
mainfrom
feat-spanner-dbapi-databoost

Conversation

@sakthivelmanii

@sakthivelmanii sakthivelmanii commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Description

Add support for Cloud Spanner DataBoost and auto_partition_mode in the Python DBAPI (PEP 249) driver (google.cloud.spanner_dbapi).

Commit Structure

  1. Commit 1 (cff1650f719): feat(spanner): add DataBoost support to DBAPI driver and client-side statements

    • Adds data_boost_enabled: bool = False to connect() and Connection.
    • Adds SET DATA_BOOST_ENABLED and SHOW VARIABLE DATA_BOOST_ENABLED (returning DATA_BOOST_ENABLED column with BOOL type).
    • Forwards data_boost_enabled in Connection.partition_query() and Connection.run_partitioned_query().
    • Confines DataBoost execution to partitioned queries (per Spanner RPC requirement of partition_token).
  2. Commit 2 (9c53e3f9a81): feat(spanner): add auto_partition_mode support to DBAPI driver and client-side statements

    • Adds auto_partition_mode: bool = False to connect() and Connection.
    • Adds SET AUTO_PARTITION_MODE and SHOW VARIABLE AUTO_PARTITION_MODE (returning AUTO_PARTITION_MODE column with BOOL type).
    • Automatically partitions and parallelizes standard queries (cursor.execute() / pandas.read_sql()) when auto_partition_mode=True.
    • Enables seamless DataBoost execution for standard queries when both auto_partition_mode=True and data_boost_enabled=True.
    • Introduces reusable _parse_bool helper for client-side boolean parameter extraction.

Testing

  • All 234 unit and gRPC mock server tests passing.
  • Verified flake8 and ruff formatting/import sorting compliance.

@sakthivelmanii
sakthivelmanii requested a review from a team as a code owner August 19, 2026 13:26

@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 adds support for configuring and querying the DATA_BOOST_ENABLED setting on Spanner DB-API connections, including client-side statement parsing and execution for SET DATA_BOOST_ENABLED and SHOW VARIABLE DATA_BOOST_ENABLED. The reviewer feedback suggests improving the robustness of parsing by stripping quotes from the parameter value and initializing column_values directly as a list for consistency and safety.

if statement_type == ClientSideStatementType.SET_AUTOCOMMIT_DML_MODE:
return connection._set_autocommit_dml_mode(parsed_statement)
if statement_type == ClientSideStatementType.SET_DATA_BOOST_ENABLED:
val_str = parsed_statement.client_side_statement_params[0].strip().lower()

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.

medium

To make the SET DATA_BOOST_ENABLED statement more robust and user-friendly, consider stripping any surrounding single or double quotes from the value. This allows users to write both SET DATA_BOOST_ENABLED = TRUE and SET DATA_BOOST_ENABLED = 'TRUE'.

Suggested change
val_str = parsed_statement.client_side_statement_params[0].strip().lower()
val_str = parsed_statement.client_side_statement_params[0].strip().strip("'\"").lower()

connection.data_boost_enabled = val_str == "true"
return None
if statement_type == ClientSideStatementType.SHOW_DATA_BOOST_ENABLED:
column_values.append(str(connection.data_boost_enabled))

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.

medium

For consistency with other SHOW statements in this file (such as SHOW_COMMIT_TIMESTAMP and SHOW_READ_TIMESTAMP), it is better to directly assign column_values as a list rather than calling .append(). This also avoids relying on the mutable state of column_values initialized at the top of the function.

Suggested change
column_values.append(str(connection.data_boost_enabled))
column_values = [str(connection.data_boost_enabled)]

@olavloite olavloite 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.

Regarding this part in the PR description:

enabling analytical and bulk read workloads (e.g. pandas.read_sql) to execute on serverless compute

Note that this feature in its current implementation can only be used with RUN PARTITIONED QUERY .... Other Spanner drivers, like JDBC, additionally also support an autoPartitionMode=true|false variable to turn all queries into partitioned queries, which makes it easier to use DataBoost for all queries.

if statement_type == ClientSideStatementType.SHOW_DATA_BOOST_ENABLED:
column_values.append(str(connection.data_boost_enabled))
return _get_streamed_result_set(
ClientSideStatementType.SHOW_DATA_BOOST_ENABLED.name,

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 column name should preferably be DATA_BOOST_ENABLED (and not SHOW_DATA_BOOST_ENABLED

params,
get_param_types(params),
request_options=self.request_options,
data_boost_enabled=self.connection.data_boost_enabled,

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 will probably cause errors on Spanner. data_boost_enabled is only allowed for partitioned queries, not for any random query. I'll admit that I do not know for sure whether Spanner will throw an error or just ignore it, but the documentation seems to indicate that you will get an error:

If this is for a partitioned query and this field is set to true, the request is executed with Spanner Data Boost independent compute resources.If the field is set to true but the request doesn't set partition_token, the API returns an INVALID_ARGUMENT error.

fine-grained access controls.

:type data_boost_enabled: bool
:param data_boost_enabled: (Optional) Whether to enable DataBoost for

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.

nit: clarify in the comment that this will only have an effect for partitioned queries

)
)
self.assertEqual(1, len(requests))
self.assertTrue(requests[0].data_boost_enabled)

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 should check that the value is false. If you send this to Spanner, then you will get an error. Data boost can only be used with partitioned queries.

)
)
self.assertEqual(1, len(requests))
self.assertTrue(requests[0].data_boost_enabled)

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.

Same here, this would lead to an error

column_values.append(str(connection.data_boost_enabled))
return _get_streamed_result_set(
ClientSideStatementType.SHOW_DATA_BOOST_ENABLED.name,
TypeCode.STRING,

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.

Would it not make more sense to use TypeCode.BOOL here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

…statements

Add support for Cloud Spanner DataBoost in the Python DBAPI (PEP 249) driver (`google.cloud.spanner_dbapi`) for partitioned queries.

Key updates:
* Add `data_boost_enabled: bool = False` argument to `spanner_dbapi.connect()` and `Connection.__init__()`.
* Add `@property def data_boost_enabled(self)` getter and setter on `Connection`.
* Add client-side statement parsing and execution for:
  - `SET DATA_BOOST_ENABLED = TRUE|FALSE`
  - `SHOW VARIABLE DATA_BOOST_ENABLED` (returns column `DATA_BOOST_ENABLED` with `BOOL` type)
* Forward `data_boost_enabled` in `Connection.partition_query()` and `Connection.run_partitioned_query()`.
* Add unit and gRPC mock server test coverage across DBAPI connection, cursor, parser, statement executor, and mock server test suites.
@sakthivelmanii
sakthivelmanii force-pushed the feat-spanner-dbapi-databoost branch from dd78a1b to cff1650 Compare August 19, 2026 15:05
@parthea parthea assigned olavloite and unassigned sakthivelmanii Aug 19, 2026
@sakthivelmanii
sakthivelmanii force-pushed the feat-spanner-dbapi-databoost branch from cff1650 to 63b2f31 Compare August 19, 2026 15:41
@sakthivelmanii sakthivelmanii changed the title feat(spanner): add DataBoost support to DBAPI driver and client-side statements feat(spanner): add DataBoost and auto_partition_mode support to DBAPI driver Aug 19, 2026
@sakthivelmanii
sakthivelmanii force-pushed the feat-spanner-dbapi-databoost branch 2 times, most recently from 70243b1 to 8b24d43 Compare August 19, 2026 15:52
…ient-side statements

Add support for `auto_partition_mode` in the Python DBAPI driver (`google.cloud.spanner_dbapi`).

Key updates:
* Add `auto_partition_mode: bool = False` parameter to `spanner_dbapi.connect()` and `Connection.__init__()`.
* Add `@property def auto_partition_mode(self)` getter and setter on `Connection`.
* Add client-side statement parsing and execution for:
  - `SET AUTO_PARTITION_MODE = TRUE|FALSE`
  - `SHOW VARIABLE AUTO_PARTITION_MODE` (returns column `AUTO_PARTITION_MODE` with `BOOL` type)
* Automatically route queries in `Cursor._execute()` to `run_partitioned_query` when `auto_partition_mode=True`.
* Add unit and gRPC mock server test coverage for automatic query partitioning.
@sakthivelmanii
sakthivelmanii force-pushed the feat-spanner-dbapi-databoost branch from 8b24d43 to 9c53e3f Compare August 19, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants