/** * CoGroupFunction that realizes an anti-join. * If the first input does not provide any pairs, all pairs of the second input are emitted. * Otherwise, no pair is emitted. */ @ConstantFieldsFirstExcept({}) public static class AntiJoinVisits extends CoGroupFunction implements Serializable { private static final long serialVersionUID = 1L; /** * If the visit iterator is empty, all pairs of the rank iterator are emitted. * Otherwise, no pair is emitted. * * Output Format: * 0: URL * 1: RANK * 2: AVG_DURATION */ @Override public void coGroup(Iterator<Record> ranks, Iterator<Record> visits, Collector<Record> out) { // Check if there is a entry in the visits relation if (!visits.hasNext()) { while (ranks.hasNext()) { // Emit all rank pairs out.collect(ranks.next()); } } } }
/** * Matches all missing edges with existing edges from input. * If the missing edge for a triad is found, the triad is transformed to a triangle by adding the missing edge. */ @ConstantFieldsFirstExcept({}) public static class CloseTriads extends JoinFunction implements Serializable { private static final long serialVersionUID = 1L; @Override public void join(Record triad, Record missingEdge, Collector<Record> out) throws Exception { // emit triangle (already contains missing edge at field 0 out.collect(triad); } }
@ConstantFieldsFirstExcept(2) public static class JoinInputs extends JoinFunction { private static final long serialVersionUID = 1L; @Override public void join(Record input1, Record input2, Collector<Record> out) { input1.setField(2, input2.getField(1, IntValue.class)); out.collect(input1); } }