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

    https://github.com/apache/spark/pull/11809#discussion_r56867675
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/patterns.scala
 ---
    @@ -202,3 +202,25 @@ object Unions {
         }
       }
     }
    +
    +/**
    + * A pattern that finds the original expression from a sequence of casts.
    + */
    +object Casts {
    +  def unapply(expr: Expression): Option[Attribute] = expr match {
    +    case c: Cast => collectCasts(expr)
    +    case _ => None
    +  }
    +
    +  private def collectCasts(e: Expression): Option[Attribute] = {
    +    if (e.isInstanceOf[Cast]) {
    +      collectCasts(e.children(0))
    +    } else {
    +      if (e.isInstanceOf[Attribute]) {
    +        Some(e.asInstanceOf[Attribute])
    --- End diff --
    
    Any time you see `isInstanceOf` / `asInstanceOf` you might want to be using 
matching instead...
    
    ```scala
    e match {
      case a: Attribute => Some(a)
      case Cast(e, _) => Some(collectCasts(e))
      case _ => None
    }
    ```


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