Github user tarekauel commented on a diff in the pull request:
https://github.com/apache/spark/pull/6981#discussion_r34337937
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/DatetimeExpressionsSuite.scala ---
@@ -45,4 +48,121 @@ class DatetimeExpressionsSuite extends QueryTest {
0).getTime - System.currentTimeMillis()) < 5000)
}
+
+
+ val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+ val sdfDate = new SimpleDateFormat("yyyy-MM-dd")
+ val d = new Date(sdf.parse("2015-04-08 13:10:15").getTime)
+ val ts = new Timestamp(sdf.parse("2013-04-08 13:10:15").getTime)
+
+
+ test("date format") {
+ val df = Seq((d, sdf.format(d), ts)).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(dateFormat("a", "y"), dateFormat("b", "y"),
dateFormat("c", "y")),
+ Row("2015", "2015", "2013"))
+
+ checkAnswer(
+ df.selectExpr("dateFormat(a, 'y')", "dateFormat(b, 'y')",
"dateFormat(c, 'y')"),
+ Row("2015", "2015", "2013"))
+ }
+
+ test("year") {
+ val df = Seq((d, sdfDate.format(d), ts)).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(year("a"), year("b"), year("c")),
+ Row(2015, 2015, 2013))
+
+ checkAnswer(
+ df.selectExpr("year(a)", "year(b)", "year(c)"),
+ Row(2015, 2015, 2013))
+ }
+
+ test("quarter") {
+ val ts = new Timestamp(sdf.parse("2013-11-08 13:10:15").getTime)
+
+ val df = Seq((d, sdfDate.format(d), ts)).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(quarter("a"), quarter("b"), quarter("c")),
+ Row(2, 2, 4))
+
+ checkAnswer(
+ df.selectExpr("quarter(a)", "quarter(b)", "quarter(c)"),
+ Row(2, 2, 4))
+ }
+
+ test("month") {
+ val df = Seq((d, sdfDate.format(d), ts)).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(month("a"), month("b"), month("c")),
+ Row(4, 4, 4))
+
+ checkAnswer(
+ df.selectExpr("month(a)", "month(b)", "month(c)"),
+ Row(4, 4, 4))
+ }
+
+ test("day") {
+ val df = Seq((d, sdfDate.format(d), ts)).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(day("a"), day("b"), day("c")),
+ Row(8, 8, 8))
+
+ checkAnswer(
+ df.selectExpr("day(a)", "day(b)", "day(c)"),
+ Row(8, 8, 8))
+ }
+
+ test("hour") {
+ val df = Seq((d, sdf.format(d), ts)).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(hour("a"), hour("b"), hour("c")),
+ Row(0, 13, 13))
+
+ checkAnswer(
+ df.selectExpr("hour(a)", "hour(b)", "hour(c)"),
+ Row(0, 13, 13))
+ }
+
+ test("minute") {
+ val df = Seq((d, sdf.format(d), ts)).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(minute("a"), minute("b"), minute("c")),
+ Row(0, 10, 10))
+
+ checkAnswer(
+ df.selectExpr("minute(a)", "minute(b)", "minute(c)"),
+ Row(0, 10, 10))
+ }
+
+ test("second") {
+ val df = Seq((d, sdf.format(d), ts)).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(second("a"), second("b"), second("c")),
+ Row(0, 15, 15))
+
+ checkAnswer(
+ df.selectExpr("second(a)", "second(b)", "second(c)"),
+ Row(0, 15, 15))
--- End diff --
This test crashes because of
```
== Analyzed Logical Plan ==
second(a): int, second(b): int, second(c): int
Project [second(CAST(a#101, TimestampType)) AS
second(a)#104,second(CAST(b#102, TimestampType)) AS second(b)#105,second(c#103)
AS second(c)#106]
Project [_1#98 AS a#101,_2#99 AS b#102,_3#100 AS c#103]
LocalRelation [_1#98,_2#99,_3#100], [[16533,2015-04-08
13:10:15,1365451815000000]]
[...]
java.lang.ClassCastException: java.lang.Long cannot be cast to
java.lang.Integer
java.lang.ClassCastException: java.lang.Long cannot be cast to
java.lang.Integer
at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:106)
at org.apache.spark.sql.Row$class.getInt(Row.scala:214)
at
org.apache.spark.sql.catalyst.InternalRow.getInt(InternalRow.scala:28)
```
I'm still investigating it. Has someone an idea what the problem might be?
---
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]