可以在udf中使用pyspark.sql.function吗? [英] Can pyspark.sql.function be used in udf?

查看:231
本文介绍了可以在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 return Column.
  • They cannot be used on the worker because there is no context in which they can be evaluated.

这篇关于可以在udf中使用pyspark.sql.function吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆