boyuanzz commented on a change in pull request #11715:
URL: https://github.com/apache/beam/pull/11715#discussion_r428343813
##########
File path:
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/splittabledofn/OffsetRangeTracker.java
##########
@@ -120,13 +136,27 @@ public String toString() {
public Progress getProgress() {
// If we have never attempted an offset, we return the length of the
entire range as work
// remaining.
+ // Convert to BigDecimal in computation to prevent overflow, which may
result in loss of
+ // precision.
if (lastAttemptedOffset == null) {
- return Progress.from(0, range.getTo() - range.getFrom());
+ return Progress.from(
+ 0,
+ BigDecimal.valueOf(range.getTo())
+ .subtract(BigDecimal.valueOf(range.getFrom()),
MathContext.DECIMAL128)
+ .doubleValue());
}
// Compute the amount of work remaining from where we are to where we are
attempting to get to
// with a minimum of zero in case we have claimed beyond the end of the
range.
- long workRemaining = Math.max(range.getTo() - lastAttemptedOffset, 0);
- return Progress.from(range.getTo() - range.getFrom() - workRemaining,
workRemaining);
+ BigDecimal workRemaining =
+ BigDecimal.valueOf(range.getTo())
+ .subtract(BigDecimal.valueOf(lastAttemptedOffset),
MathContext.DECIMAL128)
+ .max(BigDecimal.ZERO);
+ BigDecimal wholeWork =
Review comment:
Done. Thanks!
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]