亚洲女同成aV人片在线观看|亚洲www啪成人一区二区麻豆|亚洲国产中日韩精品综合|亚洲国产成人精品一级片|亚洲无码在线视频免费

新聞中心

如何利用MapReduce將數據寫(xiě)入HDFS并創(chuàng )建文件?

摘要:MapR??educe是(shi)何利一個(gè)編程模型,用于處理和生成大數據集。將數據寫(xiě)在Hadoop分布式文件系統(HDFS)中創(chuàng )建文件并寫(xiě)入內容是創(chuàng )建MapReduce作業(yè)的一部分。通過(guò)使用Hadoop的文件文件系統API,可以在HDFS(?Д?)上創(chuàng )建文件并向其中寫(xiě)入數據。何利(li)

MapReduce是將數??據???寫(xiě)一種編程模型,用于處理和生成大數據集,創(chuàng )建HDFS(Hadoop Distributed File System)是文件一個(gè)分布式文件系統,用于存儲大數據,何利下面是將數據寫(xiě)一個(gè)使用MapReduce將數(//ω//)據寫(xiě)入HDFS的示例:

(圖片來(lái)源網(wǎng)絡(luò ),侵刪)

1、創(chuàng )建我們需要創(chuàng )建一個(gè)Java項目,文件并添加Hadoop相關(guān)的何利依賴(lài)庫,在項目的將數據寫(xiě)pom.xml文件中添加以下依賴(lài):

<depend??encies> <depende??ncy> <groupId>org.apache.hadoop</groupId> <artifactId>??;hadoopclient</artifactId( ?ヮ?)> <ver(′?_?`)sion&g(T_T)t;2.7.3</version> </dependency></dependenci??es>

2、編寫(xiě)一個(gè)MapReduce程序,創(chuàng )建實(shí)現將數據寫(xiě)入HDFS的功能,??以下是一個(gè)簡(jiǎn)單的示例:

import org.apache??.hadoop.conf.Configuration;im(′?ω?`)port org.apache.hadoop.fs.Pa???th;import org.apache.hadoop.io.IntWritable;import org.apache.??hadoop.io┐(′?`)┌.Text;import org.apache.h??adoop.mapreduce.Job;import org.apache.hadoop.mapreduce.Mapper;import org.apache.hadoop.mapreduce.Reducer;import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOu(′▽?zhuān)?tputFormat;import java.io.IOException;public class WriteToHDFS {  public static class Token??(′_`)izerMapper extends Mapper<Object, Text, Text, IntWritable> {  private final static IntWritable one = new IntWritable(1); private Text word = new Text(); public void map(Object key, Text value, Context context) throws IOException, InterruptedEx(′?`)ception {  String[ヾ(′▽?zhuān)??] tokens = value.toString().split("\s+&q??uo??t;); for (String token : tokens) {  word.set(token); context.wr??ite(word, one); } } } public static clヽ(′▽?zhuān)?ノasヾ(′▽?zhuān)??s IntSumReduceヽ(′ー`)ノr extends Reducer<Text, IntWritable, Text, IntWritable> {  private IntWrita(╬?益?)ble result = new IntWritable(); public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOE( ?ヮ?)xception, Int??erruptedException {  int sum = 0; for (IntWritable val : values) {  su??m += val.get(); } result.set(sum); context??.wrヾ(′ω`)?ite(key, result); } } public static void main(┐(′д`)┌String[] args) throws Exceptio(′▽?zhuān)?n {  Configuration conf = new Configuration(); Job job = Job.getInstance(conf, "write to HDFS"); job.setJarByClass(WriteToHDFS.class); job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumR??educer.clas(°o°)s); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.ad??dInputPath((//ω//)jo(?⊿?)b, new┐(′ー`)┌ Path(args[0])); FileOutputFormat.setO??utputPath(job, new Path(args[1])); System.exit(′▽?zhuān)?(job.waitForCompletion(true) ? 0 : 1); }}

3、編譯并打包Java項目,生成jar文件。

4、使用??Hadoop命令行工具運行MapReduce任務(wù),將數據寫(xiě)??入HDFS,假設我們已經(jīng)將輸入數據上傳到HDFS的/input目錄下,輸出目錄為/output,jar文件名為writetohdfs?.jar,則運行以下命令:

hadoop jar writetohdfs.jar WriteToHDFS /input /output

5、等待任務(wù)完成,然后可以使用(′▽?zhuān)?hadoop fs ls /output命令查看輸出目錄中的內容。

(圖ヽ(′▽?zhuān)?ノ片來(lái)源網(wǎng)絡(luò ),侵刪)

上一篇:高端網(wǎng)站建設的公司_無(wú)錫高端網(wǎng)站建設的方案_2
下一篇:興仁縣網(wǎng)站建設

Copyright © 2026 天津九安特機電工程有限公司 版權所有   網(wǎng)站地圖

 
亚洲女同成aV人片在线观看|亚洲www啪成人一区二区麻豆|亚洲国产中日韩精品综合|亚洲国产成人精品一级片|亚洲无码在线视频免费 海淀区| 京山县| 庆安县| 伊春市| 东丽区| 遵义市| 饶平县| 伊川县| 深州市| 庄浪县| 菏泽市| 调兵山市| 塔城市| 安阳县| 乌鲁木齐市| 盖州市| 彭山县| 红桥区| 兴化市| 慈利县| 密云县| 商都县| 沙洋县| 开平市| 江孜县| 正镶白旗| 普陀区| 铁岭市| 平遥县| 互助| 老河口市| 黄冈市| 浮梁县| 义马市| 赣榆县| 吕梁市| 彭阳县| 蓬安县| 兰考县| 饶河县| 庆阳市| http://444 http://444 http://444 http://444 http://444 http://444