Skip to content

Commit

Permalink
chore(spanner): Issue#1163 Remove dependency of spanner dbapi from sp…
Browse files Browse the repository at this point in the history
…anner_v1 (googleapis#1164)

- Moved BatchTransactionId dataclass from spanner_dbapi to spanner_v1.transactions

Co-authored-by: Sri Harsha CH <57220027+harshachinta@users.noreply.github.com>
  • Loading branch information
bhatt4982 and harshachinta authored Jul 22, 2024
1 parent 9609ad9 commit fe20d41
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
9 changes: 2 additions & 7 deletions google/cloud/spanner_dbapi/partition_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import pickle
import base64

from google.cloud.spanner_v1 import BatchTransactionId


def decode_from_string(encoded_partition_id):
gzip_bytes = base64.b64decode(bytes(encoded_partition_id, "utf-8"))
Expand All @@ -33,13 +35,6 @@ def encode_to_string(batch_transaction_id, partition_result):
return str(base64.b64encode(gzip_bytes), "utf-8")


@dataclass
class BatchTransactionId:
transaction_id: str
session_id: str
read_timestamp: Any


@dataclass
class PartitionId:
batch_transaction_id: BatchTransactionId
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/spanner_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from .types.type import TypeAnnotationCode
from .types.type import TypeCode
from .data_types import JsonObject
from .transaction import BatchTransactionId

from google.cloud.spanner_v1 import param_types
from google.cloud.spanner_v1.client import Client
Expand Down Expand Up @@ -147,4 +148,5 @@
# google.cloud.spanner_v1.services
"SpannerClient",
"SpannerAsyncClient",
"BatchTransactionId",
)
2 changes: 1 addition & 1 deletion google/cloud/spanner_v1/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from google.cloud.spanner_admin_database_v1 import RestoreDatabaseRequest
from google.cloud.spanner_admin_database_v1 import UpdateDatabaseDdlRequest
from google.cloud.spanner_admin_database_v1.types import DatabaseDialect
from google.cloud.spanner_dbapi.partition_helper import BatchTransactionId
from google.cloud.spanner_v1.transaction import BatchTransactionId
from google.cloud.spanner_v1 import ExecuteSqlRequest
from google.cloud.spanner_v1 import Type
from google.cloud.spanner_v1 import TypeCode
Expand Down
9 changes: 9 additions & 0 deletions google/cloud/spanner_v1/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
from google.cloud.spanner_v1 import RequestOptions
from google.api_core import gapic_v1
from google.api_core.exceptions import InternalServerError
from dataclasses import dataclass
from typing import Any


class Transaction(_SnapshotBase, _BatchBase):
Expand Down Expand Up @@ -554,3 +556,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self.commit()
else:
self.rollback()


@dataclass
class BatchTransactionId:
transaction_id: str
session_id: str
read_timestamp: Any

0 comments on commit fe20d41

Please sign in to comment.