在我的 Spark 应用程序中,我必须拆分时间和数据并将它们存储在单独的列中,如下所示:
val df5=df4.withColumn("read_date",date_format(df4.col("date"), "yyyy-MM-dd")).withColumn("read_time",date_format(df4.col("date"), "HH:mm:ss")).drop("date")
该命令将分割数据和时间
------------+-------------
2012-01-12 00:06:00
------------+-------------
但将这两个字段创建为字符串。所以我必须要.cast("date")
对于日期,但是时间列使用什么数据类型?
如果我使用像.cast("timestamp")
它将把当前服务器日期与时间结合起来。当我们要在 Power BI 中可视化数据时,您认为将时间存储为字符串是正确的方法吗?
Spark 中没有数据类型来保存“HH:mm:ss”值。相反,您可以使用 hour()、min() 和 Second() 函数分别表示值。
所有这些函数都返回int types.
hour(string date) -- Returns the hour of the timestamp: hour('2009-07-30 12:58:59') = 12, hour('12:58:59') = 12.
minute(string date) -- Returns the minute of the timestamp.
second(string date) -- Returns the second of the timestamp.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)