spark-submit command-line with --files

spark提交任务

bin/spark-submit --name  Test --class com.test.batch.modeltrainer.ModelTrainerMain \ 
  --master local --files /tmp/myobject.ser --verbose  /opt/test/lib/spark-test.jar 

程序引用

val serFile = SparkFiles.get("myobject.ser")

错误提示

Exception: 
Exception in thread "main" java.lang.NullPointerException 
  at org.apache.spark.SparkFiles$.getRootDirectory(SparkFiles.scala:37) 
  at org.apache.spark.SparkFiles$.get(SparkFiles.scala:31) 
  at com.test.batch.modeltrainer.ModelTrainerMain$.main(ModelTrainerMain.scala:37) 
  at com.test.batch.modeltrainer.ModelTrainerMain.main(ModelTrainerMain.scala) 
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
  at java.lang.reflect.Method.invoke(Method.java:606) 
  at org.apache.spark.deploy.SparkSubmit$.launch(SparkSubmit.scala:303) 
  at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:55) 
  at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala) 

解决:

SparkEnv is an internal class that is only meant to be used within Spark. Outside of Spark, it will be null because there are no executors or driver to start an environment for. Similarly, SparkFiles is meant to be used internally (though it's privacy settings should be modified to reflect that).

只能在spark内去引用,在executors或driver去引用,在算子内

sc.parallelize(1 to 100).map { i => SparkFiles.get("my.file") }.collect()

转载于:https://www.cnblogs.com/xiaoma0529/p/7068457.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值