[ 
https://issues.apache.org/jira/browse/BEAM-11996?focusedWorklogId=616548&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-616548
 ]

ASF GitHub Bot logged work on BEAM-11996:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 29/Jun/21 15:28
            Start Date: 29/Jun/21 15:28
    Worklog Time Spent: 10m 
      Work Description: 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]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 616548)
    Time Spent: 3h 40m  (was: 3.5h)

> Implement SpannerIO on top of Splittable DoFn
> ---------------------------------------------
>
>                 Key: BEAM-11996
>                 URL: https://issues.apache.org/jira/browse/BEAM-11996
>             Project: Beam
>          Issue Type: Improvement
>          Components: io-java-gcp
>            Reporter: Boyuan Zhang
>            Assignee: Miguel Anzo
>            Priority: P2
>          Time Spent: 3h 40m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to