Skip to content

Commit d35eb2f

Browse files
cloud-fangatorsmile
authored andcommitted
[SPARK-24168][SQL] WindowExec should not access SQLConf at executor side
## What changes were proposed in this pull request? This PR is extracted from #21190 , to make it easier to backport. `WindowExec#createBoundOrdering` is called on executor side, so we can't use `conf.sessionLocalTimezone` there. ## How was this patch tested? tested in #21190 Author: Wenchen Fan <[email protected]> Closes #21225 from cloud-fan/minor3. (cherry picked from commit e646ae6) Signed-off-by: gatorsmile <[email protected]>
1 parent 8509284 commit d35eb2f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowExec.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ case class WindowExec(
112112
*
113113
* @param frame to evaluate. This can either be a Row or Range frame.
114114
* @param bound with respect to the row.
115+
* @param timeZone the session local timezone for time related calculations.
115116
* @return a bound ordering object.
116117
*/
117-
private[this] def createBoundOrdering(frame: FrameType, bound: Expression): BoundOrdering = {
118+
private[this] def createBoundOrdering(
119+
frame: FrameType, bound: Expression, timeZone: String): BoundOrdering = {
118120
(frame, bound) match {
119121
case (RowFrame, CurrentRow) =>
120122
RowBoundOrdering(0)
@@ -144,7 +146,7 @@ case class WindowExec(
144146
val boundExpr = (expr.dataType, boundOffset.dataType) match {
145147
case (DateType, IntegerType) => DateAdd(expr, boundOffset)
146148
case (TimestampType, CalendarIntervalType) =>
147-
TimeAdd(expr, boundOffset, Some(conf.sessionLocalTimeZone))
149+
TimeAdd(expr, boundOffset, Some(timeZone))
148150
case (a, b) if a== b => Add(expr, boundOffset)
149151
}
150152
val bound = newMutableProjection(boundExpr :: Nil, child.output)
@@ -197,6 +199,7 @@ case class WindowExec(
197199

198200
// Map the groups to a (unbound) expression and frame factory pair.
199201
var numExpressions = 0
202+
val timeZone = conf.sessionLocalTimeZone
200203
framedFunctions.toSeq.map {
201204
case (key, (expressions, functionSeq)) =>
202205
val ordinal = numExpressions
@@ -237,7 +240,7 @@ case class WindowExec(
237240
new UnboundedPrecedingWindowFunctionFrame(
238241
target,
239242
processor,
240-
createBoundOrdering(frameType, upper))
243+
createBoundOrdering(frameType, upper, timeZone))
241244
}
242245

243246
// Shrinking Frame.
@@ -246,7 +249,7 @@ case class WindowExec(
246249
new UnboundedFollowingWindowFunctionFrame(
247250
target,
248251
processor,
249-
createBoundOrdering(frameType, lower))
252+
createBoundOrdering(frameType, lower, timeZone))
250253
}
251254

252255
// Moving Frame.
@@ -255,8 +258,8 @@ case class WindowExec(
255258
new SlidingWindowFunctionFrame(
256259
target,
257260
processor,
258-
createBoundOrdering(frameType, lower),
259-
createBoundOrdering(frameType, upper))
261+
createBoundOrdering(frameType, lower, timeZone),
262+
createBoundOrdering(frameType, upper, timeZone))
260263
}
261264
}
262265

0 commit comments

Comments
 (0)