-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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-22894][SQL] DateTimeOperations should accept SQL like string type #20067
Conversation
Test build #85351 has finished for PR 20067 at commit
|
LGTM |
@@ -2760,6 +2760,17 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { | |||
} | |||
} | |||
|
|||
test("SPARK-22894: DateTimeOperations should accept SQL like string type") { |
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.
Add it to #20061?
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.
Yes, I'll and it.
@@ -2760,6 +2760,17 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { | |||
} | |||
} | |||
|
|||
test("SPARK-22894: DateTimeOperations should accept SQL like string type") { | |||
val date = "2017-12-24" | |||
val str = sql(s"SELECT CAST('$date' as STRING) + interval 2 months 2 seconds") |
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.
So far, we issue an exception. What is the behavior of Hive?
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.
Hive doesn't accept string type:
hive> SELECT cast('2017-12-24' as date) + interval 2 day;
2017-12-26 00:00:00
hive> SELECT cast('2017-12-24' as timestamp) + interval 2 day;
2017-12-26 00:00:00
hive> SELECT cast('2017-12-24' as string) + interval 2 day;
FAILED: SemanticException Line 0:-1 Wrong arguments '2': No matching method for class org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPDTIPlus with (string, interval_day_time)
hive>
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.
But Spark was originally supported:
spark/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionSuite.scala
Line 1083 in bc0848b
ruleTest(dateTimeOperations, Add(str, interval), Cast(TimeAdd(str, interval), StringType)) |
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.
I saw the original PR https://github.com/apache/spark/pull/7754/files#r35821191
Maybe the SQL API should support it since we do support it in DataFrame APIs.
retest this please |
Test build #85387 has finished for PR 20067 at commit
|
checkAnswer(str, Row("2018-02-24 00:00:02") :: Nil) | ||
checkAnswer(dt, Row(Date.valueOf("2018-02-24")) :: Nil) | ||
checkAnswer(ts, Row(Timestamp.valueOf("2018-02-24 00:00:02")) :: Nil) | ||
} |
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.
Please get rid of this test case and merge them to #20061
LGTM Merged to master. |
What changes were proposed in this pull request?
DateTimeOperations
acceptStringType
, but:After this PR:
How was this patch tested?
unit tests