cloud-fan commented on a change in pull request #30516:
URL: https://github.com/apache/spark/pull/30516#discussion_r532605473
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala
##########
@@ -1014,49 +1014,98 @@ class DateExpressionsSuite extends SparkFunSuite with
ExpressionEvalHelper {
}
test("creating values of DateType via make_date") {
- checkEvaluation(MakeDate(Literal(2013), Literal(7), Literal(15)),
Date.valueOf("2013-7-15"))
- checkEvaluation(MakeDate(Literal.create(null, IntegerType), Literal(7),
Literal(15)), null)
- checkEvaluation(MakeDate(Literal(2019), Literal.create(null, IntegerType),
Literal(19)), null)
- checkEvaluation(MakeDate(Literal(2019), Literal(7), Literal.create(null,
IntegerType)), null)
- checkEvaluation(MakeDate(Literal(Int.MaxValue), Literal(13), Literal(19)),
null)
- checkEvaluation(MakeDate(Literal(2019), Literal(13), Literal(19)), null)
- checkEvaluation(MakeDate(Literal(2019), Literal(7), Literal(32)), null)
+ Seq(true, false).foreach({ ansi =>
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> ansi.toString) {
+ checkEvaluation(MakeDate(Literal(2013), Literal(7), Literal(15)),
Date.valueOf("2013-7-15"))
+ checkEvaluation(MakeDate(Literal.create(null, IntegerType),
Literal(7), Literal(15)), null)
+ checkEvaluation(MakeDate(Literal(2019), Literal.create(null,
IntegerType), Literal(19)),
+ null)
+ checkEvaluation(MakeDate(Literal(2019), Literal(7),
Literal.create(null, IntegerType)),
+ null)
+ }
+ })
+
+ // ansi test
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
+
checkExceptionInExpression[DateTimeException](MakeDate(Literal(Int.MaxValue),
Literal(13),
+ Literal(19)), EmptyRow, "Invalid value for Year")
+ checkExceptionInExpression[DateTimeException](MakeDate(Literal(2019),
+ Literal(13), Literal(19)), EmptyRow, "Invalid value for Month")
+ checkExceptionInExpression[DateTimeException](MakeDate(Literal(2019),
Literal(7),
+ Literal(32)), EmptyRow, "Invalid value for Day")
+ }
+
+ // non-ansi test
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") {
+ checkEvaluation(MakeDate(Literal(Int.MaxValue), Literal(13),
Literal(19)), null)
+ checkEvaluation(MakeDate(Literal(2019), Literal(13), Literal(19)), null)
+ checkEvaluation(MakeDate(Literal(2019), Literal(7), Literal(32)), null)
+ }
}
test("creating values of TimestampType via make_timestamp") {
- var makeTimestampExpr = MakeTimestamp(
- Literal(2013), Literal(7), Literal(15), Literal(8), Literal(15),
- Literal(Decimal(BigDecimal(23.5), 8, 6)),
Some(Literal(ZoneId.systemDefault().getId)))
val expected = Timestamp.valueOf("2013-7-15 8:15:23.5")
- checkEvaluation(makeTimestampExpr, expected)
- checkEvaluation(makeTimestampExpr.copy(timezone = None), expected)
-
- checkEvaluation(makeTimestampExpr.copy(year = Literal.create(null,
IntegerType)), null)
- checkEvaluation(makeTimestampExpr.copy(year = Literal(Int.MaxValue)), null)
-
- checkEvaluation(makeTimestampExpr.copy(month = Literal.create(null,
IntegerType)), null)
- checkEvaluation(makeTimestampExpr.copy(month = Literal(13)), null)
-
- checkEvaluation(makeTimestampExpr.copy(day = Literal.create(null,
IntegerType)), null)
- checkEvaluation(makeTimestampExpr.copy(day = Literal(32)), null)
- checkEvaluation(makeTimestampExpr.copy(hour = Literal.create(null,
IntegerType)), null)
- checkEvaluation(makeTimestampExpr.copy(hour = Literal(25)), null)
+ Seq(true, false).foreach { ansi =>
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> ansi.toString) {
+ var makeTimestampExpr = MakeTimestamp(
+ Literal(2013), Literal(7), Literal(15), Literal(8), Literal(15),
+ Literal(Decimal(BigDecimal(23.5), 8, 6)),
Some(Literal(ZoneId.systemDefault().getId)))
+ checkEvaluation(makeTimestampExpr, expected)
+ checkEvaluation(makeTimestampExpr.copy(year = Literal.create(null,
IntegerType)), null)
+ checkEvaluation(makeTimestampExpr.copy(month = Literal.create(null,
IntegerType)), null)
+ checkEvaluation(makeTimestampExpr.copy(day = Literal.create(null,
IntegerType)), null)
+ checkEvaluation(makeTimestampExpr.copy(hour = Literal.create(null,
IntegerType)), null)
+ checkEvaluation(makeTimestampExpr.copy(min = Literal.create(null,
IntegerType)), null)
+ checkEvaluation(makeTimestampExpr.copy(sec = Literal.create(null,
DecimalType(8, 6))), null)
+ checkEvaluation(makeTimestampExpr.copy(timezone = None), expected)
+
+ Seq(
+ (makeTimestampExpr.copy(year = Literal(Int.MaxValue)), null,
+ "Invalid value for Year"),
+ (makeTimestampExpr.copy(month = Literal(13)), null, "Invalid value
for Month"),
+ (makeTimestampExpr.copy(day = Literal(32)), null, "Invalid value for
Day"),
+ (makeTimestampExpr.copy(hour = Literal(25)), null, "Invalid value
for Hour"),
+ (makeTimestampExpr.copy(min = Literal(65)), null, "Invalid value for
Min"),
+ (makeTimestampExpr.copy(sec = Literal(Decimal(
+ BigDecimal(70.0), 8, 6))), null, "Invalid value for Second")
+ ).foreach { entry =>
+ if (ansi) {
+ checkExceptionInExpression[DateTimeException](entry._1, EmptyRow,
entry._3)
+ } else {
+ checkEvaluation(entry._1, entry._2)
Review comment:
`entry._2` is always null. I think we only need `Seq[Tuple2]` not
`Seq[Tuple3]`. Here we can just write `checkEvaluation(entry._1, null)`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]