File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed
Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -1235,6 +1235,8 @@ def __init__(
12351235
12361236 self .annotations = annotations
12371237
1238+ self .display_data = {}
1239+
12381240 @property
12391241 def inputs (self ):
12401242 return tuple (self .main_inputs .values ())
@@ -1438,6 +1440,11 @@ def transform_to_runner_api(
14381440 (transform_urn not in Pipeline .runner_implemented_transforms ())):
14391441 environment_id = context .get_environment_id_for_resource_hints (
14401442 self .resource_hints )
1443+ if self .transform is not None :
1444+ display_data = DisplayData .create_from (
1445+ self .transform , extra_items = self .display_data )
1446+ else :
1447+ display_data = None
14411448
14421449 return beam_runner_api_pb2 .PTransform (
14431450 unique_name = self .full_label ,
@@ -1457,8 +1464,7 @@ def transform_to_runner_api(
14571464 environment_id = environment_id ,
14581465 annotations = self .annotations ,
14591466 # TODO(https://github.com/apache/beam/issues/18012): Add display_data.
1460- display_data = DisplayData .create_from (self .transform ).to_proto ()
1461- if self .transform else None )
1467+ display_data = display_data .to_proto () if display_data else None )
14621468
14631469 @staticmethod
14641470 def from_runner_api (
Original file line number Diff line number Diff line change @@ -226,7 +226,7 @@ def create_from_options(cls, pipeline_options):
226226 return cls (pipeline_options ._get_display_data_namespace (), items )
227227
228228 @classmethod
229- def create_from (cls , has_display_data ):
229+ def create_from (cls , has_display_data , extra_items = None ):
230230 """ Creates :class:`~apache_beam.transforms.display.DisplayData` from a
231231 :class:`HasDisplayData` instance.
232232
@@ -243,9 +243,11 @@ def create_from(cls, has_display_data):
243243 raise ValueError (
244244 'Element of class {}.{} does not subclass HasDisplayData' .format (
245245 has_display_data .__module__ , has_display_data .__class__ .__name__ ))
246+ if extra_items is None :
247+ extra_items = {}
246248 return cls (
247249 has_display_data ._get_display_data_namespace (),
248- has_display_data .display_data ())
250+ dict ( ** has_display_data .display_data (), ** extra_items ))
249251
250252
251253class DisplayDataItem (object ):
Original file line number Diff line number Diff line change @@ -217,6 +217,14 @@ def display_data(self):
217217 ]
218218
219219 hc .assert_that (dd .items , hc .has_items (* expected_items ))
220+ expected_items .append (
221+ DisplayDataItemMatcher (
222+ key = 'extra_key' , value = 'extra_value' , namespace = nspace ))
223+ hc .assert_that (
224+ DisplayData .create_from (fn , extra_items = {
225+ 'extra_key' : 'extra_value'
226+ }).items ,
227+ hc .has_items (* expected_items ))
220228
221229 def test_drop_if_none (self ):
222230 class MyDoFn (beam .DoFn ):
You can’t perform that action at this time.
0 commit comments