在独立项目中使用mapreduce的方法

最近在搞一个大数据的项目,用的是mapreduce,但是想把mapreduce集成到项目中,通过点击按钮的方式来触发mapreduce。
具体方法如下:
1 先把mapreduce类写好,由于项目的原因,只用了map,没用到reduce过程

//mapreduce类
	public static class _map extends Mapper<LongWritable, Text, NullWritable, NullWritable> {
        @Override
        public void map(LongWritable key, Text value, Context context) throws IOException, 		     InterruptedException {
        	//map过程
        	}
    }
    public static boolean main(String[] args) throws IOException, InterruptedException, ClassNotFoundException
    {
        Configuration conf = new Configuration();
        conf.set("参数1", args[1]);
        conf.set("参数2", args[2]);
        conf.set("参数3", args[3]);
        //把需要的参数放到这里即可
        conf.set("mapreduce.job.jar","/home/files/AISA.jar");
        conf.set("fs.defaultFS", "hdfs://h1:9000/");
        conf.set("mapreduce.framework.name", "yarn");
        conf.set("yarn.resourcemanager.hostname", "h1");
        Job job = new Job(conf, "_mr");
        job.setJarByClass(_mr.class);
        job.setMapperClass(_mr._map.class);
        job.setNumReduceTasks(0);
        job.setInputFormatClass(TextInputFormat.class);
        job.setOutputFormatClass(NullOutputFormat.class);
        FileInputFormat.addInputPath(job, new Path(args[0]));
        boolean iscomplete = job.waitForCompletion(true);
        return iscomplete;
    }

2 现在要在项目中调用 这个类

_mr mf = new _mr();  //上面的mapreduce类
String[] arg = {"参数1","参数2","参数3","..."};  //参数按照类里定义的顺序排列好
mf.main(arg);  //执行

这样就可以调用mapreduce了,是不是很简单

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值