Skip to content

Commit 01c5d9f

Browse files
committed
Deprecate native Python SpannerIO
The native Python SpannerIO implementation in apache_beam/io/gcp/experimental has been marked as experimental and less maintained. It is being deprecated in favor of the cross-language SpannerIO implementation in apache_beam/io/gcp/spanner. This change adds module-level and class-level deprecation warnings to clear state that the native implementation will be removed in Beam 3.0. Migration Guidance: For reads, migrate to apache_beam.io.gcp.spanner.ReadFromSpanner. For writes, migrate to apache_beam.io.gcp.spanner.SpannerInsert, SpannerUpdate, etc.
1 parent c7d13c4 commit 01c5d9f

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

sdks/python/apache_beam/io/gcp/experimental/spannerio.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
This is an experimental module for reading and writing data from Google Cloud
2323
Spanner. Visit: https://cloud.google.com/spanner for more details.
2424
25+
.. deprecated:: 2.68
26+
Native Python SpannerIO is deprecated and will be removed in Beam 3.0.
27+
Use the cross-language SpannerIO available in apache_beam.io.gcp.spanner instead.
28+
29+
2530
Reading Data from Cloud Spanner.
2631
2732
To read from Cloud Spanner apply ReadFromSpanner transformation. It will
@@ -169,6 +174,7 @@
169174
column does not exits, it will cause a exception and fails the entire pipeline.
170175
"""
171176
import typing
177+
import warnings
172178
from collections import deque
173179
from collections import namedtuple
174180

@@ -218,6 +224,12 @@
218224
# Ignoring for environments where the Spanner library is not available.
219225
pass
220226

227+
_DEPRECATION_MESSAGE = (
228+
"Native Python SpannerIO is deprecated and will be removed in Beam 3.0. "
229+
"Use the cross-language SpannerIO available in apache_beam.io.gcp.spanner instead."
230+
)
231+
warnings.warn(_DEPRECATION_MESSAGE, DeprecationWarning)
232+
221233
__all__ = [
222234
'create_transaction',
223235
'ReadFromSpanner',
@@ -241,9 +253,12 @@ class ReadOperation(namedtuple(
241253
"""
242254
Encapsulates a spanner read operation.
243255
"""
244-
245256
__slots__ = ()
246257

258+
@deprecated(since='2.68', extra_message=_DEPRECATION_MESSAGE)
259+
def __new__(cls, *args, **kwargs):
260+
return super(ReadOperation, cls).__new__(cls, *args, **kwargs)
261+
247262
@classmethod
248263
def query(cls, sql, params=None, param_types=None):
249264
"""
@@ -535,6 +550,7 @@ def process(self, element, *args, **kwargs):
535550
return [_SPANNER_TRANSACTION(self._snapshot.to_dict())]
536551

537552

553+
@deprecated(since='2.68', extra_message=_DEPRECATION_MESSAGE)
538554
@ptransform_fn
539555
def create_transaction(
540556
pbegin,
@@ -670,7 +686,10 @@ def teardown(self):
670686
self._snapshot.close()
671687

672688

673-
@deprecated(since='2.68', current='apache_beam.io.gcp.spanner.ReadFromSpanner')
689+
@deprecated(
690+
since='2.68',
691+
current='apache_beam.io.gcp.spanner.ReadFromSpanner',
692+
extra_message=_DEPRECATION_MESSAGE)
674693
class ReadFromSpanner(PTransform):
675694
"""
676695
A PTransform to perform reads from cloud spanner.
@@ -822,7 +841,9 @@ def display_data(self):
822841

823842

824843
@deprecated(
825-
since='2.68', current='apache_beam.io.gcp.spanner.WriteToSpannerSchema')
844+
since='2.68',
845+
current='apache_beam.io.gcp.spanner',
846+
extra_message=_DEPRECATION_MESSAGE)
826847
class WriteToSpanner(PTransform):
827848
def __init__(
828849
self,
@@ -915,6 +936,10 @@ class MutationGroup(deque):
915936
"""
916937
A Bundle of Spanner Mutations (_Mutator).
917938
"""
939+
@deprecated(since='2.68', extra_message=_DEPRECATION_MESSAGE)
940+
def __init__(self, *args, **kwargs):
941+
super(MutationGroup, self).__init__(*args, **kwargs)
942+
918943
@property
919944
def info(self):
920945
cells = 0
@@ -938,6 +963,7 @@ class WriteMutation(object):
938963
_OPERATION_REPLACE = "replace"
939964
_OPERATION_UPDATE = "update"
940965

966+
@deprecated(since='2.68', extra_message=_DEPRECATION_MESSAGE)
941967
def __init__(
942968
self,
943969
insert=None,

0 commit comments

Comments
 (0)