sunchao commented on a change in pull request #30807:
URL: https://github.com/apache/spark/pull/30807#discussion_r549835354
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
##########
@@ -1170,52 +1175,67 @@ case class LastDay(startDate: Expression)
group = "datetime_funcs",
since = "1.5.0")
// scalastyle:on line.size.limit
-case class NextDay(startDate: Expression, dayOfWeek: Expression)
+case class NextDay(startDate: Expression,
Review comment:
nit: indentation looks wrong here.
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
##########
@@ -1170,52 +1175,67 @@ case class LastDay(startDate: Expression)
group = "datetime_funcs",
since = "1.5.0")
// scalastyle:on line.size.limit
-case class NextDay(startDate: Expression, dayOfWeek: Expression)
+case class NextDay(startDate: Expression,
+ dayOfWeek: Expression,
+ failOnError: Boolean = SQLConf.get.ansiEnabled)
extends BinaryExpression with ImplicitCastInputTypes with NullIntolerant {
override def left: Expression = startDate
override def right: Expression = dayOfWeek
+ def this(left: Expression, right: Expression) = this(left, right,
SQLConf.get.ansiEnabled)
+
override def inputTypes: Seq[AbstractDataType] = Seq(DateType, StringType)
override def dataType: DataType = DateType
override def nullable: Boolean = true
override def nullSafeEval(start: Any, dayOfW: Any): Any = {
- val dow =
DateTimeUtils.getDayOfWeekFromString(dayOfW.asInstanceOf[UTF8String])
- if (dow == -1) {
- null
- } else {
+ try {
+ val dow =
DateTimeUtils.getDayOfWeekFromString(dayOfW.asInstanceOf[UTF8String])
val sd = start.asInstanceOf[Int]
DateTimeUtils.getNextDateForDayOfWeek(sd, dow)
+ } catch {
+ case e: IllegalArgumentException if !failOnError => null
+ }
+ }
+
+ private def nextDayGenCode(ev: ExprCode,
Review comment:
ditto
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
##########
@@ -1170,52 +1175,67 @@ case class LastDay(startDate: Expression)
group = "datetime_funcs",
since = "1.5.0")
// scalastyle:on line.size.limit
-case class NextDay(startDate: Expression, dayOfWeek: Expression)
+case class NextDay(startDate: Expression,
+ dayOfWeek: Expression,
+ failOnError: Boolean = SQLConf.get.ansiEnabled)
extends BinaryExpression with ImplicitCastInputTypes with NullIntolerant {
override def left: Expression = startDate
override def right: Expression = dayOfWeek
+ def this(left: Expression, right: Expression) = this(left, right,
SQLConf.get.ansiEnabled)
+
override def inputTypes: Seq[AbstractDataType] = Seq(DateType, StringType)
override def dataType: DataType = DateType
override def nullable: Boolean = true
override def nullSafeEval(start: Any, dayOfW: Any): Any = {
- val dow =
DateTimeUtils.getDayOfWeekFromString(dayOfW.asInstanceOf[UTF8String])
- if (dow == -1) {
- null
- } else {
+ try {
+ val dow =
DateTimeUtils.getDayOfWeekFromString(dayOfW.asInstanceOf[UTF8String])
val sd = start.asInstanceOf[Int]
DateTimeUtils.getNextDateForDayOfWeek(sd, dow)
+ } catch {
+ case e: IllegalArgumentException if !failOnError => null
Review comment:
nit: can replace variable `e` with underscore since it's unused
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
##########
@@ -1170,52 +1175,67 @@ case class LastDay(startDate: Expression)
group = "datetime_funcs",
since = "1.5.0")
// scalastyle:on line.size.limit
-case class NextDay(startDate: Expression, dayOfWeek: Expression)
+case class NextDay(startDate: Expression,
+ dayOfWeek: Expression,
+ failOnError: Boolean = SQLConf.get.ansiEnabled)
extends BinaryExpression with ImplicitCastInputTypes with NullIntolerant {
override def left: Expression = startDate
override def right: Expression = dayOfWeek
+ def this(left: Expression, right: Expression) = this(left, right,
SQLConf.get.ansiEnabled)
Review comment:
nit: is this useful given that `failOnError` already has a default value?
----------------------------------------------------------------
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]