New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-27638][SQL]: Cast string to date/timestamp in binary comparisons with dates/timestamps #24567
[SPARK-27638][SQL]: Cast string to date/timestamp in binary comparisons with dates/timestamps #24567
Changes from 1 commit
e24514e
41a03dd
19ec071
ac82eb2
34b00e9
e63367c
c3e80f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,8 +123,8 @@ 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 (StringType, DateType) => Some(StringType) | ||
case (DateType, StringType) => Some(StringType) | ||
case (StringType, DateType) => Some(DateType) | ||
case (DateType, StringType) => Some(DateType) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this mean we always find the common type as date when any arbitrary strings are compared to any dates? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it there any issue in your opinion? |
||
case (StringType, TimestampType) => Some(StringType) | ||
case (TimestampType, StringType) => Some(StringType) | ||
case (StringType, NullType) => Some(StringType) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3024,6 +3024,20 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { | |
sql("reset") | ||
} | ||
} | ||
|
||
test("string date comparison") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, add test cases for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
spark.range(1).selectExpr("date '2000-01-01' as d").createOrReplaceTempView("t1") | ||
val result = Date.valueOf("2000-01-01") | ||
checkAnswer(sql("select * from t1 where d >= '2000'"), Row(result)) | ||
checkAnswer(sql("select * from t1 where d >= '2000-1'"), Row(result)) | ||
checkAnswer(sql("select * from t1 where d >= '2000-1-1'"), Row(result)) | ||
checkAnswer(sql("select * from t1 where d >= '2000-1-01'"), Row(result)) | ||
checkAnswer(sql("select * from t1 where d >= '2000-01-1'"), Row(result)) | ||
checkAnswer(sql("select * from t1 where d >= '2000-01-01'"), Row(result)) | ||
checkAnswer(sql("select * from t1 where d > '2000-01-01'"), Nil) | ||
checkAnswer(sql("select * from t1 where '2000' >= d"), Row(result)) | ||
checkAnswer(sql("select * from t1 where d > '2000-13'"), Nil) | ||
} | ||
} | ||
|
||
case class Foo(bar: Option[String]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks we should update this comments too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks for pointing it out