attilapiros commented on code in PR #59527:
URL: https://github.com/apache/spark/pull/59527#discussion_r4295858802
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowEvaluatorFactoryBase.scala:
##########
@@ -453,11 +453,13 @@ trait WindowEvaluatorFactoryBase {
if (frameType == RangeFrame) {
return Some(8)
}
- val w: Option[Int] = (lower, upper) match {
- case (CurrentRow, CurrentRow) => Some(1)
- case (IntegerLiteral(lo), IntegerLiteral(hi)) => Some(math.abs(hi - lo)
+ 1)
- case (CurrentRow, IntegerLiteral(hi)) => Some(math.abs(hi) + 1)
- case (IntegerLiteral(lo), CurrentRow) => Some(math.abs(lo) + 1)
+ // The offsets are Ints that may be as large as Int.MaxValue, so the width
must be computed
+ // in Long: `abs(hi) + 1` and `hi - lo` both overflow an Int for such
offsets.
+ val w: Option[Long] = (lower, upper) match {
+ case (CurrentRow, CurrentRow) => Some(1L)
+ case (IntegerLiteral(lo), IntegerLiteral(hi)) => Some(math.abs(hi.toLong
- lo.toLong) + 1)
+ case (CurrentRow, IntegerLiteral(hi)) => Some(math.abs(hi.toLong) + 1)
+ case (IntegerLiteral(lo), CurrentRow) => Some(math.abs(lo.toLong) + 1)
Review Comment:
```suggestion
case (IntegerLiteral(lo), CurrentRow) => Some(math.abs(lo) + 1.toLong)
```
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowEvaluatorFactoryBase.scala:
##########
@@ -453,11 +453,13 @@ trait WindowEvaluatorFactoryBase {
if (frameType == RangeFrame) {
return Some(8)
}
- val w: Option[Int] = (lower, upper) match {
- case (CurrentRow, CurrentRow) => Some(1)
- case (IntegerLiteral(lo), IntegerLiteral(hi)) => Some(math.abs(hi - lo)
+ 1)
- case (CurrentRow, IntegerLiteral(hi)) => Some(math.abs(hi) + 1)
- case (IntegerLiteral(lo), CurrentRow) => Some(math.abs(lo) + 1)
+ // The offsets are Ints that may be as large as Int.MaxValue, so the width
must be computed
+ // in Long: `abs(hi) + 1` and `hi - lo` both overflow an Int for such
offsets.
+ val w: Option[Long] = (lower, upper) match {
+ case (CurrentRow, CurrentRow) => Some(1L)
+ case (IntegerLiteral(lo), IntegerLiteral(hi)) => Some(math.abs(hi.toLong
- lo.toLong) + 1)
+ case (CurrentRow, IntegerLiteral(hi)) => Some(math.abs(hi.toLong) + 1)
Review Comment:
Casting 1 to `Long` prevents overflow on addition, which keeps
`math.abs(hi)` working safely:
```suggestion
case (CurrentRow, IntegerLiteral(hi)) => Some(math.abs(hi) + 1.toLong)
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]