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

    https://github.com/apache/spark/pull/17174#discussion_r104481076
  
    --- 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 --
    
    Thanks for pointing that out.
    After applying the PR ` '10' < current_timestamp` does return `null` and 
its breaking the semantics.
    The fix to this issue is very important. We have seen order of magnitude 
performance difference if string is correctly casted to timestamp for Literals 
in SQL and most of these SQLs are generated using some BI tool.
    Any other suggestion to fix this issue? Shall i make it more restrictive so 
that null cases are better covered. i.e 
    `if( expr.foldable && expressed.eval( null ) !=null ) 
      cast to timestamp` 


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