【发布时间】:2022-08-11 23:34:59
【问题描述】:
我有以下用 Scala 编写的课程:
package com.ing.wbaa.spark.udf
class test() {
def hello = println(\"hello\")
def addInt( a:Int, b:Int ) : Int = {
var sum:Int = 0
sum = a + b
return sum
}
}
object test{
def main(argv: Array[String]): Unit = {
val app = new test()
app.hello;
app.addInt(1,1)
}
}
我正在尝试在 Jupyter 笔记本中访问 hello 方法。为此,我创建了上述类的 jar 文件并执行了以下操作:
pyspark --jars /home/path/of/jar/is/udf_2.12-0.1.0-SNAPSHOT.jar
当我跑步时
sc._jvm.com.ing.wbaa.spark.udf.Test.main()
我得到TypeError: \'JavaPackage\' object is not callable,当我尝试运行时
sc._jvm.com.ing.wbaa.spark.udf.Test.hello
我得到<py4j.java_gateway.JavaPackage object at 0x7fd86a95e850>
请有人告诉我如何在 jupyter notebook 中使用hello 或addInt 方法。谢谢
还
sc._jvm.com.ing.wbaa.spark.udf.Test.hello()
当它应该有测试类的调用hello函数时给出TypeError: \'JavaPackage\' object is not callable。
-
Pyspark 也可以定义 UDF。你真的需要 Scala 吗?另外,测试类是小写的,那么 Pyspark 是如何用大写导入的呢? Scala 类是否可以自行运行而没有错误?
-
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如它目前所写的那样,很难准确地说出你在问什么。
标签: python apache-spark pyspark py4j