可以在udf中使用pyspark.sql.function吗? [英] Can pyspark.sql.function be used in udf?
本文介绍了可以在udf中使用pyspark.sql.function吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我定义了
getDate = udf(lambda x : to_date(x))
当我在其中使用
df.select(getDate("time")).show()
我遇到了
File ".../pyspark/sql/functions.py", in to_date
return Column(sc._jvm.functions.to_date(_to_java_column(col)))
AttributeError: 'NoneType' object has no attribute '_jvm'
这是否意味着我不能在自己的udf中使用pyspark.sql
.function?
Does that mean that I can not use pyspark.sql
.function in my own udf?
这不是一个具体的问题,我想知道为什么会这样.
This is not a specific question, I wonder why this happen.
推荐答案
pyspark.sql.functions
中的函数是JVM函数的包装,并且旨在在pyspark.sql.Column
上运行.您不能使用这些:
Functions from pyspark.sql.functions
are wrappers for JVM functions and are designed to operates on pyspark.sql.Column
. You cannot use these:
- 转换本地Python对象.他们使用
Column
并返回Column
. - 不能在工作者上使用它们,因为没有上下文可以对其进行评估.
- To transform local Python objects. They take
Column
and returnColumn
. - They cannot be used on the worker because there is no context in which they can be evaluated.
这篇关于可以在udf中使用pyspark.sql.function吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文