@Override public void close() throws IOException { addAccumulator(CHECKSUM, new Checksum(count, checksum)); } }
@Override public Accumulator<Checksum, Checksum> clone() { return new Checksum(count, checksum); } }
@Override public void write(String executionName, PrintStream out, DataSet<T> data) throws Exception { ChecksumHashCode<T> checksumHashCode = new ChecksumHashCode<T>().run(data); if (printExecutionPlan.getValue()) { out.println(); out.println(data.getExecutionEnvironment().getExecutionPlan()); } ChecksumHashCode.Checksum checksum = checksumHashCode .execute(executionName); out.println(); out.println(checksum); } }
@Override public ChecksumHashCode<K, VV, EV> run(Graph<K, VV, EV> input) throws Exception { super.run(input); vertexChecksum = new org.apache.flink.graph.asm.dataset.ChecksumHashCode<>(); vertexChecksum.run(input.getVertices()); edgeChecksum = new org.apache.flink.graph.asm.dataset.ChecksumHashCode<>(); edgeChecksum.run(input.getEdges()); return this; }
@Override public GlobalClusteringCoefficient<K, VV, EV> run(Graph<K, VV, EV> input) throws Exception { super.run(input); triangleCount = new Count<>(); DataSet<TriangleListing.Result<K>> triangles = input .run(new TriangleListing<K, VV, EV>() .setSortTriangleVertices(false) .setParallelism(parallelism)); triangleCount.run(triangles); vertexMetrics = new VertexMetrics<K, VV, EV>() .setParallelism(parallelism); input.run(vertexMetrics); return this; }
@Override public Count<T> run(DataSet<T> input) throws Exception { super.run(input); countHelper = new CountHelper<>(); input .output(countHelper) .name("Count"); return this; }
@Override public ChecksumHashCode<T> run(DataSet<T> input) throws Exception { super.run(input); checksumHashCodeHelper = new ChecksumHashCodeHelper<>(); input .output(checksumHashCodeHelper) .name("ChecksumHashCode"); return this; }
@Override public Collect<T> run(DataSet<T> input) throws Exception { super.run(input); serializer = input.getType().createSerializer(env.getConfig()); collectHelper = new CollectHelper<>(serializer); input .output(collectHelper) .name("Collect"); return this; }
@Override public Result getResult() { // each triangle is counted from each of the three vertices long numberOfTriangles = 3 * triangleCount.getResult(); return new Result(vertexMetrics.getResult().getNumberOfTriplets(), numberOfTriangles); }
@Override public void close() throws IOException { addAccumulator(COLLECT, accumulator); } }
@Override public Long getResult() { return countHelper.getAccumulator(env, COUNT); }
@Override public Checksum getResult() { return checksumHashCodeHelper.getAccumulator(env, CHECKSUM); }
@Override public void close() throws IOException { addAccumulator(COUNT, new LongCounter(count)); } }
@Override public void merge(Accumulator<Checksum, Checksum> other) { add(other.getLocalValue()); }
@Override public List<T> getResult() { ArrayList<byte[]> accResult = collectHelper.getAccumulator(env, COLLECT); if (accResult != null) { try { return SerializedListAccumulator.deserializeList(accResult, serializer); } catch (ClassNotFoundException e) { throw new RuntimeException("Cannot find type class of collected data type", e); } catch (IOException e) { throw new RuntimeException("Serialization error while deserializing collected data", e); } } else { throw new RuntimeException("Unable to retrieve the DataSet"); } }
@Override public R execute() throws Exception { env.execute(); return getResult(); }
@Override public GlobalClusteringCoefficient<K, VV, EV> run(Graph<K, VV, EV> input) throws Exception { super.run(input); triangleCount = new Count<>(); DataSet<TriangleListing.Result<K>> triangles = input .run(new TriangleListing<K, VV, EV>() .setSortTriangleVertices(false) .setParallelism(parallelism)); triangleCount.run(triangles); vertexMetrics = new VertexMetrics<K, VV, EV>() .setParallelism(parallelism); input.run(vertexMetrics); return this; }
@Override public Result getResult() { // each triangle must be counted from each of the three vertices // as each triplet is counted in this manner long numberOfTriangles = 3 * triangleCount.getResult(); return new Result(vertexMetrics.getResult().getNumberOfTriplets(), numberOfTriangles); }
@Override public R execute(String jobName) throws Exception { Preconditions.checkNotNull(jobName); env.execute(jobName); return getResult(); } }