MiguelAnzoWizeline commented on a change in pull request #14811:
URL: https://github.com/apache/beam/pull/14811#discussion_r660731106



##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/BatchSpannerRead.java
##########
@@ -157,19 +154,29 @@ public void teardown() throws Exception {
     }
 
     @ProcessElement
-    public void processElement(ProcessContext c) throws Exception {
+    public void processElement(ProcessContext c, 
RestrictionTracker<OffsetRange, Long> tracker)
+        throws Exception {
       Transaction tx = c.sideInput(txView);
 
       BatchReadOnlyTransaction batchTx =
           
spannerAccessor.getBatchClient().batchReadOnlyTransaction(tx.transactionId());
 
-      Partition p = c.element();
-      try (ResultSet resultSet = batchTx.execute(p)) {
-        while (resultSet.next()) {
-          Struct s = resultSet.getCurrentRowAsStruct();
-          c.output(s);
+      List<Partition> partitions = c.element();
+      for (int i = (int) tracker.currentRestriction().getFrom(); i < 
partitions.size(); i++) {
+        if (tracker.tryClaim(Long.valueOf(i))) {
+          try (ResultSet resultSet = batchTx.execute(partitions.get(i))) {
+            while (resultSet.next()) {
+              Struct s = resultSet.getCurrentRowAsStruct();
+              c.output(s);
+            }
+          }
         }
       }
     }
+
+    @GetInitialRestriction
+    public OffsetRange getInitialRange(@Element List<Partition> partitions) {
+      return new OffsetRange(0L, partitions.size());

Review comment:
       I was looking for some examples, and all I could find used the size of 
the collection of elements as end, and changing it to a number < end gave me 
some incorrect results.




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