hbase

public class a  extends Mapper<LongWritable , Text,NullWritable,Text>{
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String s = value.toString();
        if (s.isEmpty()){
            return;
        }
        String[] split = s.split(":");
        if (split.length>10){
            String s4 = "";
            String s1 = s.substring(s.indexOf(split[9])).replace(":", "&");
            String s2 = s.substring(0, s.indexOf(split[9]));
            String s3 = s2.replace(" & ", ",");
            s4 = s3+s1;
            context.write(NullWritable.get(),new Text(s4));
        }

    }
}

 

 

public class DSReduce extends Reducer<NullWritable,Text,Text,Text> {
    @Override
    protected void reduce(NullWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        FileSystem fs = null;

        try {
            fs = FileSystem.get(new URI("hdfs://192.168.100.191:8020"), new Configuration());
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }

        FSDataOutputStream fsDataOutputStream = fs.create(new Path("/video.txt"));

        for (Text value : values) {

            fsDataOutputStream.write((value.toString()+"\r\n" +
                    "").getBytes());
        }
    }
}

 

public class DSDriver extends Configured implements Tool {
    @Override
    public int run(String[] args) throws Exception {

        Configuration _conf = new Configuration();

        Job job = new Job(_conf, "DataSplit");
        job.setJarByClass(DSDriver.class);

        //设置map输出类型
        job.setMapperClass(DSMapper.class);
        job.setMapOutputKeyClass(NullWritable.class);
        job.setMapOutputValueClass(Text.class);

        //设置reduce输出类型
        job.setReducerClass(DSReduce.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        //设置输入
        job.setInputFormatClass(TextInputFormat.class);
        // TextInputFormat.setInputPaths(job,new Path(args[0]));
        TextInputFormat.setInputPaths(job,new Path("F:\\wordcount\\video.txt"));

        //设置输出
        job.setOutputFormatClass(TextOutputFormat.class);
        TextOutputFormat.setOutputPath(job,new Path("hdfs://192.168.100.191:8020//DS"));

        return job.waitForCompletion(true)?0:1;
    }

    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration();
        ToolRunner.run(configuration,new DSDriver(),args);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值