Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/18364#discussion_r123588018
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
---
@@ -2562,37 +2563,63 @@ object TimeWindowing extends Rule[LogicalPlan] {
case a: Attribute => a.metadata
case _ => Metadata.empty
}
- val windowAttr =
- AttributeReference("window", window.dataType, metadata =
metadata)()
- val maxNumOverlapping = math.ceil(window.windowDuration * 1.0 /
window.slideDuration).toInt
- val windows = Seq.tabulate(maxNumOverlapping + 1) { i =>
- val windowId = Ceil((PreciseTimestamp(window.timeColumn) -
window.startTime) /
- window.slideDuration)
+ def getWindow(i: Int, maxNumOverlapping: Int): Expression = {
+ val division = (PreciseTimestampConversion(
+ window.timeColumn, TimestampType, LongType) -
window.startTime) / window.slideDuration
+ val ceil = Ceil(division)
+ // if the division is equal to the ceiling, our record is the
start of a window
+ val windowId = CaseWhen(Seq((ceil === division, ceil + 1)),
Some(ceil))
val windowStart = (windowId + i - maxNumOverlapping) *
- window.slideDuration + window.startTime
+ window.slideDuration + window.startTime
val windowEnd = windowStart + window.windowDuration
CreateNamedStruct(
- Literal(WINDOW_START) :: windowStart ::
- Literal(WINDOW_END) :: windowEnd :: Nil)
+ Literal(WINDOW_START) ::
+ PreciseTimestampConversion(windowStart, LongType,
TimestampType) ::
+ Literal(WINDOW_END) ::
+ PreciseTimestampConversion(windowEnd, LongType,
TimestampType) ::
+ Nil)
}
- val projections = windows.map(_ +: p.children.head.output)
+ val windowAttr = AttributeReference(
+ WINDOW_COL_NAME, window.dataType, metadata = metadata)()
- val filterExpr =
- window.timeColumn >= windowAttr.getField(WINDOW_START) &&
- window.timeColumn < windowAttr.getField(WINDOW_END)
+ if (window.windowDuration == window.slideDuration) {
+ val windowStruct = Alias(getWindow(0, 1), WINDOW_COL_NAME)(
+ exprId = windowAttr.exprId, explicitMetadata = Some(metadata))
--- End diff --
nit: Wrapping is off. Prefer to break at `=` and if you wrap args, wrap
all of them.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]