diff --git a/CHANGES.md b/CHANGES.md index c754a4fe6581..cf828384b548 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -90,6 +90,8 @@ ## Deprecations * X behavior is deprecated and will be removed in X versions ([#X](https://github.com/apache/beam/issues/X)). +* Python SDK native SpannerIO (apache_beam/io/gcp/experimental/spannerio) is deprecated. Use cross-language wrapper + (apache_beam/io/gcp/spanner) instead (Python) ([#35860](https://github.com/apache/beam/issues/35860)). ## Bugfixes diff --git a/sdks/python/apache_beam/io/gcp/experimental/spannerio.py b/sdks/python/apache_beam/io/gcp/experimental/spannerio.py index 7b615e223cfc..cac66bd2ef54 100644 --- a/sdks/python/apache_beam/io/gcp/experimental/spannerio.py +++ b/sdks/python/apache_beam/io/gcp/experimental/spannerio.py @@ -17,7 +17,7 @@ """Google Cloud Spanner IO -Experimental; no backwards-compatibility guarantees. +Deprecated; use apache_beam.io.gcp.spanner module instead. This is an experimental module for reading and writing data from Google Cloud Spanner. Visit: https://cloud.google.com/spanner for more details. @@ -190,6 +190,7 @@ from apache_beam.transforms.display import DisplayDataItem from apache_beam.typehints import with_input_types from apache_beam.typehints import with_output_types +from apache_beam.utils.annotations import deprecated # Protect against environments where spanner library is not available. # pylint: disable=wrong-import-order, wrong-import-position, ungrouped-imports @@ -356,8 +357,8 @@ def _table_metric(self, table_id, status): labels = { **self.base_labels, monitoring_infos.RESOURCE_LABEL: resource, - monitoring_infos.SPANNER_TABLE_ID: table_id } + if table_id: labels[monitoring_infos.SPANNER_TABLE_ID] = table_id service_call_metric = ServiceCallMetric( request_count_urn=monitoring_infos.API_REQUEST_COUNT_URN, base_labels=labels) @@ -612,8 +613,8 @@ def _table_metric(self, table_id): labels = { **self.base_labels, monitoring_infos.RESOURCE_LABEL: resource, - monitoring_infos.SPANNER_TABLE_ID: table_id } + if table_id: labels[monitoring_infos.SPANNER_TABLE_ID] = table_id service_call_metric = ServiceCallMetric( request_count_urn=monitoring_infos.API_REQUEST_COUNT_URN, base_labels=labels) @@ -675,6 +676,7 @@ def teardown(self): self._snapshot.close() +@deprecated(since='2.68', current='apache_beam.io.gcp.spanner.ReadFromSpanner') class ReadFromSpanner(PTransform): """ A PTransform to perform reads from cloud spanner. @@ -825,6 +827,8 @@ def display_data(self): return res +@deprecated( + since='2.68', current='apache_beam.io.gcp.spanner.WriteToSpannerSchema') class WriteToSpanner(PTransform): def __init__( self, @@ -1224,8 +1228,8 @@ def _register_table_metric(self, table_id): labels = { **self.base_labels, monitoring_infos.RESOURCE_LABEL: resource, - monitoring_infos.SPANNER_TABLE_ID: table_id } + if table_id: labels[monitoring_infos.SPANNER_TABLE_ID] = table_id service_call_metric = ServiceCallMetric( request_count_urn=monitoring_infos.API_REQUEST_COUNT_URN, base_labels=labels) diff --git a/sdks/python/apache_beam/metrics/monitoring_infos.py b/sdks/python/apache_beam/metrics/monitoring_infos.py index 6dc4b7ef9c57..46f856676d34 100644 --- a/sdks/python/apache_beam/metrics/monitoring_infos.py +++ b/sdks/python/apache_beam/metrics/monitoring_infos.py @@ -367,8 +367,8 @@ def create_monitoring_info( urn=urn, type=type_urn, labels=labels or {}, payload=payload) except TypeError as e: raise RuntimeError( - f'Failed to create MonitoringInfo for urn {urn} type {type} labels ' + - '{labels} and payload {payload}') from e + f'Failed to create MonitoringInfo for urn {urn} type {type_urn} ' + f'labels {labels} and payload {payload}') from e def is_counter(monitoring_info_proto):