You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "Abacn (via GitHub)" <gi...@apache.org> on 2023/01/26 00:44:43 UTC

[GitHub] [beam] Abacn commented on a diff in pull request #25173: Fix Jdbc Write after window assigned

Abacn commented on code in PR #25173:
URL: https://github.com/apache/beam/pull/25173#discussion_r1087325840


##########
sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java:
##########
@@ -1716,31 +1714,10 @@ static <T> PCollection<Iterable<T>> batchElements(
               .apply(Values.create());
     } else {
       iterables =
-          input.apply(
-              ParDo.of(
-                  new DoFn<T, Iterable<T>>() {
-                    @Nullable List<T> outputList;
-
-                    @ProcessElement
-                    public void process(ProcessContext c) {
-                      if (outputList == null) {
-                        outputList = new ArrayList<>();
-                      }
-                      outputList.add(c.element());
-                      if (outputList.size() > batchSize) {
-                        c.output(outputList);
-                        outputList = null;
-                      }
-                    }
-
-                    @FinishBundle
-                    public void finish(FinishBundleContext c) {
-                      if (outputList != null && outputList.size() > 0) {
-                        c.output(outputList, Instant.now(), GlobalWindow.INSTANCE);
-                      }
-                      outputList = null;
-                    }
-                  }));
+          input
+              .apply(WithKeys.<String, T>of(""))
+              .apply(GroupIntoBatches.<String, T>ofSize(batchSize).withShardedKey())

Review Comment:
   thanks for the detailed explanation. I am wondering what is the performance impact of changing it to GroupIntoBatches. Should we preserve the current implementation (a DoFn) used for batch, and use GroupIntoBatches  in streaming with/without autosharding?



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