开发者社区> 问答> 正文

E-MapReduce kSpark + OSS是什么?



Spark + OSS



Spark 接入 OSS


当前E-MapReduce支持 MetaService服务,支持用户在E-MapReduce环境免AK访问OSS数据源。旧的显式写AK和Endpoint方式也支持,但需要注意OSS Endpoint请使用内网域名,所有的Endpoint可以参考 OSS Endpoint
下面这个例子演示了Spark如何免AK从OSS中读入数据,并将处理完的数据写回到OSS 中。

  1. [backcolor=transparent]    val conf [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]SparkConf[backcolor=transparent]().[backcolor=transparent]setAppName[backcolor=transparent]([backcolor=transparent]"Test OSS"[backcolor=transparent])
  2. [backcolor=transparent]    val sc [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]SparkContext[backcolor=transparent]([backcolor=transparent]conf[backcolor=transparent])
  3. [backcolor=transparent]    val pathIn [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]"oss://bucket/path/to/read"
  4. [backcolor=transparent]    val inputData [backcolor=transparent]=[backcolor=transparent] sc[backcolor=transparent].[backcolor=transparent]textFile[backcolor=transparent]([backcolor=transparent]pathIn[backcolor=transparent])
  5. [backcolor=transparent]    val cnt [backcolor=transparent]=[backcolor=transparent] inputData[backcolor=transparent].[backcolor=transparent]count
  6. [backcolor=transparent]    println[backcolor=transparent]([backcolor=transparent]s[backcolor=transparent]"count: $cnt"[backcolor=transparent])
  7. [backcolor=transparent]    val outputPath [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]"oss://bucket/path/to/write"
  8. [backcolor=transparent]    val outpuData [backcolor=transparent]=[backcolor=transparent] inputData[backcolor=transparent].[backcolor=transparent]map[backcolor=transparent]([backcolor=transparent]e [backcolor=transparent]=>[backcolor=transparent] s[backcolor=transparent]"$e has been processed."[backcolor=transparent])
  9. [backcolor=transparent]    outpuData[backcolor=transparent].[backcolor=transparent]saveAsTextFile[backcolor=transparent]([backcolor=transparent]outputPath[backcolor=transparent])


附录


示例代码请看:

展开
收起
nicenelly 2017-10-27 16:03:03 1848 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
OSS运维进阶实战手册 立即下载
《OSS运维基础实战手册》 立即下载
OSS运维基础实战手册 立即下载