示例#1
0
 @Override
 public void process(String input, Emitter<Pair<String, Pair<String, Integer>>> emitter) {
   List<String> pieces = Lists.newArrayList(Splitter.on(sep).split(input));
   String id1 = pieces.get(0);
   String id2 = pieces.get(1);
   Integer score = Integer.valueOf(pieces.get(2));
   if (!id1.equals(id2) && score >= 0) {
     emitter.emit(Pair.of(id1, Pair.of(id2, score)));
     emitter.emit(Pair.of(id2, Pair.of(id1, -1)));
   }
 }
示例#2
0
 @Test
 public void testPairs() throws Exception {
   AvroType<Pair<String, String>> at = Avros.pairs(Avros.strings(), Avros.strings());
   Pair<String, String> j = Pair.of("a", "b");
   GenericData.Record w = new GenericData.Record(at.getSchema());
   w.put(0, new Utf8("a"));
   w.put(1, new Utf8("b"));
   testInputOutputFn(at, j, w);
 }
示例#3
0
 @Test
 @SuppressWarnings("rawtypes")
 public void testTableOf() throws Exception {
   AvroType at = Avros.tableOf(Avros.strings(), Avros.strings());
   Pair<String, String> j = Pair.of("a", "b");
   org.apache.avro.mapred.Pair w = new org.apache.avro.mapred.Pair(at.getSchema());
   w.put(0, new Utf8("a"));
   w.put(1, new Utf8("b"));
   // TODO update this after resolving the o.a.a.m.Pair.equals issue
   initialize(at);
   assertEquals(j, at.getInputMapFn().map(w));
   org.apache.avro.mapred.Pair converted =
       (org.apache.avro.mapred.Pair) at.getOutputMapFn().map(j);
   assertEquals(w.key(), converted.key());
   assertEquals(w.value(), converted.value());
 }
 @Override
 public Class<Pair<K, Iterable<V>>> getTypeClass() {
   return (Class<Pair<K, Iterable<V>>>) Pair.of(null, null).getClass();
 }