Can pyspark.sql.function be used in udf?

前端 未结 2 1383
没有蜡笔的小新
没有蜡笔的小新 2020-12-10 19:32

I define a function like

getDate = udf(lambda x : to_date(x))

When I use it in

df.select(getDate(\"time\")).show()
         


        
2条回答
  •  余生分开走
    2020-12-10 19:42

    Looking at error seems problem with sc as sc._jvm:'NoneType' object has no attribute '_jvm'

    Here sc is of NoneType.

    And there is no need to write udf for it, you can use directly:-

    import pyspark.sql.functions as F
    df.select(F.to_date(df.time)).show()
    

提交回复
热议问题