c语言sscanf函数的用法是什么
241
2022-11-25
MapReducer自定义OutPutFormat
package MyOutPutFormat;
import DBOutFormat.MysqlDBOutPutFormat;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FSDataOutputStream;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.LongWritable;import org.apache.hadoop.io.NullWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.*;import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import java.io.File;import java.io.IOException;
import static org.apache.hadoop.mapreduce.lib.output.FileOutputFormat.getOutputPath;
public class reduce {public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
String input = "data/access.log" ;
String output ="out" ;
final Configuration co = new Configuration() ;
final Job job = Job.getInstance(co);
//设置class
job.setJarByClass(reduce.class);
//设置mapper 和 Reduce
job.setMapperClass(MyMapper.class);
job.setReducerClass(MyReducer.class);
//设置 Mapper 阶段输出数据的key 和value
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(NullWritable.class);
//设置Reducer 阶段输出数据的key 和value
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(NullWritable.class);
//设置输入和输出路径
FileInputFormat.setInputPaths(job, new Path(input));
FileOutputFormat.setOutputPath(job, new Path(output));
//job输出发生变化 ,使用自定义的 outputformat
job.setOutputFormatClass(MyOutputFormat.class);
Path outDir = getOutputPath(job) ;
if (outDir.getFileSystem(job.getConfiguration()).exists(outDir)) {
File file = new File(outDir.toUri()) ;
if(file.isDirectory()){
File[] childrenFiles = file.listFiles();
for (File childFile:childrenFiles){
childFile.delete() ;
}
}
file.delete();
}
//提交 job
final boolean result = job.waitForCompletion(true);
System.exit(result ? 0 : 1);
}
public static class MyMapper extends Mapper
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~