flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tillrohrmann <...@git.apache.org>
Subject [GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Date Wed, 10 Jun 2015 08:10:55 GMT
Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/801#discussion_r32096112
  
    --- 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));
    --- End diff --
    
    Why using floating point arithmetic when we deal with integer values? This can only lead
to errors because of rounding errors. Better to use something like `Integer.numberOfLeadingZeros()`.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message