org.apache.flink.graph.Edge Java Examples
The following examples show how to use
org.apache.flink.graph.Edge.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphOperationsITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@SuppressWarnings("serial") @Test public void testFilterVertices() throws Exception { /* * Test filterOnVertices: */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env); DataSet<Edge<Long, Long>> data = graph.filterOnVertices(new FilterFunction<Vertex<Long, Long>>() { public boolean filter(Vertex<Long, Long> vertex) throws Exception { return (vertex.getValue() > 2); } }).getEdges(); List<Edge<Long, Long>> result = data.collect(); expectedResult = "3,4,34\n" + "3,5,35\n" + "4,5,45\n"; compareResultAsTuples(result, expectedResult); }
Example #2
Source File: MapEdgesITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithTuple1Type() throws Exception { /* * Test mapEdges() and change the value type to a Tuple1 */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env); DataSet<Edge<Long, Tuple1<Long>>> mappedEdges = graph.mapEdges(new ToTuple1Mapper()).getEdges(); List<Edge<Long, Tuple1<Long>>> result = mappedEdges.collect(); expectedResult = "1,2,(12)\n" + "1,3,(13)\n" + "2,3,(23)\n" + "3,4,(34)\n" + "3,5,(35)\n" + "4,5,(45)\n" + "5,1,(51)\n"; compareResultAsTuples(result, expectedResult); }
Example #3
Source File: GatherSumApplyITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testConnectedComponentsWithObjectReuseEnabled() throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.getConfig().enableObjectReuse(); DataSet<Edge<LongValue, NullValue>> edges = Translate.translateEdgeIds( ConnectedComponentsDefaultData.getDefaultEdgeDataSet(env), new LongToLongValue()); Graph<LongValue, LongValue, NullValue> inputGraph = Graph.fromDataSet( edges, new IdentityMapper<>(), env); List<Vertex<LongValue, LongValue>> result = inputGraph.run( new GSAConnectedComponents<>(16)).collect(); compareResultAsTuples(result, expectedResultCC); }
Example #4
Source File: MapEdgesITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithStringValue() throws Exception { /* * Test mapEdges() and change the value type to String */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env); DataSet<Edge<Long, String>> mappedEdges = graph.mapEdges(new ToStringMapper()).getEdges(); List<Edge<Long, String>> result = mappedEdges.collect(); expectedResult = "1,2,string(12)\n" + "1,3,string(13)\n" + "2,3,string(23)\n" + "3,4,string(34)\n" + "3,5,string(35)\n" + "4,5,string(45)\n" + "5,1,string(51)\n"; compareResultAsTuples(result, expectedResult); }
Example #5
Source File: EdgeDegreesPairTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraph() throws Exception { String expectedResult = "(0,1,((null),(2,2,0),(3,0,3)))\n" + "(0,2,((null),(2,2,0),(3,2,1)))\n" + "(2,1,((null),(3,2,1),(3,0,3)))\n" + "(2,3,((null),(3,2,1),(4,2,2)))\n" + "(3,1,((null),(4,2,2),(3,0,3)))\n" + "(3,4,((null),(4,2,2),(1,0,1)))\n" + "(5,3,((null),(1,1,0),(4,2,2)))"; DataSet<Edge<IntValue, Tuple3<NullValue, Degrees, Degrees>>> degreesPair = directedSimpleGraph .run(new EdgeDegreesPair<>()); TestBaseUtils.compareResultAsText(degreesPair.collect(), expectedResult); }
Example #6
Source File: JoinWithEdgesITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testOnSourceWithCustom() throws Exception { /* * Test joinWithEdgesOnSource with a DataSet containing custom parametrised type input values */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env); Graph<Long, Long, Long> res = graph.joinWithEdgesOnSource(TestGraphUtils.getLongCustomTuple2SourceData(env), new CustomValueMapper()); DataSet<Edge<Long, Long>> data = res.getEdges(); List<Edge<Long, Long>> result = data.collect(); expectedResult = "1,2,10\n" + "1,3,10\n" + "2,3,30\n" + "3,4,40\n" + "3,5,40\n" + "4,5,45\n" + "5,1,51\n"; compareResultAsTuples(result, expectedResult); }
Example #7
Source File: EuclideanGraphData.java From flink with Apache License 2.0 | 6 votes |
public static DataSet<Edge<Long, Double>> getDefaultEdgeDataSet(ExecutionEnvironment env) { List<Edge<Long, Double>> edges = new ArrayList<>(); edges.add(new Edge<>(1L, 2L, 0.0)); edges.add(new Edge<>(1L, 4L, 0.0)); edges.add(new Edge<>(2L, 3L, 0.0)); edges.add(new Edge<>(2L, 4L, 0.0)); edges.add(new Edge<>(2L, 5L, 0.0)); edges.add(new Edge<>(3L, 5L, 0.0)); edges.add(new Edge<>(4L, 5L, 0.0)); edges.add(new Edge<>(4L, 6L, 0.0)); edges.add(new Edge<>(5L, 7L, 0.0)); edges.add(new Edge<>(5L, 9L, 0.0)); edges.add(new Edge<>(6L, 7L, 0.0)); edges.add(new Edge<>(6L, 8L, 0.0)); edges.add(new Edge<>(6L, 8L, 0.0)); edges.add(new Edge<>(7L, 8L, 0.0)); edges.add(new Edge<>(7L, 9L, 0.0)); edges.add(new Edge<>(8L, 9L, 0.0)); return env.fromCollection(edges); }
Example #8
Source File: TriangleEnumerator.java From flink with Apache License 2.0 | 6 votes |
@Override public void reduce(Iterable<Edge<K, NullValue>> edgesIter, Collector<Triad<K>> out) throws Exception { final Iterator<Edge<K, NullValue>> edges = edgesIter.iterator(); // clear vertex list vertices.clear(); // read first edge Edge<K, NullValue> firstEdge = edges.next(); outTriad.setFirstVertex(firstEdge.getSource()); vertices.add(firstEdge.getTarget()); // build and emit triads while (edges.hasNext()) { K higherVertexId = edges.next().getTarget(); // combine vertex with all previously read vertices for (K lowerVertexId : vertices) { outTriad.setSecondVertex(lowerVertexId); outTriad.setThirdVertex(higherVertexId); out.collect(outTriad); } vertices.add(higherVertexId); } }
Example #9
Source File: JoinWithEdgesITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testOnTargetWithCustom() throws Exception { /* * Test joinWithEdgesOnTarget with a DataSet containing custom parametrised type input values */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env); Graph<Long, Long, Long> res = graph.joinWithEdgesOnTarget(TestGraphUtils.getLongCustomTuple2TargetData(env), new CustomValueMapper()); DataSet<Edge<Long, Long>> data = res.getEdges(); List<Edge<Long, Long>> result = data.collect(); expectedResult = "1,2,10\n" + "1,3,20\n" + "2,3,20\n" + "3,4,40\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n"; compareResultAsTuples(result, expectedResult); }
Example #10
Source File: EdgeMetrics.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public Tuple3<T, LongValue, LongValue> map(Edge<T, Tuple3<ET, LongValue, LongValue>> edge) throws Exception { Tuple3<ET, LongValue, LongValue> degrees = edge.f2; output.f0 = edge.f0; output.f1 = degrees.f1; long sourceDegree = degrees.f1.getValue(); long targetDegree = degrees.f2.getValue(); if (sourceDegree < targetDegree || (sourceDegree == targetDegree && edge.f0.compareTo(edge.f1) < 0)) { output.f2 = one; } else { output.f2 = zero; } return output; }
Example #11
Source File: BipartitenessCheckTest.java From gelly-streaming with Apache License 2.0 | 6 votes |
@Test public void testBipartite() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(1); //needed to ensure total ordering for windows CollectSink.values.clear(); DataStream<Edge<Long, NullValue>> edges = env.fromCollection(getBipartiteEdges()); GraphStream<Long, NullValue, NullValue> graph = new SimpleEdgeStream<>(edges, env); graph .aggregate(new BipartitenessCheck<>((long) 500)) .addSink(new CollectSink()); env.execute("Bipartiteness check"); // verify the results assertEquals(Lists.newArrayList( "(true,{1={1=(1,true), 2=(2,false), 3=(3,false), 4=(4,false), 5=(5,true), 7=(7,true), 9=(9,true)}})"), CollectSink.values); }
Example #12
Source File: BipartitenessCheckTest.java From gelly-streaming with Apache License 2.0 | 6 votes |
@Test public void testNonBipartite() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(1); CollectSink.values.clear(); DataStream<Edge<Long, NullValue>> edges = env.fromCollection(getNonBipartiteEdges()); GraphStream<Long, NullValue, NullValue> graph = new SimpleEdgeStream<>(edges, env); graph. aggregate(new BipartitenessCheck<>((long) 500)) .addSink(new CollectSink()); env.execute("Non Bipartiteness check"); // verify the results assertEquals(Lists.newArrayList( "(false,{})"), CollectSink.values); }
Example #13
Source File: SummarizationITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithVertexAndEdgeStringValues() throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, String, String> input = Graph.fromDataSet( SummarizationData.getVertices(env), SummarizationData.getEdges(env), env); List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>(); List<Edge<Long, EdgeValue<String>>> summarizedEdges = new ArrayList<>(); Graph<Long, Summarization.VertexValue<String>, EdgeValue<String>> output = input.run(new Summarization<>()); output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices)); output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges)); env.execute(); validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices); validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges); }
Example #14
Source File: SummarizationITCase.java From flink with Apache License 2.0 | 6 votes |
private <EV extends Comparable<EV>> void validateEdges(String[] expectedEdges, List<Edge<Long, EdgeValue<EV>>> actualEdges) { Arrays.sort(expectedEdges); Collections.sort(actualEdges, new Comparator<Edge<Long, EdgeValue<EV>>> () { @Override public int compare(Edge<Long, EdgeValue<EV>> o1, Edge<Long, EdgeValue<EV>> o2) { int result = o1.getSource().compareTo(o2.getSource()); if (result == 0) { result = o1.getTarget().compareTo(o2.getTarget()); } if (result == 0) { result = o1.getValue().getEdgeGroupValue().compareTo(o2.getValue().getEdgeGroupValue()); } return result; } }); for (int i = 0; i < expectedEdges.length; i++) { validateEdge(expectedEdges[i], actualEdges.get(i)); } }
Example #15
Source File: SummarizationITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithVertexAndEdgeStringValues() throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, String, String> input = Graph.fromDataSet( SummarizationData.getVertices(env), SummarizationData.getEdges(env), env); List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>(); List<Edge<Long, EdgeValue<String>>> summarizedEdges = new ArrayList<>(); Graph<Long, Summarization.VertexValue<String>, EdgeValue<String>> output = input.run(new Summarization<>()); output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices)); output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges)); env.execute(); validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices); validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges); }
Example #16
Source File: SummarizationITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithVertexAndAbsentEdgeStringValues() throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, String, NullValue> input = Graph.fromDataSet( SummarizationData.getVertices(env), SummarizationData.getEdges(env), env) .run(new TranslateEdgeValues<>(new ToNullValue<>())); List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>(); List<Edge<Long, EdgeValue<NullValue>>> summarizedEdges = new ArrayList<>(); Graph<Long, Summarization.VertexValue<String>, EdgeValue<NullValue>> output = input.run(new Summarization<>()); output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices)); output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges)); env.execute(); validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices); validateEdges(SummarizationData.EXPECTED_EDGES_ABSENT_VALUES, summarizedEdges); }
Example #17
Source File: SingletonEdgeGraph.java From flink with Apache License 2.0 | 6 votes |
@Override public Graph<LongValue, NullValue, NullValue> generate() { Preconditions.checkState(vertexPairCount > 0); // Vertices long vertexCount = 2 * vertexPairCount; DataSet<Vertex<LongValue, NullValue>> vertices = GraphGeneratorUtils.vertexSequence(env, parallelism, vertexCount); // Edges LongValueSequenceIterator iterator = new LongValueSequenceIterator(0, vertexCount - 1); DataSet<Edge<LongValue, NullValue>> edges = env .fromParallelCollection(iterator, LongValue.class) .setParallelism(parallelism) .name("Edge iterators") .map(new LinkVertexToSingletonNeighbor()) .setParallelism(parallelism) .name("Complete graph edges"); // Graph return Graph.fromDataSet(vertices, edges, env); }
Example #18
Source File: GraphMutationsITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testRemoveVertices() throws Exception { /* * Test removeVertices() -- simple case */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env); List<Vertex<Long, Long>> verticesToBeRemoved = new ArrayList<>(); verticesToBeRemoved.add(new Vertex<>(1L, 1L)); verticesToBeRemoved.add(new Vertex<>(2L, 2L)); graph = graph.removeVertices(verticesToBeRemoved); DataSet<Edge<Long, Long>> data = graph.getEdges(); List<Edge<Long, Long>> result = data.collect(); expectedResult = "3,4,34\n" + "3,5,35\n" + "4,5,45\n"; compareResultAsTuples(result, expectedResult); }
Example #19
Source File: GraphMutationsITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testRemoveVertex() throws Exception { /* * Test removeVertex() -- simple case */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env); graph = graph.removeVertex(new Vertex<>(5L, 5L)); DataSet<Edge<Long, Long>> data = graph.getEdges(); List<Edge<Long, Long>> result = data.collect(); expectedResult = "1,2,12\n" + "1,3,13\n" + "2,3,23\n" + "3,4,34\n"; compareResultAsTuples(result, expectedResult); }
Example #20
Source File: GridGraph.java From flink with Apache License 2.0 | 6 votes |
@Override public Graph<LongValue, NullValue, NullValue> generate() { Preconditions.checkState(!dimensions.isEmpty(), "No dimensions added to GridGraph"); // Vertices DataSet<Vertex<LongValue, NullValue>> vertices = GraphGeneratorUtils.vertexSequence(env, parallelism, vertexCount); // Edges LongValueSequenceIterator iterator = new LongValueSequenceIterator(0, this.vertexCount - 1); DataSet<Edge<LongValue, NullValue>> edges = env .fromParallelCollection(iterator, LongValue.class) .setParallelism(parallelism) .name("Edge iterators") .flatMap(new LinkVertexToNeighbors(vertexCount, dimensions)) .setParallelism(parallelism) .name("Grid graph edges"); // Graph return Graph.fromDataSet(vertices, edges, env); }
Example #21
Source File: BipartiteGraph.java From flink with Apache License 2.0 | 6 votes |
@Override public void join(Tuple5<KT, KB, EV, VVT, VVB> first, Tuple5<KT, KB, EV, VVT, VVB> second, Collector<Edge<KB, Projection<KT, VVT, VVB, EV>>> out) throws Exception { if (!first.f1.equals(second.f1)) { edge.f0 = first.f1; edge.f1 = second.f1; projection.f0 = first.f0; projection.f1 = first.f3; projection.f2 = first.f4; projection.f3 = second.f4; projection.f4 = first.f2; projection.f5 = second.f2; out.collect(edge); } }
Example #22
Source File: MapEdgesITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithSameValue() throws Exception { /* * Test mapEdges() keeping the same value type */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env); DataSet<Edge<Long, Long>> mappedEdges = graph.mapEdges(new AddOneMapper()).getEdges(); List<Edge<Long, Long>> result = mappedEdges.collect(); expectedResult = "1,2,13\n" + "1,3,14\n" + "2,3,24\n" + "3,4,35\n" + "3,5,36\n" + "4,5,46\n" + "5,1,52\n"; compareResultAsTuples(result, expectedResult); }
Example #23
Source File: TriangleEnumerator.java From flink with Apache License 2.0 | 6 votes |
@Override public Edge<K, NullValue> map(EdgeWithDegrees<K> inEdge) throws Exception { // copy vertices to simple edge outEdge.setSource(inEdge.getFirstVertex()); outEdge.setTarget(inEdge.getSecondVertex()); outEdge.setValue(NullValue.getInstance()); // flip vertices if first degree is larger than second degree. if (inEdge.getFirstDegree() > inEdge.getSecondDegree()) { outEdge = outEdge.reverse(); } // return edge return outEdge; }
Example #24
Source File: EdgeDegreesPairTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraph() throws Exception { String expectedResult = "(0,1,((null),(2,2,0),(3,0,3)))\n" + "(0,2,((null),(2,2,0),(3,2,1)))\n" + "(2,1,((null),(3,2,1),(3,0,3)))\n" + "(2,3,((null),(3,2,1),(4,2,2)))\n" + "(3,1,((null),(4,2,2),(3,0,3)))\n" + "(3,4,((null),(4,2,2),(1,0,1)))\n" + "(5,3,((null),(1,1,0),(4,2,2)))"; DataSet<Edge<IntValue, Tuple3<NullValue, Degrees, Degrees>>> degreesPair = directedSimpleGraph .run(new EdgeDegreesPair<>()); TestBaseUtils.compareResultAsText(degreesPair.collect(), expectedResult); }
Example #25
Source File: EdgeTargetDegreesTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraph() throws Exception { String expectedResult = "(0,1,((null),(3,0,3)))\n" + "(0,2,((null),(3,2,1)))\n" + "(2,1,((null),(3,0,3)))\n" + "(2,3,((null),(4,2,2)))\n" + "(3,1,((null),(3,0,3)))\n" + "(3,4,((null),(1,0,1)))\n" + "(5,3,((null),(4,2,2)))"; DataSet<Edge<IntValue, Tuple2<NullValue, Degrees>>> targetDegrees = directedSimpleGraph .run(new EdgeTargetDegrees<>()); TestBaseUtils.compareResultAsText(targetDegrees.collect(), expectedResult); }
Example #26
Source File: GraphMutationsITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testRemoveVertices() throws Exception { /* * Test removeVertices() -- simple case */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env); List<Vertex<Long, Long>> verticesToBeRemoved = new ArrayList<>(); verticesToBeRemoved.add(new Vertex<>(1L, 1L)); verticesToBeRemoved.add(new Vertex<>(2L, 2L)); graph = graph.removeVertices(verticesToBeRemoved); DataSet<Edge<Long, Long>> data = graph.getEdges(); List<Edge<Long, Long>> result = data.collect(); expectedResult = "3,4,34\n" + "3,5,35\n" + "4,5,45\n"; compareResultAsTuples(result, expectedResult); }
Example #27
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 5 votes |
@Override public void iterateEdges(Iterable<Tuple2<Long, Edge<Long, Long>>> edges, Collector<Tuple2<Long, Long>> out) throws Exception { for (Tuple2<Long, Edge<Long, Long>> edge : edges) { if (edge.f0 != 5) { out.collect(new Tuple2<>(edge.f0, edge.f1.getSource())); } } }
Example #28
Source File: ReduceOnNeighborMethodsITCase.java From flink with Apache License 2.0 | 5 votes |
@Override public void iterateNeighbors(Iterable<Tuple3<Long, Edge<Long, Long>, Vertex<Long, Long>>> neighbors, Collector<Tuple2<Long, Long>> out) throws Exception { long sum = 0; Tuple3<Long, Edge<Long, Long>, Vertex<Long, Long>> next = null; for (Tuple3<Long, Edge<Long, Long>, Vertex<Long, Long>> neighbor : neighbors) { next = neighbor; sum += next.f2.getValue() * next.f1.getValue(); } if (next.f0 > 2) { out.collect(new Tuple2<>(next.f0, sum)); out.collect(new Tuple2<>(next.f0, sum * 2)); } }
Example #29
Source File: IncrementalSSSPData.java From flink with Apache License 2.0 | 5 votes |
public static final DataSet<Edge<Long, Double>> getDefaultEdgesInSSSP(ExecutionEnvironment env) { List<Edge<Long, Double>> edges = new ArrayList<>(); edges.add(new Edge<>(1L, 3L, 3.0)); edges.add(new Edge<>(2L, 5L, 2.0)); edges.add(new Edge<>(3L, 2L, 1.0)); edges.add(new Edge<>(4L, 5L, 1.0)); return env.fromCollection(edges); }
Example #30
Source File: JoinWithEdgesITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testWithOnTargetWithLessElements() throws Exception { /* * Test joinWithEdgesOnTarget with the input DataSet passed as a parameter containing * less elements than the edge DataSet, but of the same type */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env); Graph<Long, Long, Long> res = graph.joinWithEdgesOnTarget(graph.getEdges().first(3) .map(new ProjectTargetAndValueMapper()), new AddValuesMapper()); DataSet<Edge<Long, Long>> data = res.getEdges(); List<Edge<Long, Long>> result = data.collect(); expectedResult = "1,2,24\n" + "1,3,26\n" + "2,3,36\n" + "3,4,34\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n"; compareResultAsTuples(result, expectedResult); }