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

    https://github.com/apache/spark/pull/6981#discussion_r34369375
  
    --- 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 --
    
    see my comment


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