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

    https://github.com/apache/spark/pull/21008#discussion_r183067178
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala
 ---
    @@ -453,34 +453,45 @@ class DateExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
             MonthsBetween(
               Literal(new Timestamp(sdf.parse("1997-02-28 10:30:00").getTime)),
               Literal(new Timestamp(sdf.parse("1996-10-30 00:00:00").getTime)),
    -          timeZoneId),
    -        3.94959677)
    -      checkEvaluation(
    -        MonthsBetween(
    -          Literal(new Timestamp(sdf.parse("2015-01-30 11:52:00").getTime)),
    -          Literal(new Timestamp(sdf.parse("2015-01-30 11:50:00").getTime)),
    -          timeZoneId),
    -        0.0)
    +          Literal.TrueLiteral,
    +          timeZoneId = timeZoneId), 3.94959677)
           checkEvaluation(
             MonthsBetween(
    -          Literal(new Timestamp(sdf.parse("2015-01-31 00:00:00").getTime)),
    -          Literal(new Timestamp(sdf.parse("2015-03-31 22:00:00").getTime)),
    -          timeZoneId),
    -        -2.0)
    -      checkEvaluation(
    -        MonthsBetween(
    -          Literal(new Timestamp(sdf.parse("2015-03-31 22:00:00").getTime)),
    -          Literal(new Timestamp(sdf.parse("2015-02-28 00:00:00").getTime)),
    -          timeZoneId),
    -        1.0)
    +          Literal(new Timestamp(sdf.parse("1997-02-28 10:30:00").getTime)),
    +          Literal(new Timestamp(sdf.parse("1996-10-30 00:00:00").getTime)),
    +          Literal.FalseLiteral,
    +          timeZoneId = timeZoneId), 3.9495967741935485)
    +
    +      Seq(Literal.FalseLiteral, Literal.TrueLiteral). foreach { roundOff =>
    +        checkEvaluation(
    +          MonthsBetween(
    +            Literal(new Timestamp(sdf.parse("2015-01-30 
11:52:00").getTime)),
    +            Literal(new Timestamp(sdf.parse("2015-01-30 
11:50:00").getTime)),
    +            roundOff,
    +            timeZoneId = timeZoneId), 0.0)
    +        checkEvaluation(
    +          MonthsBetween(
    +            Literal(new Timestamp(sdf.parse("2015-01-31 
00:00:00").getTime)),
    +            Literal(new Timestamp(sdf.parse("2015-03-31 
22:00:00").getTime)),
    +            roundOff,
    +            timeZoneId = timeZoneId), -2.0)
    +        checkEvaluation(
    +          MonthsBetween(
    +            Literal(new Timestamp(sdf.parse("2015-03-31 
22:00:00").getTime)),
    +            Literal(new Timestamp(sdf.parse("2015-02-28 
00:00:00").getTime)),
    +            roundOff,
    +            timeZoneId = timeZoneId), 1.0)
    +      }
           val t = Literal(Timestamp.valueOf("2015-03-31 22:00:00"))
           val tnull = Literal.create(null, TimestampType)
    -      checkEvaluation(MonthsBetween(t, tnull, timeZoneId), null)
    -      checkEvaluation(MonthsBetween(tnull, t, timeZoneId), null)
    -      checkEvaluation(MonthsBetween(tnull, tnull, timeZoneId), null)
    +      checkEvaluation(MonthsBetween(t, tnull, Literal.TrueLiteral, 
timeZoneId = timeZoneId), null)
    +      checkEvaluation(MonthsBetween(tnull, t, Literal.TrueLiteral, 
timeZoneId = timeZoneId), null)
    +      checkEvaluation(
    +        MonthsBetween(tnull, tnull, Literal.TrueLiteral, timeZoneId = 
timeZoneId), null)
    --- End diff --
    
    it returns null, I added a test case for it, thanks.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to