Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18364#discussion_r123588431
  
    --- 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))
     
    -        val expandedPlan =
    -          Filter(filterExpr,
    +          val replacedPlan = p transformExpressions {
    +            case t: TimeWindow => windowAttr
    +          }
    +
    +          // For backwards compatibility we add a filter to filter out 
nulls
    +          val filterExpr = IsNotNull(window.timeColumn)
    +
    +          replacedPlan.withNewChildren(Filter(filterExpr,
    +            Project(windowStruct +: child.output, child)) :: Nil)
    +        } else {
    +
    --- End diff --
    
    nit: no blank line


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to