spark读取外部配置⽂件的⽅法spark读取外部配置⽂件的⽅法
spark-submit --files /tmp/fileName /tmp/test.jar
使⽤spark提交时使⽤--files参数,spark会将将本地的⽂件上传的hdfs,然后分发给每个executor
在程序中只需要使⽤⽂件名获取数据
val filePath ="fileName"
val props =newProperties()
props.load(newFileInputStream(filePath))
//发送到executor去执⾏
val rdd=sc.parallelize(0to3)
rdd.foreach(index=>
props.keySet().toArray().foreach(x=>println(x+"\t"+String)))
)
酉怎么读音
洋伞java的⽅式也是⼀样的,在这就不写了
3、--files ./config.properties收款收据格式
读⼀般⽂件:
val t: BufferedSource = scala.io.Source.fromFile("config.properties")
读配置⽂件:
/* val config = "config.properties"
val prop = new Properties()
prop.load(new FileInputStream(config))
val keyset = prop.keySet().toArray()
keyset.foreach(t=>println(t+" "+String)))*/
配置⽂件类加载测试配置采⽤ key=value 的
形式
client/cluster
采⽤ ⽅法;配合submit 参数–properties-file 上传配置⽂件; 配置⽂
件key value 以空格为分隔符
配置⽂件类加配置采⽤ key=value 的采⽤java.util.Properties ⽅法;配置⽂件打包到jar包⾥; 配置⽂件key value 以“=”为
载测试形式client/cluster分隔符
资源⽂件类加载测试普通⽂本格式,⾮key
value模式
client/cluster采⽤scala.io.Source.fromFile ⽅法;资源⽂件采⽤submit 参数–files 上传;
3月1日后个人收款码还能用吗资源⽂件类加载测试普通⽂本格式,⾮key
value模式
client/cluster采⽤scala.io.Source.fromFile和getResourceAsStream⽅法;资源⽂件打包到jar包中;
在/tmp下创建a⽂件,内容为:
this is a test data
this is a test data
this is a test data
this is a test data
this is a test data
this is a test data
说说看吧this is a test data
this is a test data
this is a test data
this is a test data
this is a test data
spark-shell --master yarn --files "/tmp/a"
可以看到a⽂件被上传到hdfs上了:
在代码中读取该⽂件,如下
可以看见这个⽂件在excutor被正确读取:且在两个excutor上分别执⾏,⼀个打印了22⾏,⼀个打印11⾏,原⽂件总共11⾏;上述rdd 公有三个元素,每个元素遍历时打印⼀遍,总共迷茫的生活
3*11=33
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论