chongguang commented on a change in pull request #30807:
URL: https://github.com/apache/spark/pull/30807#discussion_r549664984



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
##########
@@ -1195,27 +1208,46 @@ case class NextDay(startDate: Expression, dayOfWeek: 
Expression)
     nullSafeCodeGen(ctx, ev, (sd, dowS) => {
       val dateTimeUtilClass = DateTimeUtils.getClass.getName.stripSuffix("$")
       val dayOfWeekTerm = ctx.freshName("dayOfWeek")
+      val failOnErrorTerm = ctx.freshName("failOnError")
       if (dayOfWeek.foldable) {
         val input = dayOfWeek.eval().asInstanceOf[UTF8String]
-        if ((input eq null) || DateTimeUtils.getDayOfWeekFromString(input) == 
-1) {
+        if (input eq null) {
+          s"""${ev.isNull} = true;"""
+        } else if (DateTimeUtils.getDayOfWeekFromString(input) == -1) {
+          val errMsg = input.replace(
+            UTF8String.fromString("""""""), UTF8String.fromString("""\""""))
           s"""
-             |${ev.isNull} = true;
-           """.stripMargin
+             |boolean $failOnErrorTerm = $failOnError;
+             |if ($failOnErrorTerm) {

Review comment:
       Maybe we can go modify the function 
`DateTimeUtils.getDayOfWeekFromString` to make it throw an exception instead of 
returning -1 and do some try-catch in `NextDay` ?
   
   From a spark point of view it is ok because the `getDayOfWeekFromString` is 
only used in the `NextDay` expression. But since the `getDayOfWeekFromString` 
function is not private, maybe users of spark are using it as well. And in that 
case the change would be breaking for them.




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

Reply via email to