实验3MapReduce编程初级实践


    实验3 MapReduce编程初级实践
    1 实验目
    1通实验掌握基MapReduce编程方法
    2掌握MapReduce解决常见数处理问题包括数重数排序数挖掘等
    2 实验台
    已配置完成Hadoop伪分布式环境
    3 实验容求
    1编程实现文件合重操作
    两输入文件文件A文件B请编写MapReduce程序两文件进行合剔中重复容新输出文件C面输入文件输出文件样例供参考

    实验终结果(合文件):

    代码:
    package comMerge

    import javaioIOException
    import orgapachehadoopconfConfiguration
    import orgapachehadoopfsPath
    import orgapachehadoopioText
    import orgapachehadoopmapreduceJob
    import orgapachehadoopmapreduceMapper
    import orgapachehadoopmapreduceReducer
    import orgapachehadoopmapreducelibinputFileInputFormat
    import orgapachehadoopmapreduceliboutputFileOutputFormat

    public class Merge {

    public static class Map extends Mapper {
    private static Text text new Text()

    public void map(Object key Text value Context context)
    throws IOException InterruptedException {
    text value
    contextwrite(text new Text())
    }
    }

    public static class Reduce extends Reducer {
    public void reduce(Text key Iterable values Context context)
    throws IOException InterruptedException {
    contextwrite(key new Text())
    }
    }

    public static void main(String[] args) throws Exception {
    Configuration conf new Configuration()
    confset(fsdefaultFS hdfslocalhost9000)
    String[] otherArgs new String[] { input output }
    if (otherArgslength 2) {
    Systemerrprintln(Usage Merge and duplicate removal )
    Systemexit(2)
    }
    Job job JobgetInstance(conf Merge and duplicate removal)
    jobsetJarByClass(Mergeclass)
    jobsetMapperClass(Mapclass)
    jobsetReducerClass(Reduceclass)
    jobsetOutputKeyClass(Textclass)
    jobsetOutputValueClass(Textclass)
    FileInputFormataddInputPath(job new Path(otherArgs[0]))
    FileOutputFormatsetOutputPath(job new Path(otherArgs[1]))
    Systemexit(jobwaitForCompletion(true) 0 1)
    }

    }
    2 编写程序实现输入文件排序
    现输入文件文件中行容均整数求读取文件中整数进行升序排序输出新文件中输出数格式行两整数第数字第二整数排序位次第二整数原排列整数面输入文件输出文件样例供参考

    实验结果截图:


    代码:
    package comMergeSort

    import javaioIOException
    import orgapachehadoopconfConfiguration
    import orgapachehadoopfsPath
    import orgapachehadoopioIntWritable
    import orgapachehadoopioText
    import orgapachehadoopmapreduceJob
    import orgapachehadoopmapreduceMapper
    import orgapachehadoopmapreduceReducer
    import orgapachehadoopmapreducelibinputFileInputFormat
    import orgapachehadoopmapreduceliboutputFileOutputFormat

    public class MergeSort {
    public static class Map extends
    Mapper {
    private static IntWritable data new IntWritable()

    public void map(Object key Text value Context context)
    throws IOException InterruptedException {
    String line valuetoString()
    dataset(IntegerparseInt(line))
    contextwrite(data new IntWritable(1))
    }
    }

    public static class Reduce extends
    Reducer {
    private static IntWritable linenum new IntWritable(1)

    public void reduce(IntWritable key Iterable values
    Context context) throws IOException InterruptedException {
    for (IntWritable val values) {
    contextwrite(linenum key)
    linenum new IntWritable(linenumget() + 1)
    }

    }

    }

    public static void main(String[] args) throws Exception {
    Configuration conf new Configuration()
    confset(fsdefaultFS hdfslocalhost9000)
    String[] otherArgs new String[] { input2 output2 } * 直接设置输入参数 *
    if (otherArgslength 2) {
    Systemerrprintln(Usage mergesort )
    Systemexit(2)
    }
    Job job JobgetInstance(conf mergesort)
    jobsetJarByClass(MergeSortclass)
    jobsetMapperClass(Mapclass)
    jobsetReducerClass(Reduceclass)
    jobsetOutputKeyClass(IntWritableclass)
    jobsetOutputValueClass(IntWritableclass)
    FileInputFormataddInputPath(job new Path(otherArgs[0]))
    FileOutputFormatsetOutputPath(job new Path(otherArgs[1]))
    Systemexit(jobwaitForCompletion(true) 0 1)

    }

    }
    3 定表格进行信息挖掘
    面出childparent表格求挖掘中父子辈关系出祖孙辈关系表格

    实验结果截图:

    代码:
    package comjoin

    import javaioIOException
    import javautil*
    import orgapachehadoopconfConfiguration
    import orgapachehadoopfsPath
    import orgapachehadoopioText
    import orgapachehadoopmapreduceJob
    import orgapachehadoopmapreduceMapper
    import orgapachehadoopmapreduceReducer
    import orgapachehadoopmapreducelibinputFileInputFormat
    import orgapachehadoopmapreduceliboutputFileOutputFormat

    public class STjoin {
    public static int time 0

    public static class Map extends Mapper {
    public void map(Object key Text value Context context)
    throws IOException InterruptedException {
    String child_name new String()
    String parent_name new String()
    String relation_type new String()
    String line valuetoString()
    int i 0
    while (linecharAt(i) ' ') {
    i++
    }
    String[] values { linesubstring(0 i) linesubstring(i + 1) }
    if (values[0]compareTo(child) 0) {
    child_name values[0]
    parent_name values[1]
    relation_type 1
    contextwrite(new Text(values[1]) new Text(relation_type + +
    + child_name + + + parent_name))
    relation_type 2
    contextwrite(new Text(values[0]) new Text(relation_type + +
    + child_name + + + parent_name))
    }
    }
    }

    public static class Reduce extends Reducer {
    public void reduce(Text key Iterable values Context context)
    throws IOException InterruptedException {
    if (time 0) {
    contextwrite(new Text(grand_child) new Text(grand_parent))
    time++
    }
    int grand_child_num 0
    String grand_child[] new String[10]
    int grand_parent_num 0
    String grand_parent[] new String[10]
    Iterator ite valuesiterator()
    while (itehasNext()) {
    String record itenext()toString()
    int len recordlength()
    int i 2
    if (len 0)
    continue
    char relation_type recordcharAt(0)
    String child_name new String()
    String parent_name new String()
    while (recordcharAt(i) '+') {
    child_name child_name + recordcharAt(i)
    i++
    }
    i i + 1
    while (i < len) {
    parent_name parent_name + recordcharAt(i)
    i++
    }
    if (relation_type '1') {
    grand_child[grand_child_num] child_name
    grand_child_num++
    } else {
    grand_parent[grand_parent_num] parent_name
    grand_parent_num++
    }
    }

    if (grand_parent_num 0 && grand_child_num 0) {
    for (int m 0 m < grand_child_num m++) {
    for (int n 0 n < grand_parent_num n++) {
    contextwrite(new Text(grand_child[m]) new Text(
    grand_parent[n]))
    }
    }
    }
    }
    }

    public static void main(String[] args) throws Exception {
    Configuration conf new Configuration()
    confset(fsdefaultFS hdfslocalhost9000)
    String[] otherArgs new String[] { input3 output3 }
    if (otherArgslength 2) {
    Systemerrprintln(Usage Single Table Join )
    Systemexit(2)
    }
    Job job JobgetInstance(conf Single table join )
    jobsetJarByClass(STjoinclass)
    jobsetMapperClass(Mapclass)
    jobsetReducerClass(Reduceclass)
    jobsetOutputKeyClass(Textclass)
    jobsetOutputValueClass(Textclass)
    FileInputFormataddInputPath(job new Path(otherArgs[0]))
    FileOutputFormatsetOutputPath(job new Path(otherArgs[1]))
    Systemexit(jobwaitForCompletion(true) 0 1)

    }

    }



    4 实验报告
    云计算 实验报告
    题目:
    MapReduce编程初级实践
    姓名
    包生友
    日期:20161220
    实验环境:机房虚拟机配置环境
    解决问题思路:根老师代码进行操作
    实验容完成情况:已完成学商量部分代码尚未知道作
    出现问题:执行出现未找main函数情况次执行会报错说文件已存
    解决方案(列出遇问题解决办法列出没解决问题):
    问题:1执行出现未找main函数情况
    2 次执行会报错说文件已存
    解决办法:删输出文件(程序执行时输出文件存)

    5 实验总结
    通次实验掌握基MapReduce编程方法掌握MapReduce解决常见数处理问题包括数重数排序数挖掘等短暂云计算课程实验结束知道云计算学没头


    文档香网(httpswwwxiangdangnet)户传

    《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
    该内容是文档的文本内容,更好的格式请下载文档

    下载文档到电脑,查找使用更方便

    文档的实际排版效果,会与网站的显示效果略有不同!!

    需要 2 香币 [ 分享文档获得香币 ]

    下载文档

    相关文档

    linux编程SHELL编程实验报告

    Linux编程课程设计报告题 目: Linux Shell编程 专 业 学 号 姓 名 ...

    1年前   
    607    0

    数控铣床编程与操作实验

    实验四 数控铣床编程与操作实验一、实验目的1.了解数控铣床的基本特点和机床坐标系。2.熟悉FANUC 0i-MD 数控系统应用。3.掌握数控铣床常规操作方法,重点学习数控铣床回零操作、手动对...

    1年前   
    272    0

    《windows编程实践》教学大纲

    课程名称:windows编程实践课程编号:开课学院:计算机学院适用专业:计算机学院各专业学 分: 1.5 学 时: 56(其中讲课16,机时40) 先修课程:C/C++程序设计基础

    2年前   
    452    0

    电子商务创业初级实践报告

    电子商务创业初级实践报告  我们是x团队!虽然我们在第一阶段的比赛中有许多地方做的不足,有许多方面需要改进,还有许多东西要去学习去尝试……但我们不会因此而放弃的,最大的收获就是学会了坚持和不断...

    11年前   
    429    0

    XX县实验初级中学学生资助工作计划

    XX县实验初级中学学生资助工作计划全面贯彻教体局关于家庭经济困难学生资助的相关工作文件和意见,制定了学校资助工作计划,全面开展学年段资助工作。一、加大力度,认真做好资助政策的宣传建立健全学校学...

    3年前   
    523    0

    2021年实验初级中学政教工作总结

     2021年实验初级中学政教工作总结撰写人:___________日 期:___________2021年实验初级中学政教工作总结一、取得的成绩:(一)、构建德育平台,全面加强学生的思想道德...

    10个月前   
    137    0

    实验初级中学2021年上半年工作总结

    二○一九上半年,学校以党的十九大精神为指导,深刻领会习近平新时代中国特色社会主义思想,在县委、县政府的正确领导和县教育局的全力指导下,持续开展每月的“党员主题活动日”活动

    3年前   
    520    0

    实验初级中学“县管校聘”工作实施方案

    @县实验初级中学“县管校聘”工作实施方案(讨论稿)根据@政办发〔2018〕30号《@县人民政府办公室关于印发推进中小学教师 “县管校聘”管理改革工作的实施意见》文件精神,结合我校实际情况,制定...

    4年前   
    1903    0

    实验初级中学党支部深入学习实践科学发展观活动计划

    实验初级中学党支部深入学习实践科学发展观活动计划 根据上级党委的部署,本党支部深入学习实践科学发展观活动列入第三批学习实践活动,现提出如下学习计划: 一、充分认识开展第三批学习实践活动的重...

    14年前   
    16451    0

    01-MySQL文档C文档API-编程实践

    MySQL_C_API编程实践1MySQL C API helloWorld1.1有关mysqlclient库C APIs包含在mysqlclient库文件当中,与MySQL的源代码一块发行,...

    3年前   
    352    0

    编程 汇编题目

    一、选择题1. 已知指令CALL DWORD PTR [BX]执行前(SP)=108H, 则该指令执行后SP的内容为 ( )。A. 100H B. 104H C. 0...

    4年前   
    698    0

    linux与windows 编程区别

    linux windows 编程的区别 如果一个程序员从来没有在linux,unix下开发过程序,一直在windows下面开发程序, 同样是工作10年, 大部分情况下与在linux,unix...

    7年前   
    2605    0

    软件编程实习总结

    软件编程实习总结  实习时间:3月1日―――5月9日  实习地点:广州xx大学生实训基地  实训目标:  1.通过系统性的实训,熟练掌握java se、java ee知识体系,具备java开发...

    9年前   
    520    0

    Scratch趣味编程

    Scratch趣味编程随着社会信息化程度的不断提高,掌握运用计算机 解决问题的能力显得越来越重要,计算机程序设计是培 养学生运用计算机解决问题能力的重要途径,也是培养 学生计算思维与创新能力的...

    2年前   
    703    1

    编程人员的质量感言

    质  量  感  言   质量是社会生活中最常见的概念,是企业永恒的主题,关系到企业的生存与发展。做为加工中心的一名编程人员,深知这个岗位的重要性,图纸一但输入错误会对公司造成很大的损失,...

    12年前   
    12709    0

    网络编程实习报告

    网络编程实习报告  [实习目的]   通过理论联系实际,巩固所学的知识,提高处理实际问题的能力,并为自己能顺利与社会环境接轨做准备。[实习任务]Linux下网络服务器开发(基于C语言);本文总...

    9年前   
    521    0

    CMM实用编程技术

    CMM实用编程技术   1. 若图面各视图上均有尺寸需编程测量时,最好在每个视图上标示出坐标系,以利于判断工件在机台所处的位置   2. 在建立工件坐标系时,若无特别说明,工件坐标系应...

    9年前   
    7730    0

    数控编程实习报告

    数控编程实习报告  随着制造业的发展,机床是制造业的主要生产设备其发展也是日新月异。社会的进步,人们对各类产品的要求也越来越高,像汽车这样大批量的产品,也要求个性化。因此不能采用传统化的刚性生...

    10年前   
    582    0

    数控编程说课

    《数控加工技术》既是数控技术专业基于工作过程系统化设计的专业核心课程,又是数控工艺员,数控程序员,数控机床操作工职业资格考试的必修课程.下面我从课程设置,教学内容,教学设计,教学组织与实施,特色...

    6年前   
    14069    0

    《Java趣味编程100例》

    第1章 变幻多姿的图表图表简洁直观,在各种场合得到广泛应用,给人以很强的视觉冲击,经常让人难以忘怀。我们的程序中如果能够灵活地应用图表,一定能给我们的程序增色不少。本章将带你进入变换多姿的图...

    2年前   
    813    0

    文档贡献者

    文***享

    贡献于2023-04-02

    下载需要 2 香币 [香币充值 ]
    亲,您也可以通过 分享原创文档 来获得香币奖励!

    该用户的其他文档