damccorm commented on code in PR #41328:
URL: https://github.com/apache/beam/pull/41328#discussion_r4673017783


##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubIO.java:
##########
@@ -1912,12 +1913,11 @@ private class OutgoingData {
       public void startBundle(StartBundleContext c) throws IOException {
         this.output = Maps.newHashMap();
 
-        // NOTE: idAttribute is ignored.
         this.pubsubClient =
             getPubsubClientFactory()
                 .newClient(
                     getTimestampAttribute(),
-                    null,
+                    getIdAttribute(),

Review Comment:
   This shouldn't happen per bundle. If anything, this should be something we 
do at construction time like we do for unbounded sources - 
https://github.com/Naman-Katiyar/beam/blob/00d646e47c2901550be88a77e5a04772f0cebf60/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubIO.java#L1825



##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubIO.java:
##########
@@ -1930,9 +1930,18 @@ public void processElement(@Element PubsubMessage 
message, @Timestamp Instant ti
         // - Size validation makes no distinction between JSON and Protobuf 
encoding
         // - Accounting for HTTP to gRPC transcoding is non-trivial
         PreparePubsubWriteDoFn.validatePubsubMessage(message, 
maxPublishBatchByteSize);
-        // NOTE: The record id is always null since it will be assigned by 
Pub/Sub.
+        // If an id attribute is configured, use the id the message already
+        // carries, or generate a fresh random id for this element.
+        @Nullable String recordId = null;
+        @Nullable String idAttribute = getIdAttribute();
+        if (idAttribute != null) {
+          recordId = message.getAttribute(idAttribute);
+          if (recordId == null || recordId.isEmpty()) {
+            recordId = UUID.randomUUID().toString();

Review Comment:
   Assigning a random id seems wrong here. If there is a failure, this will be 
regenerated. We are better off leaving this null I think.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to