feat: add databoost enabled property for batch transactions by asthamohta · Pull Request #892 · googleapis/python-spanner · GitHub
Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion google/cloud/spanner_v1/database.py
20 changes: 20 additions & 0 deletions google/cloud/spanner_v1/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def read(
limit=0,
partition=None,
request_options=None,
data_boost_enabled=False,
*,
retry=gapic_v1.method.DEFAULT,
timeout=gapic_v1.method.DEFAULT,
Expand Down Expand Up @@ -210,6 +211,14 @@ def read(
:type timeout: float
:param timeout: (Optional) The timeout for this request.

:type data_boost_enabled:
:param data_boost_enabled:
(Optional) If this is for a partitioned read and this field is
set ``true``, the request will be executed via offline access.
If the field is set to ``true`` but the request does not set
``partition_token``, the API will return an
``INVALID_ARGUMENT`` error.

:rtype: :class:`~google.cloud.spanner_v1.streamed.StreamedResultSet`
:returns: a result set instance which can be used to consume rows.

Expand Down Expand Up @@ -247,6 +256,7 @@ def read(
limit=limit,
partition_token=partition,
request_options=request_options,
data_boost_enabled=data_boost_enabled,
)
restart = functools.partial(
api.streaming_read,
Expand Down Expand Up @@ -302,6 +312,7 @@ def execute_sql(
partition=None,
retry=gapic_v1.method.DEFAULT,
timeout=gapic_v1.method.DEFAULT,
data_boost_enabled=False,
):
"""Perform an ``ExecuteStreamingSql`` API request.

Expand Down Expand Up @@ -351,6 +362,14 @@ def execute_sql(
:type timeout: float
:param timeout: (Optional) The timeout for this request.

:type data_boost_enabled:
:param data_boost_enabled:
(Optional) If this is for a partitioned query and this field is
set ``true``, the request will be executed via offline access.
If the field is set to ``true`` but the request does not set
``partition_token``, the API will return an
``INVALID_ARGUMENT`` error.

:raises ValueError:
for reuse of single-use snapshots, or if a transaction ID is
already pending for multiple-use snapshots.
Expand Down Expand Up @@ -400,6 +419,7 @@ def execute_sql(
seqno=self._execute_sql_count,
query_options=query_options,
request_options=request_options,
data_boost_enabled=data_boost_enabled,
)
restart = functools.partial(
api.execute_streaming_sql,
Expand Down
7 changes: 6 additions & 1 deletion samples/samples/batch_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def run_batch_query(instance_id, database_id):
table="Singers",
columns=("SingerId", "FirstName", "LastName"),
keyset=spanner.KeySet(all_=True),
# A Partition object is serializable and can be used from a different process.
# DataBoost option is an optional parameter which can also be used for partition read
# and query to execute the request via spanner independent compute resources.
data_boost_enabled=True,
)

# Create a pool of workers for the tasks
Expand Down Expand Up @@ -87,4 +91,5 @@ def process(snapshot, partition):

args = parser.parse_args()

run_batch_query(args.instance_id, args.database_id)
if args.command == "run_batch_query":
run_batch_query(args.instance_id, args.database_id)
12 changes: 8 additions & 4 deletions tests/system/test_session_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ def test_read_with_range_keys_and_index_open_open(sessions_database):
assert rows == expected


def test_partition_read_w_index(sessions_database):
def test_partition_read_w_index(sessions_database, not_emulator):
sd = _sample_data
row_count = 10
columns = sd.COLUMNS[1], sd.COLUMNS[2]
Expand All @@ -1886,7 +1886,11 @@ def test_partition_read_w_index(sessions_database):

batch_txn = sessions_database.batch_snapshot(read_timestamp=committed)
batches = batch_txn.generate_read_batches(
sd.TABLE, columns, spanner_v1.KeySet(all_=True), index="name"
sd.TABLE,
columns,
spanner_v1.KeySet(all_=True),
index="name",
data_boost_enabled=True,
)
for batch in batches:
p_results_iter = batch_txn.process(batch)
Expand Down Expand Up @@ -2494,7 +2498,7 @@ def test_execute_sql_returning_transfinite_floats(sessions_database, not_postgre
assert math.isnan(float_array[2])


def test_partition_query(sessions_database):
def test_partition_query(sessions_database, not_emulator):
row_count = 40
sql = f"SELECT * FROM {_sample_data.TABLE}"
committed = _set_up_table(sessions_database, row_count)
Expand All @@ -2503,7 +2507,7 @@ def test_partition_query(sessions_database):
all_data_rows = set(_row_data(row_count))
union = set()
batch_txn = sessions_database.batch_snapshot(read_timestamp=committed)
for batch in batch_txn.generate_query_batches(sql):
for batch in batch_txn.generate_query_batches(sql, data_boost_enabled=True):
p_results_iter = batch_txn.process(batch)
# Lists aren't hashable so the results need to be converted
rows = [tuple(result) for result in p_results_iter]
Expand Down
83 changes: 82 additions & 1 deletion tests/unit/test_database.py