mosche commented on a change in pull request #16503:
URL: https://github.com/apache/beam/pull/16503#discussion_r789843552



##########
File path: 
sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/sns/SnsIO.java
##########
@@ -418,8 +420,14 @@ public void setup() throws Exception {
 
       @ProcessElement
       public void processElement(ProcessContext context) throws Exception {
-        PublishRequest request =
-            (PublishRequest) 
spec.getPublishRequestFn().apply(context.element());
+        PublishRequest.Builder reqBuilder =

Review comment:
       It's actually not any different from before ... only if one uses the 
deprecated old interface there's an additional roundtrip converting a 
`PublishRequest` to `PublishRequest.Builder` to set the `topic` and back to 
`PublishRequest`.
   
   Previously `publishRequestFn` as `T => PublishRequest` was also using a 
`PublishRequest.Builder` per input element. But the request had to be build 
immediately. E.g. 
   
   ```java
   PublishRequest.builder().topicArn("topicArn").message(m).build()
   ```
   
   It would be possible to use `(T, PublishRequest.Builder) => PublishRequest` 
instead and reuse the same builder. But that comes with a rather high risk of 
leaking state between input elements as soon as fields are set conditionally by 
users. And the AWS SDK doesn't allow clearing a builder, so each field has to 
be reset manually with the risk of missing newly added fields.




-- 
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