相关疑难解决方法(0)

在Dataframes中将日期从String转换为Date格式

我试图使用to_date函数将一个String格式的列转换为Date格式,但是它返回的Null值.

df.createOrReplaceTempView("incidents")
spark.sql("select Date from incidents").show()

+----------+
|      Date|
+----------+
|08/26/2016|
|08/26/2016|
|08/26/2016|
|06/14/2016|

spark.sql("select to_date(Date) from incidents").show()

+---------------------------+
|to_date(CAST(Date AS DATE))|
 +---------------------------+
|                       null|
|                       null|
|                       null|
|                       null|
Run Code Online (Sandbox Code Playgroud)

Date列采用String格式:

 |-- Date: string (nullable = true)
Run Code Online (Sandbox Code Playgroud)

apache-spark apache-spark-sql

35
推荐指数
5
解决办法
12万
查看次数

标签 统计

apache-spark ×1

apache-spark-sql ×1