Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Wrapper for user-defined table function registration. This instance can be accessed by spark.udtf.
Syntax
# Access through SparkSession
spark.udtf
Methods
| Method | Description |
|---|---|
register(name, f) |
Registers a Python user-defined table function as a SQL table function. |
Notes
Spark uses the return type of the given user-defined table function as the return type of the registered function.
To register a nondeterministic Python table function, first build a nondeterministic user-defined table function and then register it as a SQL function.
Examples
from pyspark.sql.functions import udtf
@udtf(returnType="c1: int, c2: int")
class PlusOne:
def eval(self, x: int):
yield x, x + 1
_ = spark.udtf.register(name="plus_one", f=PlusOne)
spark.sql("SELECT * FROM plus_one(1)").collect()
[Row(c1=1, c2=2)]
spark.sql("SELECT * FROM VALUES (0, 1), (1, 2) t(x, y), LATERAL plus_one(x)").collect()
[Row(x=0, y=1, c1=0, c2=1), Row(x=1, y=2, c1=1, c2=2)]