feat(spanner): add DataBoost and auto_partition_mode support to DBAPI driver - #18161
feat(spanner): add DataBoost and auto_partition_mode support to DBAPI driver#18161sakthivelmanii wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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'.
| 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)) |
There was a problem hiding this comment.
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.
| column_values.append(str(connection.data_boost_enabled)) | |
| column_values = [str(connection.data_boost_enabled)] |
olavloite
left a comment
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Would it not make more sense to use TypeCode.BOOL here?
…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.
dd78a1b to
cff1650
Compare
cff1650 to
63b2f31
Compare
70243b1 to
8b24d43
Compare
…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.
8b24d43 to
9c53e3f
Compare
Description
Add support for Cloud Spanner DataBoost and
auto_partition_modein the Python DBAPI (PEP 249) driver (google.cloud.spanner_dbapi).Commit Structure
Commit 1 (
cff1650f719):feat(spanner): add DataBoost support to DBAPI driver and client-side statementsdata_boost_enabled: bool = Falsetoconnect()andConnection.SET DATA_BOOST_ENABLEDandSHOW VARIABLE DATA_BOOST_ENABLED(returningDATA_BOOST_ENABLEDcolumn withBOOLtype).data_boost_enabledinConnection.partition_query()andConnection.run_partitioned_query().partition_token).Commit 2 (
9c53e3f9a81):feat(spanner): add auto_partition_mode support to DBAPI driver and client-side statementsauto_partition_mode: bool = Falsetoconnect()andConnection.SET AUTO_PARTITION_MODEandSHOW VARIABLE AUTO_PARTITION_MODE(returningAUTO_PARTITION_MODEcolumn withBOOLtype).cursor.execute()/pandas.read_sql()) whenauto_partition_mode=True.auto_partition_mode=Trueanddata_boost_enabled=True._parse_boolhelper for client-side boolean parameter extraction.Testing