美文网首页
spark读取外部配置文件的方法

spark读取外部配置文件的方法

作者: light01 | 来源:发表于2017-06-19 17:21 被阅读0次

问题:有时我们需要在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"+props.getProperty(x.toString)))

)

java的方式也是一样的,在这就不写了

相关文章

网友评论

      本文标题:spark读取外部配置文件的方法

      本文链接:https://www.haomeiwen.com/subject/cjfnqxtx.html