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

    https://github.com/apache/spark/pull/17174#discussion_r104401305
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
 ---
    @@ -324,14 +324,22 @@ object TypeCoercion {
           // We should cast all relative timestamp/date/string comparison into 
string comparisons
           // This behaves as a user would expect because timestamp strings 
sort lexicographically.
           // i.e. TimeStamp(2013-01-01 00:00 ...) < "2014" = true
    -      case p @ BinaryComparison(left @ StringType(), right @ DateType()) =>
    -        p.makeCopy(Array(left, Cast(right, StringType)))
    -      case p @ BinaryComparison(left @ DateType(), right @ StringType()) =>
    -        p.makeCopy(Array(Cast(left, StringType), right))
    -      case p @ BinaryComparison(left @ StringType(), right @ 
TimestampType()) =>
    -        p.makeCopy(Array(left, Cast(right, StringType)))
    -      case p @ BinaryComparison(left @ TimestampType(), right @ 
StringType()) =>
    -        p.makeCopy(Array(Cast(left, StringType), right))
    +      // If StringType is foldable then we need to cast String to Date or 
Timestamp type
    +      // which would give order of magnitude performance gain as well as 
preserve the behavior
    +      // achieved by expressed above
    +      // TimeStamp(2013-01-01 00:00 ...) < Cast( "2014" as timestamp) = 
true
    +      case p @ BinaryComparison(left @ StringType(), right) if 
dateOrTimestampType(right) =>
    +        if (left.foldable) {
    +          p.makeCopy(Array(Cast(left, right.dataType), right))
    --- End diff --
    
    You are changing the semantics of the comparison here. For example `'10' < 
current_timestamp` currently returns `true`, if we apply your PR it will return 
`null`. This is a breaking change, and I don't think we should do this.


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