获取 Spark SQL date_format 和一年中的一周之间的日期周



一个非常简单的:

SELECT  date_format("2018-01-14", "w"), weekofyear("2018-01-14")

给:

3, 2

它们都应该返回 2,如何正确配置区域设置?

(环境user.country = fr user.lang = FR(

我可以在 Spark 一年中的一周代码源代码中看到一周从星期一开始。

从版本 2.2.1 开始(但也在当前的 master 分支上(,date_formatDateFormatClass 中定义,而 又使用 DateTimeUtils#newDateFormat ,不幸的是,它使用硬编码Locale.US ,让您没有配置其行为的选项。

def newDateFormat(formatString: String, timeZone: TimeZone): DateFormat = {
  val sdf = new SimpleDateFormat(formatString, Locale.US)
  sdf.setTimeZone(timeZone)
  // Enable strict parsing, if the input date/format is invalid, it will throw an exception.
  // e.g. to parse invalid date '2016-13-12', or '2016-01-12' with  invalid format 'yyyy-aa-dd',
  // an exception will be throwed.
  sdf.setLenient(false)
  sdf
}

所以看起来这两者注定会有不同的行为。也许您可能想看看他们的错误存储库,并可能为此提交票证。

最新更新