@Override public Vertex<NEW, VV> map(Vertex<OLD, VV> value) throws Exception { vertex.f0 = wrappedFunction.translate(value.f0, vertex.f0); vertex.f1 = value.f1; return vertex; } }
/** * Translate {@link Vertex} IDs using the given {@link TranslateFunction}. * * @param vertices input vertices * @param translator implements conversion from {@code OLD} to {@code NEW} * @param <OLD> old vertex ID type * @param <NEW> new vertex ID type * @param <VV> vertex value type * @return translated vertices */ public static <OLD, NEW, VV> DataSet<Vertex<NEW, VV>> translateVertexIds(DataSet<Vertex<OLD, VV>> vertices, TranslateFunction<OLD, NEW> translator) { return translateVertexIds(vertices, translator, PARALLELISM_DEFAULT); }
/** * Translate {@link Edge} IDs using the given {@link TranslateFunction}. * * @param edges input edges * @param translator implements conversion from {@code OLD} to {@code NEW} * @param <OLD> old edge ID type * @param <NEW> new edge ID type * @param <EV> edge value type * @return translated edges */ public static <OLD, NEW, EV> DataSet<Edge<NEW, EV>> translateEdgeIds(DataSet<Edge<OLD, EV>> edges, TranslateFunction<OLD, NEW> translator) { return translateEdgeIds(edges, translator, PARALLELISM_DEFAULT); }
@Override public Graph<NEW, VV, EV> runInternal(Graph<OLD, VV, EV> input) throws Exception { // Vertices DataSet<Vertex<NEW, VV>> translatedVertices = translateVertexIds(input.getVertices(), translator, parallelism); // Edges DataSet<Edge<NEW, EV>> translatedEdges = translateEdgeIds(input.getEdges(), translator, parallelism); // Graph return Graph.fromDataSet(translatedVertices, translatedEdges, input.getContext()); } }
/** * Translate {@link Vertex} and {@link Edge} IDs using the given {@link MapFunction}. * * @param translator implements conversion from {@code K} to {@code NEW} * @param <NEW> new ID type * @return graph with translated vertex and edge IDs * @throws Exception */ public <NEW> Graph<NEW, VV, EV> translateGraphIds(TranslateFunction<K, NEW> translator) throws Exception { return run(new TranslateGraphIds<>(translator)); }
/** * Translate {@link Edge} values using the given {@link TranslateFunction}. * * @param edges input edges * @param translator implements conversion from {@code OLD} to {@code NEW} * @param <K> edge ID type * @param <OLD> old edge value type * @param <NEW> new edge value type * @return translated edges */ public static <K, OLD, NEW> DataSet<Edge<K, NEW>> translateEdgeValues(DataSet<Edge<K, OLD>> edges, TranslateFunction<OLD, NEW> translator) { return translateEdgeValues(edges, translator, PARALLELISM_DEFAULT); }
/** * Translate {@link Vertex} values using the given {@link TranslateFunction}. * * @param vertices input vertices * @param translator implements conversion from {@code OLD} to {@code NEW} * @param <K> vertex ID type * @param <OLD> old vertex value type * @param <NEW> new vertex value type * @return translated vertices */ public static <K, OLD, NEW> DataSet<Vertex<K, NEW>> translateVertexValues(DataSet<Vertex<K, OLD>> vertices, TranslateFunction<OLD, NEW> translator) { return translateVertexValues(vertices, translator, PARALLELISM_DEFAULT); }
/** * Translate {@link Vertex} values using the given {@link MapFunction}. * * @param translator implements conversion from {@code VV} to {@code NEW} * @param <NEW> new vertex value type * @return graph with translated vertex values * @throws Exception */ public <NEW> Graph<K, NEW, EV> translateVertexValues(TranslateFunction<VV, NEW> translator) throws Exception { return run(new TranslateVertexValues<>(translator)); }
/** * Translate {@link Edge} values using the given {@link MapFunction}. * * @param translator implements conversion from {@code EV} to {@code NEW} * @param <NEW> new edge value type * @return graph with translated edge values * @throws Exception */ public <NEW> Graph<K, VV, NEW> translateEdgeValues(TranslateFunction<EV, NEW> translator) throws Exception { return run(new TranslateEdgeValues<>(translator)); }
.map(new TranslateEdgeId<>(translator)) .returns(returnType) .setParallelism(parallelism)
.map(new TranslateEdgeValue<>(translator)) .returns(returnType) .setParallelism(parallelism)
.map(new TranslateVertexId<>(translator)) .returns(returnType) .setParallelism(parallelism)
@Override public Edge<K, NEW> map(Edge<K, OLD> value) throws Exception { edge.f0 = value.f0; edge.f1 = value.f1; edge.f2 = wrappedFunction.translate(value.f2, edge.f2); return edge; } }
@Override public Graph<K, VV, NEW> runInternal(Graph<K, VV, OLD> input) throws Exception { DataSet<Edge<K, NEW>> translatedEdges = translateEdgeValues(input.getEdges(), translator, parallelism); return Graph.fromDataSet(input.getVertices(), translatedEdges, input.getContext()); } }
@Override public Graph<K, NEW, EV> runInternal(Graph<K, OLD, EV> input) throws Exception { DataSet<Vertex<K, NEW>> translatedVertices = translateVertexValues(input.getVertices(), translator, parallelism); return Graph.fromDataSet(translatedVertices, input.getEdges(), input.getContext()); } }
@Override public Vertex<K, NEW> map(Vertex<K, OLD> value) throws Exception { vertex.f0 = value.f0; vertex.f1 = wrappedFunction.translate(value.f1, vertex.f1); return vertex; } }
@Override public <T> TranslatableResult<T> translate(TranslateFunction<K, T> translator, TranslatableResult<T> reuse, Collector<TranslatableResult<T>> out) throws Exception { if (reuse == null) { reuse = new BasicBinaryResult<>(); } K vertexId0 = this.getVertexId0(); K vertexId1 = this.getVertexId1(); BinaryResult<T> translatable = (BinaryResult<T>) reuse; BinaryResult<T> translated = (BinaryResult<T>) this; translated.setVertexId0(translator.translate(this.getVertexId0(), translatable.getVertexId0())); translated.setVertexId1(translator.translate(this.getVertexId1(), translatable.getVertexId1())); out.collect((TranslatableResult<T>) translated); this.setVertexId0(vertexId0); this.setVertexId1(vertexId1); return reuse; }
@Override public <T> TranslatableResult<T> translate(TranslateFunction<K, T> translator, TranslatableResult<T> reuse, Collector<TranslatableResult<T>> out) throws Exception { if (reuse == null) { reuse = new BasicUnaryResult<>(); } K vertexId0 = this.getVertexId0(); UnaryResult<T> translatable = (UnaryResult<T>) reuse; UnaryResult<T> translated = (UnaryResult<T>) this; translated.setVertexId0(translator.translate(this.getVertexId0(), translatable.getVertexId0())); out.collect((TranslatableResult<T>) translated); this.setVertexId0(vertexId0); return reuse; }
@Override public <T> TranslatableResult<T> translate(TranslateFunction<K, T> translator, TranslatableResult<T> reuse, Collector<TranslatableResult<T>> out) throws Exception { if (reuse == null) { reuse = new BasicTertiaryResult<>(); } K vertexId0 = this.getVertexId0(); K vertexId1 = this.getVertexId1(); K vertexId2 = this.getVertexId2(); TertiaryResult<T> translatable = (TertiaryResult<T>) reuse; TertiaryResult<T> translated = (TertiaryResult<T>) this; translated.setVertexId0(translator.translate(this.getVertexId0(), translatable.getVertexId0())); translated.setVertexId1(translator.translate(this.getVertexId1(), translatable.getVertexId1())); translated.setVertexId2(translator.translate(this.getVertexId2(), translatable.getVertexId2())); out.collect((TranslatableResult<T>) translated); this.setVertexId0(vertexId0); this.setVertexId1(vertexId1); this.setVertexId2(vertexId2); return reuse; }