List of usage examples for org.apache.hadoop.conf Configuration Configuration
public Configuration()
From source file:FormatStorageBasicTest.java
License:Open Source License
public void testGetNextRecordFDCompress() { try {/*from w ww .j a va2s .co m*/ FieldMap fieldMap = new FieldMap(); fieldMap.addField(new Field(ConstVar.FieldType_Byte, ConstVar.Sizeof_Byte, (short) 0)); fieldMap.addField(new Field(ConstVar.FieldType_Short, ConstVar.Sizeof_Short, (short) 1)); fieldMap.addField(new Field(ConstVar.FieldType_Int, ConstVar.Sizeof_Int, (short) 2)); fieldMap.addField(new Field(ConstVar.FieldType_Long, ConstVar.Sizeof_Long, (short) 3)); fieldMap.addField(new Field(ConstVar.FieldType_Float, ConstVar.Sizeof_Float, (short) 4)); fieldMap.addField(new Field(ConstVar.FieldType_Double, ConstVar.Sizeof_Double, (short) 5)); fieldMap.addField(new Field(ConstVar.FieldType_String, 0, (short) 6)); Head head = new Head(); head.setFieldMap(fieldMap); head.setCompress((byte) 1); head.setCompressStyle(ConstVar.LZOCompress); String fileName = prefix + "testGetRecordByLineFDCompress"; Configuration conf = new Configuration(); FormatDataFile fd = new FormatDataFile(conf); fd.open(fileName); int recordNum = 1000 * 10000; Record record = fd.getRecordByLine(-1); if (record != null) { fail("should get null"); } for (int i = 0; i < recordNum; i++) { record = fd.getNextRecord(); if (record == null) { fail("should not get null:" + i); } judgeNotFixedRecord(record, i); } record = fd.getRecordByLine(recordNum); if (record != null) { fail("should get null"); } record = fd.getRecordByLine(recordNum + 1); if (record != null) { fail("should get null"); } fd.close(); } catch (IOException e) { e.printStackTrace(); fail("get IOException:" + e.getMessage()); } catch (Exception e) { e.printStackTrace(); fail("get exception:" + e.getMessage()); } }
From source file:FormatStorageBasicTest.java
License:Open Source License
public void testGetNextRecordFDCompressNotVar() { try {//from w ww . j ava 2s. c o m FieldMap fieldMap = new FieldMap(); fieldMap.addField(new Field(ConstVar.FieldType_Byte, ConstVar.Sizeof_Byte, (short) 0)); fieldMap.addField(new Field(ConstVar.FieldType_Short, ConstVar.Sizeof_Short, (short) 1)); fieldMap.addField(new Field(ConstVar.FieldType_Int, ConstVar.Sizeof_Int, (short) 2)); fieldMap.addField(new Field(ConstVar.FieldType_Long, ConstVar.Sizeof_Long, (short) 3)); fieldMap.addField(new Field(ConstVar.FieldType_Float, ConstVar.Sizeof_Float, (short) 4)); fieldMap.addField(new Field(ConstVar.FieldType_Double, ConstVar.Sizeof_Double, (short) 5)); Head head = new Head(); head.setFieldMap(fieldMap); head.setCompress((byte) 1); head.setCompressStyle(ConstVar.LZOCompress); String fileName = prefix + "testGetRecordByLineFDCompressNotVar"; Configuration conf = new Configuration(); FormatDataFile fd = new FormatDataFile(conf); fd.open(fileName); int recordNum = 1000 * 10000; Record record = fd.getRecordByLine(-1); if (record != null) { fail("should get null"); } for (int i = 0; i < recordNum; i++) { record = fd.getNextRecord(); if (record == null) { fail("should not get null:" + i); } judgeNotFixedRecord(record, i); } record = fd.getRecordByLine(recordNum); if (record != null) { fail("should get null"); } record = fd.getRecordByLine(recordNum + 1); if (record != null) { fail("should get null"); } fd.close(); } catch (IOException e) { e.printStackTrace(); fail("get IOException:" + e.getMessage()); } catch (Exception e) { e.printStackTrace(); fail("get exception:" + e.getMessage()); } }
From source file:FormatStorageBasicTest.java
License:Open Source License
public void testGetNextRecordFDCompressMR() { try {/* w w w.j a va2s . co m*/ FieldMap fieldMap = new FieldMap(); fieldMap.addField(new Field(ConstVar.FieldType_Byte, ConstVar.Sizeof_Byte, (short) 0)); fieldMap.addField(new Field(ConstVar.FieldType_Short, ConstVar.Sizeof_Short, (short) 1)); fieldMap.addField(new Field(ConstVar.FieldType_Int, ConstVar.Sizeof_Int, (short) 2)); fieldMap.addField(new Field(ConstVar.FieldType_Long, ConstVar.Sizeof_Long, (short) 3)); fieldMap.addField(new Field(ConstVar.FieldType_Float, ConstVar.Sizeof_Float, (short) 4)); fieldMap.addField(new Field(ConstVar.FieldType_Double, ConstVar.Sizeof_Double, (short) 5)); fieldMap.addField(new Field(ConstVar.FieldType_String, 0, (short) 6)); Head head = new Head(); head.setFieldMap(fieldMap); head.setCompress((byte) 1); head.setCompressStyle(ConstVar.LZOCompress); String fileName = prefix + "testGetRecordByLineFDCompress"; Configuration conf = new Configuration(); FormatDataFile fd = new FormatDataFile(conf); fd.open(fileName); int recordNum = 1000 * 10000; Record record = fd.getRecordByLine(-1); if (record != null) { fail("should get null"); } Record valueRecord = new Record(); for (int i = 0; i < recordNum; i++) { record = fd.getNextRecord(valueRecord); if (record == null) { fail("should not get null:" + i); } judgeNotFixedRecord(valueRecord, i); } record = fd.getRecordByLine(recordNum); if (record != null) { fail("should get null"); } record = fd.getRecordByLine(recordNum + 1); if (record != null) { fail("should get null"); } fd.close(); } catch (IOException e) { e.printStackTrace(); fail("get IOException:" + e.getMessage()); } catch (Exception e) { e.printStackTrace(); fail("get exception:" + e.getMessage()); } }
From source file:AvgScore.java
License:Apache License
public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length < 2) { System.err.println("Usage: AvgScore <in> [<in>...] <out>"); System.exit(2);/*w w w .j a v a 2s . c om*/ } Job job = new Job(conf, "AvgScore"); job.setJarByClass(AvgScore.class); job.setMapperClass(Map.class); //job.setCombinerClass(Reduce.class); job.setReducerClass(Reduce.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); for (int i = 0; i < otherArgs.length - 1; ++i) { FileInputFormat.addInputPath(job, new Path(otherArgs[i])); } FileOutputFormat.setOutputPath(job, new Path(otherArgs[otherArgs.length - 1])); System.exit(job.waitForCompletion(true) ? 0 : 1); }
From source file:LobFilePerfTest.java
License:Apache License
public LobFilePerfTest() { conf = new Configuration(); conf.set("fs.default.name", "file:///"); p = new Path("foo.lob"); }
From source file:TaskSearchWords.java
public static void main(String[] args) throws Exception { String hadoopServer = "ip-172-31-13-245.ap-southeast-1.compute.internal"; Configuration conf = new Configuration(); // this should be like defined in your mapred-site.xml conf.set("mapred.job.tracker", hadoopServer + ":54311"); // like defined in hdfs-site.xml conf.set("fs.default.name", "hdfs://" + hadoopServer + ":9000"); //setting mapred classes for HDFS to know which classes to process conf.set("mapreduce.map.class", "TokenizerMapper"); conf.set("mapreduce.reduce.class", "IntSumReducer"); //to prevent classdefnotfound exception conf.set("mapred.jar", "C:\\GitRepos\\OCR\\HadoopTasks\\dist\\HadoopTasks.jar"); //to pass parameters to mapred classes conf.set("RAWOCRCLOB", "Omeprazole_Cap E/C 10mg\n" + "Dressit Ster esDress\n" + "Flaminal Forte 15g\n" + "Co-Magaldrox_Susp 195mg/220mg/5ml S/F\n" + "Antacid/Oxetacaine_Oral Susp S/F\n" + "Simeticone_Susp 40mg/ml S/F\n" + "Infacol_Susp 40mg/ml S/F"); Job job = Job.getInstance(conf, "word count"); job.setJarByClass(TaskSearchWords.class); job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumReducer.class); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path("/user/ubuntu/MedicinesProcessed.csv")); FileSystem fs = FileSystem.get(conf); Path out = new Path("/user/ubuntu/processed/"); fs.delete(out, true);/*from ww w .j a v a 2s .c o m*/ //finally set the empty out path FileOutputFormat.setOutputPath(job, out); System.exit(job.waitForCompletion(true) ? 0 : 1); }
From source file:CountJob.java
License:Apache License
public static void doJob(String param, String args[], String msgs) throws IOException, ClassNotFoundException, InterruptedException { Configuration conf = new Configuration(); conf.set(TokenizerMapper.PATTERN, args[2]); FileSystem hdfs = FileSystem.get(conf); Path tempOutput1 = new Path("/data/output/temp/" + param + "1"); Path tempOutput2 = new Path("/data/output/temp/" + param + "2"); if (hdfs.exists(tempOutput1) || hdfs.exists(tempOutput2)) { hdfs.delete(tempOutput1, true);/*from w w w.j a v a 2s . com*/ hdfs.delete(tempOutput2, true); } Job job = new Job(conf, "word count"); job.setJarByClass(CountJob.class); job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(LongSumReducer.class); job.setReducerClass(LongSumReducer.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, tempOutput1); job.waitForCompletion(true); Job sortJob1 = new Job(conf); sortJob1.setJobName("grep-sort"); FileInputFormat.setInputPaths(sortJob1, tempOutput1); sortJob1.setInputFormatClass(SequenceFileInputFormat.class); sortJob1.setMapperClass(InverseMapper.class); sortJob1.setNumReduceTasks(1); // write a single file FileOutputFormat.setOutputPath(sortJob1, tempOutput2); sortJob1.setSortComparatorClass( // sort by decreasing freq LongWritable.DecreasingComparator.class); sortJob1.waitForCompletion(true); hdfs.delete(tempOutput1, true); }
From source file:CountJob.java
License:Apache License
public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); String msgs = ""; doJob("1", args, msgs); doJob("2", args, msgs); FileSystem hdfs = FileSystem.get(conf); BufferedReader bfr = new BufferedReader( new InputStreamReader(hdfs.open(new Path("/data/output/temp/12/part-r-00000")))); BufferedReader bfr2 = new BufferedReader( new InputStreamReader(hdfs.open(new Path("/data/output/temp/22/part-r-00000")))); Boolean same = true;/*w ww . j ava 2s .c om*/ String line1; String line2; line1 = bfr.readLine(); line2 = bfr2.readLine(); while (same == true) { if ((line1 == null && line2 != null) || (line1 != null && line2 == null)) { same = false; break; } else if ((line1 == null && line2 == null)) { break; } else { if (line1.equals(line2)) { line1 = bfr.readLine(); line2 = bfr2.readLine(); } else { same = false; break; } } } if (same == true) { System.out.print("same " + same + "\n"); Path localP = new Path("/tmp/output.txt"); hdfs.copyToLocalFile(new Path("/data/output/temp/12/part-r-00000"), localP); hdfs.copyFromLocalFile(localP, new Path(args[1] + "/part-r-00000")); hdfs.createNewFile(new Path(args[1] + "/_SUCCESS")); System.out.print("created result"); } else { System.out.print("Different"); doJob("3", args, msgs); Path localP = new Path("/tmp/output.txt"); hdfs.copyToLocalFile(new Path("/data/output/temp/32/part-r-00000"), localP); hdfs.copyFromLocalFile(localP, new Path(args[1] + "/part-r-00000")); hdfs.createNewFile(new Path(args[1] + "/_SUCCESS")); System.out.print("created result"); } hdfs.delete(new Path("/data/output/temp/12/part-r-00000"), true); hdfs.delete(new Path("/data/output/temp/22/part-r-00000"), true); }
From source file:FileAnalyzerTest.java
License:Open Source License
@BeforeTest public void setUp() throws IOException { //TODO mockito? fs = FileSystem.get(new Configuration()); // set up local file system }
From source file:lab2_3.java
public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); FileSystem.get(conf).delete(new Path(args[1]), true); FileSystem.get(conf).delete(TMPDIR, true); Job first = Job.getInstance(conf, "drive time lab 2.2"); first.setJarByClass(lab2_3.class); first.setMapperClass(lab2_2.PartitioningMapper.class); first.setPartitionerClass(lab2_2.TypePartitioner.class); first.setReducerClass(lab2_2.IdentityReducer.class); first.setNumReduceTasks(6);/* ww w . j a va 2s . c o m*/ first.setOutputKeyClass(IntWritable.class); first.setOutputValueClass(Text.class); FileInputFormat.addInputPath(first, new Path(args[0])); FileOutputFormat.setOutputPath(first, TMPDIR); int code = first.waitForCompletion(true) ? 0 : 1; if (code == 0) { Job second = Job.getInstance(conf, "drive time lab 2.3"); second.setJarByClass(lab2_3.class); second.setMapperClass(MMMaper.class); second.setReducerClass(Reeeducer.class); second.setPartitionerClass(Partitioneeeer.class); second.setNumReduceTasks(6); second.setOutputKeyClass(Text.class); second.setOutputValueClass(lab2_1.Statistics.class); FileInputFormat.addInputPath(second, TMPDIR); FileOutputFormat.setOutputPath(second, new Path(args[1])); code = second.waitForCompletion(true) ? 0 : 1; } // FileSystem.get(conf).delete(TMPDIR, true); System.exit(code); }