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

    https://github.com/apache/spark/pull/18540#discussion_r130214960
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
 ---
    @@ -805,4 +806,27 @@ object TypeCoercion {
           Option(ret)
         }
       }
    +
    +  /**
    +   * Cast WindowFrame boundaries to the type they operate upon.
    +   */
    +  object WindowFrameCoercion extends Rule[LogicalPlan] {
    +    def apply(plan: LogicalPlan): LogicalPlan = plan resolveExpressions {
    +      case s @ WindowSpecDefinition(_, Seq(order), 
SpecifiedWindowFrame(RangeFrame, lower, upper))
    +        if order.resolved =>
    +        s.copy(frameSpecification = SpecifiedWindowFrame(
    +          RangeFrame,
    +          createBoundaryCast(lower, order.dataType),
    +          createBoundaryCast(upper, order.dataType)))
    +    }
    +
    +    private def createBoundaryCast(boundary: Expression, dt: DataType): 
Expression = {
    +      boundary match {
    +        case e: Expression if e.dataType != dt && Cast.canCast(e.dataType, 
dt) &&
    +          !e.isInstanceOf[SpecialFrameBoundary] =>
    --- End diff --
    
    Splitting `if` in the middle looks weird. How about?
    ```Scala
            case e: SpecialFrameBoundary => e
            case e: Expression if e.dataType != dt && Cast.canCast(e.dataType, 
dt) => Cast(e, dt)
            case _ => boundary
    ```


---
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]

Reply via email to