Pyspark:输入Pyspark列中存在空值的当前日期(历元)

Pyspark:输入Pyspark列中存在空值的当前日期(历元),pyspark,Pyspark,我有一个pyspark数据帧df1 id account created_date 1 A-111 1487384387 2 B-222 3 C-333 4 D-444 1372873827 我想填充当前系统时间戳(历元),其中曾经创建的\u日期为空。我在下面试过了 current_date = unix_timestamp(current_timestamp())

我有一个pyspark数据帧df1

id      account        created_date
1       A-111          1487384387
2       B-222          
3       C-333
4       D-444          1372873827
我想填充当前系统时间戳(历元),其中曾经创建的\u日期为空。我在下面试过了

current_date = unix_timestamp(current_timestamp()) * 1000
df1 = df1.na.fill({'created_date': current_date})   
但是获取列中的错误是不可编辑的。如何实现这一点

使用
cast(“long”)
当前时间戳()
转换为历元时间戳。
coalesce
功能可用于替换空值

from pyspark.sql.functions import current_timestamp, coalesce

df.withColumn('created_date', coalesce('created_date', 
        current_timestamp().cast("long"))).show()

+---+-------+------------+                                                      
| id|account|created_date|
+---+-------+------------+
|  1|  A-111|  1487384387|
|  2|  B-222|  1604798619|
|  3|  C-333|  1604798619|
|  4|  D-444|  1372873827|
+---+-------+------------+