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

    https://github.com/apache/spark/pull/8049#discussion_r36664105
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala
 ---
    @@ -410,6 +410,12 @@ private[sql] object DataSourceStrategy extends 
Strategy with Logging {
           case _ => None
         }
     
    -    filters.flatMap(translate)
    +    filters.map(eliminateCastOnAttribute(_)).flatMap(translate)
    +  }
    +
    +  private def eliminateCastOnAttribute(expression: Expression): Expression 
= {
    +    expression.transform {
    +      case Cast(a: Attribute, _) => a
    +    }
    --- End diff --
    
    I haven't successfully constructed a test case to prove it, but simply 
removing the casts here looks a little bit dangerous to me. For example, both 
`BinaryOperator` and logic in `ParquetFilters` assume that both branches of a 
binary expression should have the same data type.
    
    Instead of removing the casts, how about transposing them? Namely, 
converting
    
    ```
    expression.transform {
      case LessThan(Cast(a: Attribute, _), value) => 
        LessThan(a, Cast(value, a.dataType).eval())
    
      case LessThan(value, Cast(a: Attribute, _)) => 
        LessThan(Cast(value, a.dataType).eval(), a)
    
      ...
    }
    ```
    
    In this way, we still ensure both branches have the same data type.


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