简体   繁体   English

spark-shell - 无法访问jar中的java函数

[英]spark-shell - Not able to access java functions in jars

I have started exploring spark 2 days back. 我已经开始探索火花2天了。 So I am pretty new to it. 所以我对它很新。 My use case is around accessing a java function present in an external jar in my scala code which I am writing in spark-shell. 我的用例是在我的scala代码中访问外部jar中存在的java函数,我在spark-shell中编写。 But I think I am not loading my jar properly. 但我想我没有正确加载我的罐子。 Here is what I am doing 这就是我在做的事情

spark-shell --master local[2] --jars pathToJarsWithComma --conf="spark.driver.extraClassPath=pathToJarsWithColon" --conf="spark.executor.extraClassPath=pathToJarsWithColon"

This is how I launch my spark-shell with all the required jars being passed. 这就是我启动所有必需罐子的火花壳的方法。 And whenever I am trying to call the java static function like : 每当我试图调用java静态函数时:

rdd1.collect.foreach(a=>MyClass.myfuncttion(a))

I am getting error as : 我收到的错误是:

<console>:26: error: not found: value MyClass

I want to know if my understanding is correct. 我想知道我的理解是否正确。 Can we use java functions in spark by loading external jars. 我们可以通过加载外部jar来在spark中使用java函数。 If yes, then what I am doing wrong here. 如果是,那么我在这里做错了。 Please guide. 请指导。

We can load java functions in Spark by loading external jars. 我们可以通过加载外部jar来加载Spark中的java函数。 I am not sure whether you need the confs you added at the end to make this work. 我不确定你是否需要你在最后添加的confs来完成这项工作。 For me, I tried out the following to test loading a jar in a spark shell. 对我来说,我尝试了以下测试来加载火花壳中的罐子。

./bin/spark-shell --master <spark url>  --jars /home/SparkBench/Terasort/target/jars/guava-19.0-rc2.jar

After that in the shell, I tried to access a field from a class in the jar. 在shell之后,我尝试从jar中的类访问一个字段。

scala> import com.google.common.primitives.UnsignedBytes
import com.google.common.primitives.UnsignedBytes
scala> UnsignedBytes.MAX_POWER_OF_TWO
res0: Byte = -128

As you can see, I was able to access fields from the external jar. 如您所见,我能够从外部jar访问字段。 You can also test out whether you can access the Class by a simple field from it. 您还可以测试是否可以通过一个简单的字段访问Class。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM