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

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

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


##########
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:
   ```suggestion
                 .apply(GroupIntoBatches.<String, T>ofSize(batchSize)..withMaxBufferingDuration(Duration.millis(200)))
   ```



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