• hive数据文件简单合并


    MR代码:

    package merge;
    import java.io.IOException;
    import java.util.Iterator;
    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.io.IntWritable;
    import org.apache.hadoop.io.LongWritable;
    import org.apache.hadoop.io.Text;
    import org.apache.hadoop.mapred.FileInputFormat;
    import org.apache.hadoop.mapred.FileOutputFormat;
    import org.apache.hadoop.mapred.JobClient;
    import org.apache.hadoop.mapred.JobConf;
    import org.apache.hadoop.mapred.MapReduceBase;
    import org.apache.hadoop.mapred.Mapper;
    import org.apache.hadoop.mapred.OutputCollector;
    import org.apache.hadoop.mapred.Reducer;
    import org.apache.hadoop.mapred.Reporter;
    import org.apache.hadoop.mapred.TextInputFormat;
    import org.apache.hadoop.mapred.TextOutputFormat;
    
    public class merge
    {
        public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, Text>
        {
            private Text word=new Text("");
            public void map(LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter)
                    throws IOException
            {
                output.collect(value,word);
            }
        }
    
    
        public static void main(String[] args) throws Exception
        {
            JobConf conf = new JobConf(merge.class);
            conf.setJobName("wordcount");
            conf.setOutputKeyClass(Text.class);
            conf.setOutputValueClass(Text.class);
            conf.setMapperClass(Map.class);
            conf.setInputFormat(TextInputFormat.class);
            conf.setOutputFormat(TextOutputFormat.class);
            FileInputFormat.setInputPaths(conf, new Path(args[0]));
            FileOutputFormat.setOutputPath(conf, new Path(args[1]));
            JobClient.runJob(conf);
        }
    }

    Eclipse自动生成.class文件,打包命令:

    jar打包:在项目的bin目录下
    Dev-Fac:bin ce-pc$ jar -cvf hive-merge.jar -C  ../ .

    合并命令:

    hadoop jar /tmp/hive-merge.jar merge.merge /user/hive/warehouse/table1 /user/hive/warehouse/table1/out
    
    #merge.merge 表示merge包下的merge
  • 相关阅读:
    win10系统安装oracle11g时遇到INS-13001环境不满足最低要求
    C#文件重命名的代码
    自学MVC开发基础
    我的面试感悟-----3年工作经验的女程序员的感慨
    问心无愧,莫问前程
    Install your Application into RaspberryPi2 and automatically start up
    基于Vmware player的Windows 10 IoT core + RaspberryPi2安装部署
    MVC开发-后台开发总结
    页面长按禁止弹出选择菜单
    js检测链接(URL)是否有效
  • 原文地址:https://www.cnblogs.com/ggzone/p/5094492.html
Copyright © 2020-2023  润新知