hanover-fiste commented on a change in pull request #31965:
URL: https://github.com/apache/spark/pull/31965#discussion_r602119395
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JDBCRelation.scala
##########
@@ -118,13 +119,28 @@ private[sql] object JDBCRelation extends Logging {
s"Upper bound: ${boundValueToString(upperBound)}.")
upperBound - lowerBound
}
- // Overflow and silliness can happen if you subtract then divide.
- // Here we get a little roundoff, but that's (hopefully) OK.
- val stride: Long = upperBound / numPartitions - lowerBound / numPartitions
+
+ // Overflow can happen if you subtract then divide. For example:
+ // (Long.MaxValue - Long.MinValue) / (numPartitions - 2).
+ // Also, using fixed-point decimals here to avoid possible inaccuracy from
floating point.
+ val strideUpperCalculation = (upperBound / BigDecimal(numPartitions))
+ .setScale(18, RoundingMode.HALF_EVEN)
+ val strideLowerCalculation = (lowerBound / BigDecimal(numPartitions))
Review comment:
Changed to the suggested name.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]