gpt4 book ai didi

java - Spark (2.3+) 可从 PySpark/Python 调用的 Java 函数

转载 作者:行者123 更新时间:2023-12-01 19:49:57 25 4
gpt4 key购买 nike

关于 Spark 文档 2.3:

https://spark.apache.org/docs/latest/api/python/pyspark.sql.html#pyspark.sql.SQLContext.registerJavaFunction

registerJavaFunction(name, javaClassName, returnType=None)[source]

Register a Java user-defined function as a SQL function.

In addition to a name and the function itself, the return type can be >optionally specified. When the return type is not specified we would infer it via reflection.

Parameters:

name – name of the user-defined function

javaClassName – fully qualified name of java class

returnType – the return type of the registered Java function. The value can be either a pyspark.sql.types.DataType object or a DDL-formatted type string.

<小时/>

我的问题:

我想要一个包含大量 UDF 的库,适用于 Spark 2.3+,全部用 Java 编写,并且都可以通过 PySpark/Python 访问。

阅读我上面链接的文档,似乎在类和 Java UDF 函数之间存在一对一映射(可从 PySpark 中的 Spark-SQL 调用)。因此,如果我有 10 个 Java UDF 函数,那么我需要创建 10 个公共(public) Java 类,每个类有 1 个 UDF,以使它们可以从 PySpark/SQL 调用。

这是正确的吗?

我可以创建 1 个公共(public) Java 类并在 1 个类中放置多个不同的 UDF,并使所有 UDF 都可从 Spark 2.3 中的 PySpark 调用吗?

这篇文章没有提供任何Java示例代码来帮助解决我的问题。看起来一切都在 Scala 中。我想要全部用 Java 编写。我是否需要扩展类或实现接口(interface)才能在 Java 中执行此操作?任何从 PySpark-SQL 调用的示例 Java 代码的链接将不胜感激。

Spark: How to map Python with Scala or Java User Defined Functions?

最佳答案

So that if I have say 10 Java UDF functions then I need to create 10 public Java classes with 1 UDF per class to make them callable from PySpark/SQL.

Is this correct?

是的,没错。但是您可以:

关于java - Spark (2.3+) 可从 PySpark/Python 调用的 Java 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51797395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com