Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/801#discussion_r32096127
  
    --- Diff: 
flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/library/UniqueLabelAssignmentAlgorithm.java
 ---
    @@ -0,0 +1,101 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.flink.graph.library;
    +
    +import org.apache.flink.api.common.functions.MapFunction;
    +import org.apache.flink.api.common.functions.RichMapPartitionFunction;
    +import org.apache.flink.api.java.DataSet;
    +import org.apache.flink.api.java.tuple.Tuple2;
    +import org.apache.flink.configuration.Configuration;
    +import org.apache.flink.graph.Graph;
    +import org.apache.flink.graph.GraphAlgorithm;
    +import org.apache.flink.graph.Vertex;
    +import org.apache.flink.types.NullValue;
    +import org.apache.flink.util.Collector;
    +
    +/**
    + * Unique Label Assignment Algorithm.
    + *
    + * This library method initializes the vertex values with unique Long 
labels by making use of the
    + * following abstractions:
    + * <ul>
    + *         <li> a map function generates an n-bit(n - number of parallel 
tasks) ID based on its own index
    + *         <li> with each record, a counter c is increased
    + *         <li> the unique label is then produced by shifting the counter 
c by the n-bit mapper ID
    + * </ul>
    + */
    +public class UniqueLabelAssignmentAlgorithm implements 
GraphAlgorithm<String, Long, NullValue> {
    +
    +   /**
    +    * @param vertices the data set of graph vertices
    +    * @return a data set of Tuple2 containing the vertex ID and its unique 
Long label
    +    */
    +   private DataSet<Tuple2<String, Long>> 
assignLabels(DataSet<Vertex<String, Long>> vertices) {
    +
    +           return vertices.mapPartition(new 
RichMapPartitionFunction<Vertex<String, Long>,
    +                           Tuple2<String, Long>>() {
    +
    +                   long shifter = 0;
    +                   long start = 0;
    +                   long taskId = 0;
    +                   long label = 0;
    +
    +                   @Override
    +                   public void open(Configuration parameters) throws 
Exception {
    +                           super.open(parameters);
    +                           shifter = (long) 
Math.ceil(Math.log(getRuntimeContext().getNumberOfParallelSubtasks())/Math.log(2));
    +                           taskId = 
getRuntimeContext().getIndexOfThisSubtask();
    +                   }
    +
    +                   @Override
    +                   public void mapPartition(Iterable<Vertex<String, Long>> 
vertices,
    +                                                                   
Collector<Tuple2<String, Long>> out) throws Exception {
    +
    +                           for(Vertex<String, Long> v: vertices) {
    +                                   label = start << shifter + taskId;
    +
    +                                   if (Math.log(start)/Math.log(2) + 
shifter < Math.log(Long.MAX_VALUE)/Math.log(2)) {
    --- End diff --
    
    Same here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to