You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/09/27 23:26:47 UTC

[GitHub] [beam] robertwb commented on a change in pull request #15564: [BEAM-11129] Add namespace and key to portable display data

robertwb commented on a change in pull request #15564:
URL: https://github.com/apache/beam/pull/15564#discussion_r717112192



##########
File path: runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/DisplayDataTranslation.java
##########
@@ -65,13 +64,22 @@
     return builder.build();
   }
 
-  private static ByteString translateStringUtf8(DisplayData.Item item) {
-    String value = String.valueOf(item.getValue() == null ? item.getShortValue() : item.getValue());
+  private static ByteString translate(DisplayData.Item item) {
     String label = item.getLabel() == null ? item.getKey() : item.getLabel();
-    return RunnerApi.LabelledPayload.newBuilder()
-        .setLabel(label)
-        .setStringValue(value)
-        .build()
-        .toByteString();
+    String namespace = item.getNamespace() == null ? "" : item.getNamespace().getName();
+    RunnerApi.LabelledPayload.Builder builder =
+        RunnerApi.LabelledPayload.newBuilder()
+            .setKey(item.getKey())
+            .setLabel(label)
+            .setNamespace(namespace);
+    Object valueObj = item.getValue() == null ? item.getShortValue() : item.getValue();
+    if (valueObj instanceof Boolean) {
+      builder.setBoolValue((Boolean) valueObj);
+    } else if (valueObj instanceof Number) {

Review comment:
       This might be lossy. Could you add an integer type as well? 

##########
File path: sdks/python/apache_beam/transforms/display.py
##########
@@ -149,13 +149,22 @@ def create_payload(dd):
       value = display_data_dict['value']
       if isinstance(value, str):
         return beam_runner_api_pb2.LabelledPayload(
-            label=label, string_value=value)
+            label=label,
+            string_value=value,
+            key=display_data_dict['key'],
+            namespace=display_data_dict.get('namespace', ''))
       elif isinstance(value, bool):
         return beam_runner_api_pb2.LabelledPayload(
-            label=label, bool_value=value)
+            label=label,
+            bool_value=value,
+            key=display_data_dict['key'],
+            namespace=display_data_dict.get('namespace', ''))
       elif isinstance(value, (int, float, complex)):

Review comment:
       Same.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org