gpt4 book ai didi

apache-spark - Spark 数据帧 : Convert bigint to timestamp

转载 作者:行者123 更新时间:2023-12-04 16:42:30 32 4
gpt4 key购买 nike

我有一个带有 bigint 列的数据框。如何在scala spark中将bigint列转换为时间戳

最佳答案

您可以使用 from_unixtime/to_timestamp spark中的函数转换Bigint列到 timestamp .

示例:

spark.sql("select timestamp(from_unixtime(1563853753,'yyyy-MM-dd HH:mm:ss')) as ts").show(false)
+-------------------+
|ts |
+-------------------+
|2019-07-22 22:49:13|
+-------------------+

(或)
spark.sql("select to_timestamp(1563853753) as ts").show(false)
+-------------------+
|ts |
+-------------------+
|2019-07-22 22:49:13|
+-------------------+

架构:
spark.sql("select to_timestamp(1563853753) as ts").printSchema
root
|-- ts: timestamp (nullable = false)

引用 this有关在 spark 中转换不同格式的时间戳的更多详细信息的链接。

关于apache-spark - Spark 数据帧 : Convert bigint to timestamp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57156200/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com