【问题标题】:Timestamp converted to UTC while loading to parquet加载到镶木地板时时间戳转换为 UTC
【发布时间】:2021-03-22 05:11:32
【问题描述】:

我正在通过 spark 将数据加载到镶木地板。

dataFrame.write.parquet(path)

我的数据在写入 parquet 时有一个时间戳列,它实际上是将时间戳转换为 UTC 时区,然后存储。

实际时间 -------- 2020-10-21 00:00:00.000
UTC时间--------- 2020-10-21T05:30:00.000+05:30

我看到 spark conf 设置为 UTC 时区。spark.sql.session.timeZone 有什么办法可以关闭这种转换?

我想按原样加载时间戳而不将其转换为任何其他时区。我该怎么做?

【问题讨论】:

  • 你设置 spark.session.timezone 了吗?
  • 在我的集群中它设置为 UTC
  • 作为替代选项,您可以将其存储为long

标签: scala apache-spark timestamp parquet timestamp-with-timezone


【解决方案1】:

在此处查看文档:

https://databricks.com/blog/2020/07/22/a-comprehensive-look-at-dates-and-timestamps-in-apache-spark-3-0.html

将时间戳值写入 Parquet 等非文本数据源时,这些值只是没有时区信息的瞬间(如 UTC 中的时间戳)。如果您使用不同的会话时区写入和读取时间戳值,您可能会看到小时、分钟和秒字段的不同值,但它们是相同的具体时间。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-15
  • 2018-01-04
  • 1970-01-01
  • 2019-03-09
  • 2017-11-21
  • 1970-01-01
  • 2019-01-05
相关资源
最近更新 更多