【发布时间】:2019-07-23 23:33:35
【问题描述】:
如何创建像 https://docs.databricks.com/spark/latest/spark-sql/language-manual/create-function.html#create-function 这样的函数但在 python 中定义函数?
我已经做过类似的事情了:
from pyspark.sql.types import IntegerType
def relative_month(input_date):
if input_date is not None:
return ((input_date.month + 2) % 6)+1
else:
return None
_ = spark.udf.register("relative_month", relative_month, IntegerType())
但是这个 UDF 只适用于运行这段代码的笔记本。
我想使用 SQL 语法来注册函数,因为我将有一些用户通过 SQL 客户端使用 databricks,他们也需要这些函数。
在 Databricks 文档中说我可以定义资源:
: (JAR|FILE|ARCHIVE) file_uri
我需要创建一个 .py 文件并将其放在我的 databricks 集群中的某个位置吗?
【问题讨论】:
标签: python apache-spark databricks