【发布时间】:2021-06-15 23:56:51
【问题描述】:
每当我将 Dataframe 写入 ORC 时,时间戳字段的时区都不正确。 这是我的代码 -
// setting the timezone
val schema = List(
StructField("name", StringType),
StructField("date", TimestampType)
)
val data = Seq(
Row("test", java.sql.Timestamp.valueOf("2021-03-15 10:10:10.0"))
)
val df = spark.createDataFrame(
spark.sparkContext.parallelize(data),
StructType(schema)
)
// changing the timezone
spark.conf.set("spark.sql.session.timeZone", "MDT")
// value of the df has changed accordingly
df.show // prints 2021-03-15 08:10:10
// writing to orc
df.write.mode(SaveMode.Overwrite).format("orc").save("/tmp/dateTest.orc/")
ORC 文件中的值为 2021-03-15 10:10:10.0。
有没有办法控制作者的时区?我在这里错过了什么吗? 提前致谢!
【问题讨论】:
-
怎么知道ORC文件中的值为
10:10:10?你是用 Spark 还是其他东西读的? -
@mck 使用 orc-tools 打开它
-
您可能希望将 JVM 时区更改为 MDT。见this answer
-
@mck 试过了,但没有帮助.. 尝试设置所有这些参数和写作。然后我尝试重新创建 HiveContext,但也得到了相同的结果
标签: apache-spark apache-spark-sql timezone orc