Github user setjet commented on a diff in the pull request: https://github.com/apache/spark/pull/18080#discussion_r118820456 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala --- @@ -402,23 +402,40 @@ case class DayOfMonth(child: Expression) extends UnaryExpression with ImplicitCa } } +// scalastyle:off line.size.limit @ExpressionDescription( - usage = "_FUNC_(date) - Returns the week of the year of the given date.", + usage = "_FUNC_(date[, format]) - Returns the week of the year of the given date. Defaults to ISO 8601 standard, but can be gregorian specific", extended = """ Examples: > SELECT _FUNC_('2008-02-20'); 8 + > SELECT _FUNC_('2017-01-01', 'gregorian'); + 1 + > SELECT _FUNC_('2017-01-01', 'iso'); + 52 + > SELECT _FUNC_('2017-01-01'); + 52 """) -case class WeekOfYear(child: Expression) extends UnaryExpression with ImplicitCastInputTypes { +// scalastyle:on line.size.limit +case class WeekOfYear(child: Expression, format: Expression) extends + UnaryExpression with ImplicitCastInputTypes { + + def this(child: Expression) = { + this(child, Literal("iso")) + } override def inputTypes: Seq[AbstractDataType] = Seq(DateType) override def dataType: DataType = IntegerType + @transient private lazy val minimalDays = { + if ("gregorian".equalsIgnoreCase(format.toString)) 1 else 4 --- End diff -- I did a bit of research, and there seem to be no other formats. However, some systems (such as MySQL and Java), allow the first day of the week to be defined as well. Some countries in the middle east have a week on Friday/Saturday, or even Thursday/Friday. I will update the PR to allow users to override the first day of the week, as well as specify how the first week is defined (1 iso standard: week with more than half of the days, i.e. Thursday in a Monday-Sunday week. 2 gregorian: week with first day of the new year)
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org