将sparkDataframe写入orc时给出了错误的时区

qyswt5oh  于 2021-07-14  发布在  Spark
关注(0)|答案(1)|浏览(373)

每当我将Dataframe写入orc时,时间戳字段的时区就不正确。这是我的密码-

  1. // setting the timezone
  2. val schema = List(
  3. StructField("name", StringType),
  4. StructField("date", TimestampType)
  5. )
  6. val data = Seq(
  7. Row("test", java.sql.Timestamp.valueOf("2021-03-15 10:10:10.0"))
  8. )
  9. val df = spark.createDataFrame(
  10. spark.sparkContext.parallelize(data),
  11. StructType(schema)
  12. )
  13. // changing the timezone
  14. spark.conf.set("spark.sql.session.timeZone", "MDT")
  15. // value of the df has changed accordingly
  16. df.show // prints 2021-03-15 08:10:10
  17. // writing to orc
  18. df.write.mode(SaveMode.Overwrite).format("orc").save("/tmp/dateTest.orc/")

orc文件中的值为2021-03-15 10:10:10.0。
有没有办法控制作者的时区?我是不是漏了什么?提前谢谢!

50pmv0ei

50pmv0ei1#

所以经过大量调查,这是orc不支持的(atm)。不过,csv支持它。

相关问题