`
tenght
  • 浏览: 51835 次
社区版块
存档分类
最新评论

Application to find the maximum temperature in the weather dataset

 
阅读更多

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class MaxTemperature {
  public static void main(String[] args) throws Exception {
    if (args.length != 2) {
      System.err.println("Usage: MaxTemperature <input path> <output path>");
      System.exit(-1);
    }
    
    Job job = new Job();
    job.setJarByClass(MaxTemperature.class);
    job.setJobName("Max temperature");
    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));
    
    job.setMapperClass(MaxTemperatureMapper.class);
    job.setReducerClass(MaxTemperatureReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}

Job对象指定了作业的各种参数.它授予你对整个作业如何运行的控制权.当我 们在 Hadoop 集群上运行这个作业时,我们把代码打包成一个 JAR 文件(Hadoop 会在集群分发这个包).我们没有明确指定 JAR 文件的名称,而是在 Job构造函数中传送一个类,Hadoop 会找到这个包含此类的 JAR 文件.

在创建 Job对象后,我们将指定输入和输出的路径.通过调用 FileInputFormat 内的静态方法 addInputPath()来定义输入的路径,它可以是单个 文件,目录(本例中,输入的内容组成此目录下所有文件)或文件模式的路径.同时, addInputPath()可被调用多次从而实现使用多路径输入.

输出路径(其中只有一个)是在 FileOutputFormat 内的静态方法 setOutputPath()来指定的.它指定了 reduce 函数输出文件写入的目录.在运行作业前该目录不应该存在,否则 Hadoop 会报错并且拒绝运行任务.这种预防措施是为了防止 数据丢失(一个长时间的任务可能非常恼人地被另一个意外覆盖).

接下来,通过 setMapperClass()和 setReducerClass()这两个方法来指定要使 用的 map 和 reduce 类型. setOutputKeyClass()和 setOutputValueClass()方法控制 map 和 reduce 函数的输出类型,正如本例所示,这两个方法往往是相同的.如果它们不同,那么 map 的输出类型可设置成使用 setMapOutputKeyClass()和 setMapOutputValueClass()方法.

输入的类型通过输入格式来控制,我们没有设置,因为我们使用的是默认的 TextInputFormat(文本输入格式).

在设置了定义 map 和 reduce 函数的类之后,运行作业的准备工作就算完成了. JobClient 内的静态方法 runJob()会提交作业并等待它完成,把进展情况写入控制台.

waitForCompletion()方法的返回值是一个布尔型true表示成功,false表示失败,即我们翻译成0或1程序的退出代码。


分享到:
评论

相关推荐

    野生动物中的印度蒙面人_Indian Masked Faces in the Wild Dataset

    ing face masks has become mandatory in public areas due to the COVID-19 pandemic, leading to a significant portion of the facial region being occluded. This presents new challenges for face ...

    Linq技术实例 Linq To Sql Linq To DataSet

    **Linq技术实例:Linq To Sql与Linq To DataSet** **一、Linq简介** Linq(Language Integrated Query,语言集成查询)是.NET Framework 3.5引入的一项创新技术,它将查询操作直接整合到C#和VB.NET等编程语言中,...

    批量转换json_to_dataset.py

    用labelme标注图片的时候只能进行一张图片的转换,将此代码放入E:\anaconda\Lib\site-packages\labelme\cli(conda安装目录下labelme的文件夹)替换掉原始的json_to_dataset.py 在想要得到转换后文件的文件夹中打开...

    cvpr18-3D Human Pose Estimation in the Wild by Adversarial Learning

    learned from the fully annotated dataset to in-the-wild im- ages with only 2D pose annotations. Instead of defining hard-coded rules to constrain the pose estimation results, we design a novel multi-...

    DataSetToExcel

    delphi DataSettoExcel

    pytorch-Learning-to-See-in-the-Dark-master.zip

    在这个名为"pytorch-Learning-to-See-in-the-Dark-master"的项目中,我们看到的是一个针对CVPR(计算机视觉与模式识别)会议发表的论文实现。CVPR是计算机视觉领域的顶级会议,每年都会展示许多前沿的研究成果。此...

    Restricting the nonlinearity parameter in soil greenhouse gas flux calculation

    scheme for a measured flux dataset to estimate the actual bias and uncertainty. The KAPPA.MAX method effectively improved the decision between linear and nonlinear flux estimatesreducing the bias at a...

    C# list to dataset

    ### C# 中 List 转换为 DataSet 的方法解析及应用场景 #### 一、知识点概述 在 C# 开发过程中,经常会遇到数据处理的需求,尤其是从数据库查询数据后进行一系列操作,比如展示、分析或者导出报表等。在这个过程中...

    The Extended Cohn-Kanade Dataset (CK+)

    Bai渡Yun链接 内含CK和CK+两个完整数据集,只可用于人脸表情识别的学术研究。The Extended Cohn-Kanade Dataset (CK+): A complete dataset for action unit and emotion-specified expression

    json_to_dataset.py

    实现了json文件批量转换,修改了类别,可自主修改labelme类别。 希望大家能多多采用,多多支持。

    Linq 大全 Linq To Sql Linq To DataSet Linq To Object Linq to Xml

    在标题和描述中提到的"Linq To Sql"、"Linq To DataSet"、"Linq To Object"和"Linq To Xml"是LINQ的四种主要应用方式,分别用于SQL数据库、DataSet、内存中的对象以及XML数据的查询。 1. **LINQ to SQL**: LINQ ...

    The DataSet Grows Up in ADO.NET 2.0

    `serialize-to-disk.aspx`文件可能涉及到了`DataSet`的序列化,即把`DataSet`对象的状态转换为磁盘上的文件。这在需要持久化数据或跨进程传递数据时非常有用。`DataSet`可以被序列化为XML,方便存储和恢复。 `...

    关于gis几何变化的文章

    Geometric conflation is the process undertaken to modify the coordinates of features in dataset A in order to match corresponding ones in dataset B. The overwhelming majorityof the literature ...

    牛津IIIT宠物数据集(The Oxford-IIIT Pet Dataset).rar

    牛津IIIT宠物数据集(The Oxford-IIIT Pet Dataset)是计算机视觉和深度学习领域中一个广泛使用的数据集,尤其在图像分类和物体识别任务上。该数据集由牛津大学和IIIT-Hyderabad合作创建,旨在促进宠物识别技术的...

    To the Point Efficient 3D Object Detection in the Range Image

    【To the Point: Efficient 3D Object Detection in the Range Image with Graph Convolution Kernels】这篇论文探讨了在3D对象检测中的一个关键问题,尤其是在机器人应用中。它提出了一种直接从范围图像视角学习3D...

    dataset

    在IT行业中,数据处理是至关重要的任务,而`DataSet`是.NET Framework提供的一种数据处理组件,它能够存储和操作多个相关的数据表。在这个场景中,我们看到一个Web应用程序的事件处理函数,其目标是将从数据库查询...

    Parking-slot Dataset 2.0

    The images in this dataset were surround-view images synthesized from four low-cost fisheye cameras. Various parking-slot types were considered, including the vertical ones, the parallel ones, and the...

    labelme_json_to_dataset批量转数据

    labelme_json_to_dataset的批量转数据,提高效率, 下载后修改自己的路径 for file in ./img+json_org*

    LINQ自定义实体及LINQtoDATASET

    本文档详细介绍了LINQ TO DATASET以以及LINQ TO SQL创建实体类的例子,本人亲自测试通过。可以做参考,源代码,注释很清楚

    DataSet 转化为List的通用方法

    ### DataSet 转化为 List 的通用方法:深入解析与应用 在 IT 领域,数据处理是一项核心任务,特别是在数据库操作与数据展现层之间,数据格式的转换显得尤为重要。其中,`DataSet`到`List`的转换是常见的需求之一,...

Global site tag (gtag.js) - Google Analytics