Search in sources :

Example 1 with LongValue

use of org.apache.flink.types.LongValue in project flink by apache.

the class SingletonEdgeGraph method generate.

@Override
public Graph<LongValue, NullValue, NullValue> generate() {
    // Vertices
    long vertexCount = 2 * this.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);
}
Also used : LongValueSequenceIterator(org.apache.flink.util.LongValueSequenceIterator) Vertex(org.apache.flink.graph.Vertex) LongValue(org.apache.flink.types.LongValue) Edge(org.apache.flink.graph.Edge)

Example 2 with LongValue

use of org.apache.flink.types.LongValue in project flink by apache.

the class StarGraph method generate.

@Override
public Graph<LongValue, NullValue, NullValue> generate() {
    // Vertices
    DataSet<Vertex<LongValue, NullValue>> vertices = GraphGeneratorUtils.vertexSequence(env, parallelism, vertexCount);
    // Edges
    LongValueSequenceIterator iterator = new LongValueSequenceIterator(1, this.vertexCount - 1);
    DataSet<Edge<LongValue, NullValue>> edges = env.fromParallelCollection(iterator, LongValue.class).setParallelism(parallelism).name("Edge iterators").flatMap(new LinkVertexToCenter()).setParallelism(parallelism).name("Star graph edges");
    // Graph
    return Graph.fromDataSet(vertices, edges, env);
}
Also used : LongValueSequenceIterator(org.apache.flink.util.LongValueSequenceIterator) Vertex(org.apache.flink.graph.Vertex) LongValue(org.apache.flink.types.LongValue) Edge(org.apache.flink.graph.Edge)

Example 3 with LongValue

use of org.apache.flink.types.LongValue in project flink by apache.

the class GatherSumApplyITCase method testConnectedComponentsWithObjectReuseEnabled.

@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<LongValue>(), env);
    List<Vertex<LongValue, LongValue>> result = inputGraph.run(new GSAConnectedComponents<LongValue, LongValue, NullValue>(16)).collect();
    compareResultAsTuples(result, expectedResultCC);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) NullValue(org.apache.flink.types.NullValue) LongToLongValue(org.apache.flink.graph.asm.translate.translators.LongToLongValue) LongValue(org.apache.flink.types.LongValue) LongToLongValue(org.apache.flink.graph.asm.translate.translators.LongToLongValue) GSAConnectedComponents(org.apache.flink.graph.library.GSAConnectedComponents) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 4 with LongValue

use of org.apache.flink.types.LongValue in project flink by apache.

the class ScatterGatherIteration method createResult.

/**
	 * Creates the operator that represents this scatter-gather graph computation.
	 * 
	 * @return The operator that represents this scatter-gather graph computation.
	 */
@Override
public DataSet<Vertex<K, VV>> createResult() {
    if (this.initialVertices == null) {
        throw new IllegalStateException("The input data set has not been set.");
    }
    // prepare some type information
    TypeInformation<K> keyType = ((TupleTypeInfo<?>) initialVertices.getType()).getTypeAt(0);
    TypeInformation<Tuple2<K, Message>> messageTypeInfo = new TupleTypeInfo<>(keyType, messageType);
    // create a graph
    Graph<K, VV, EV> graph = Graph.fromDataSet(initialVertices, edgesWithValue, initialVertices.getExecutionEnvironment());
    // check whether the numVertices option is set and, if so, compute the total number of vertices
    // and set it within the scatter and gather functions
    DataSet<LongValue> numberOfVertices = null;
    if (this.configuration != null && this.configuration.isOptNumVertices()) {
        try {
            numberOfVertices = GraphUtils.count(this.initialVertices);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (this.configuration != null) {
        scatterFunction.setDirection(this.configuration.getDirection());
    } else {
        scatterFunction.setDirection(EdgeDirection.OUT);
    }
    // retrieve the direction in which the updates are made and in which the messages are sent
    EdgeDirection messagingDirection = scatterFunction.getDirection();
    // add them to the vertex value
    if (this.configuration != null && this.configuration.isOptDegrees()) {
        return createResultVerticesWithDegrees(graph, messagingDirection, messageTypeInfo, numberOfVertices);
    } else {
        return createResultSimpleVertex(messagingDirection, messageTypeInfo, numberOfVertices);
    }
}
Also used : EdgeDirection(org.apache.flink.graph.EdgeDirection) TupleTypeInfo(org.apache.flink.api.java.typeutils.TupleTypeInfo) Tuple2(org.apache.flink.api.java.tuple.Tuple2) LongValue(org.apache.flink.types.LongValue)

Example 5 with LongValue

use of org.apache.flink.types.LongValue in project flink by apache.

the class VertexInDegreeTest method testWithRMatGraph.

@Test
public void testWithRMatGraph() throws Exception {
    DataSet<Vertex<LongValue, LongValue>> inDegree = directedRMatGraph.run(new VertexInDegree<LongValue, NullValue, NullValue>().setIncludeZeroDegreeVertices(true));
    Checksum checksum = new ChecksumHashCode<Vertex<LongValue, LongValue>>().run(inDegree).execute();
    assertEquals(902, checksum.getCount());
    assertEquals(0x0000000000e1d885L, checksum.getChecksum());
}
Also used : Vertex(org.apache.flink.graph.Vertex) Checksum(org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum) LongValue(org.apache.flink.types.LongValue) ChecksumHashCode(org.apache.flink.graph.asm.dataset.ChecksumHashCode) Test(org.junit.Test)

Aggregations

LongValue (org.apache.flink.types.LongValue)50 Test (org.junit.Test)33 NullValue (org.apache.flink.types.NullValue)23 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)17 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)15 Edge (org.apache.flink.graph.Edge)13 StringValue (org.apache.flink.types.StringValue)13 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)12 Vertex (org.apache.flink.graph.Vertex)11 IntValue (org.apache.flink.types.IntValue)9 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)7 JDKRandomGeneratorFactory (org.apache.flink.graph.generator.random.JDKRandomGeneratorFactory)7 NumberFormat (java.text.NumberFormat)6 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)6 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)6 ParameterTool (org.apache.flink.api.java.utils.ParameterTool)6 ProgramParametrizationException (org.apache.flink.client.program.ProgramParametrizationException)6 RMatGraph (org.apache.flink.graph.generator.RMatGraph)6 Graph (org.apache.flink.graph.Graph)5 GraphCsvReader (org.apache.flink.graph.GraphCsvReader)5