6869707172737475767778
.parallelDo(extractIPResponseSize, Writables.tableOf(Writables.strings(), Writables.longs())).groupByKey() .combineValues(longSumCombiner); pipeline.writeTextFile(ipAddrResponseSize, args[1]); // Execute the pipeline as a MapReduce. PipelineResult result = pipeline.done(); return result.succeeded() ? 0 : 1; } // Function to parse apache log records
132133134135136137138139140141142
PCollection<Put> resultPut = createPut(result); // We write the puts in hbase, in the target table pipeline.write(resultPut, new HBaseTarget(TABLE_TARGET)); pipeline.done(); return 0; } /** * Put the puts in HBase
6970717273747576
return j.join(input.first(), j.join(input.second())); } }, ptf.strings()).materialize(); assertEquals(ImmutableList.of("one,[-5,10],[1,1],[2,-3]", "three,[0,-1]", "two,[1,7],[2,6],[4,5]"), ImmutableList.copyOf(lines)); p.done(); } }
113114115116117118119120121122123
assertEquals(3, sortedByAgeList.size()); assertEquals(ccc10, sortedByAgeList.get(0)); assertEquals(bbb20, sortedByAgeList.get(1)); assertEquals(aaa30, sortedByAgeList.get(2)); pipeline.done(); } private static void writeAvroFile(List<Person> people, File avroFile) throws IOException { FileOutputStream outputStream = new FileOutputStream(avroFile);
5152535455565758596061
return Pair.of(p[0], p[1]); } }, Avros.tableOf(Avros.strings(), Avros.strings())) .groupByKey() .write(new AvroPathPerKeyTarget(outDir)); p.done(); Set<String> names = Sets.newHashSet(); FileSystem fs = outDir.getFileSystem(tempDir.getDefaultConfiguration()); for (FileStatus fstat : fs.listStatus(outDir)) { names.add(fstat.getPath().getName());
8586878889909192939495
} }, Avros.tableOf(Avros.strings(), Avros.strings())) .filter(FilterFns.<Pair<String, String>>REJECT_ALL()) .groupByKey() .write(new AvroPathPerKeyTarget(outDir)); p.done(); FileSystem fs = outDir.getFileSystem(tempDir.getDefaultConfiguration()); assertFalse(fs.exists(outDir)); }
7576777879808182838485
org.apache.crunch.Pair<Person, Integer> firstEntry = Iterables.getFirst(personTable.materialize(), null); assertEquals("a", firstEntry.first().getName().toString()); assertEquals(Integer.valueOf(1), firstEntry.second()); pipeline.done(); } @Test public void testInputFromMapRedKeyValueFile_Specific() throws IOException {
9899100101102103104105106107108
PTableType<Person, Integer> tableType = Avros.keyValueTableOf(Avros.specifics(Person.class), Avros.ints()); tableType.initialize(tempDir.getDefaultConfiguration()); org.apache.crunch.Pair<Person, Integer> detachedPair = tableType.getDetachedValue(firstEntry); assertEquals(firstEntry, detachedPair); pipeline.done(); } @Test public void testInputFromMapRedKeyValueFile_Reflect() throws IOException { Path keyValuePath = produceMapRedOutputFile();
121122123124125126127128129130131
Avros.keyValueTableOf(Avros.reflects(ReflectedPerson.class), Avros.ints()); tableType.initialize(tempDir.getDefaultConfiguration()); org.apache.crunch.Pair<ReflectedPerson, Integer> detachedPair = tableType.getDetachedValue(firstEntry); assertEquals(firstEntry, detachedPair); pipeline.done(); } /** * Produces an Avro file using the org.apache.avro.mapred.* API. */
90919293949596979899100
} }, Writables.tableOf(Writables.writables(IntWritable.class), Writables.writables(Text.class))); PTable<IntWritable, Text> out = Mapreduce.map(two, TestMapper.class, IntWritable.class, Text.class); out.write(To.sequenceFile(tempDir.getPath("temp"))); PipelineResult res = p.done(); assertEquals(1, res.getStageResults().size()); StageResult sr = res.getStageResults().get(0); assertEquals(3667, sr.getCounters().findCounter("written", "out").getValue()); }