You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by andralungu <gi...@git.apache.org> on 2015/06/07 15:39:24 UTC
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
GitHub user andralungu opened a pull request:
https://github.com/apache/flink/pull/801
[FLINK-2150][gelly] Added library method for assigning unique labels to vertices
This PR adds a library method that assigns unique labels to vertices.
The following facts are used:
* a map function generates an n-bit(n - number of parallel tasks) ID based on its own index
* with each record, a counter c is increased
* the unique label is then produced by shifting the counter c by the n-bit mapper ID
Thanks @fhueske for the useful tips!
And thanks @rmetzger for the nice stackoverflow answer (http://stackoverflow.com/questions/30596556/zipwithindex-on-apache-flink)
If you guys find some spare minutes, you are more than welcome to have a look at what I did here. If not, we'll just let @vasia do what she does best :)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/andralungu/flink generateUniqueIds
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/flink/pull/801.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #801
----
commit d655187a9626be6aca734fdbe035de62e3ead839
Author: andralungu <lu...@gmail.com>
Date: 2015-06-07T13:27:24Z
[FLINK-2150][gelly] Added library method for assigning unique labels to vertcies
----
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-110655024
+1 for adding both methods in a utility class as suggested in FLINK-2152.
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-110654447
I agree, it makes sense to offer that externally.
There is a JIRA for zipWithIndex (FLINK-2152). zipWithUniqueID could be added correspondingly.
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by andralungu <gi...@git.apache.org>.
Github user andralungu commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-110642404
Ooops! My bad. Fixed the log and the ceil issue in the latest update.
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by thvasilo <gi...@git.apache.org>.
Github user thvasilo commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-114132214
Hello, wondering what the status is on this PR
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-110511102
If you reserve 2 bytes of a long for the task id you have 6 bytes left for the counter. This gives you 2^16 partitions, with 2^48 elements per partition. You can also use Strings instead of longs if you are worried about the value range.
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by tillrohrmann <gi...@git.apache.org>.
Github user tillrohrmann commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-110656116
+1 as well.
On Wed, Jun 10, 2015 at 10:38 AM Fabian Hueske <no...@github.com>
wrote:
> +1 for adding both methods in a utility class as suggested in FLINK-2152.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/apache/flink/pull/801#issuecomment-110655024>.
>
---
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.
---
[GitHub] flink pull request: [FLINK-2150] Added zipWithUniqueIds
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/flink/pull/801
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by tillrohrmann <gi...@git.apache.org>.
Github user tillrohrmann commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-110645638
Why only offering this method for Gelly? Can't we generalize the index algorithm for generic types? It could also be useful for the ML library, for example. I'm thinking of something like `zipWithIndex` what is also offered by Spark's API.
---
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.
---
[GitHub] flink pull request: [FLINK-2150] Added zipWithUniqueIds
Posted by vasia <gi...@git.apache.org>.
Github user vasia commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-118164049
Great work @andralungu, +1 from me!
Make sure you squash your commits and appropriately update the commit message before merging ;)
---
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.
---
[GitHub] flink pull request: [FLINK-2150] Added zipWithUniqueIds
Posted by andralungu <gi...@git.apache.org>.
Github user andralungu commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-117112526
Okay, can I get some +1s to merge this :)?
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by tillrohrmann <gi...@git.apache.org>.
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-110276236
Hi Andra,
you approach basically follows @rmetzger 's suggestion which is necessary if you need sequential IDs. However, it comes at the cost of doing two passes over the data and temping the data after the first map because you need to wait for the count before you can assign IDs. Temping data means writing to and reading from disk if you process a lot of data.
My approach won't give sequential IDs but works in a pipelined fashion with a single Mapper and without temping. For each parallel task, you create an ID based on its index and a counter that starts at 0. These are the two components from which a record ID is created by shifting the counter by the number of bits you need for the task ID which is log2 of the number of tasks.
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:
https://github.com/apache/flink/pull/801#discussion_r32067705
--- Diff: flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/library/UniqueLabelAssignmentAlgorithm.java ---
@@ -0,0 +1,92 @@
+/*
+ * 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;
+
+ @Override
+ public void open(Configuration parameters) throws Exception {
+ super.open(parameters);
+ shifter = getRuntimeContext().getIndexOfThisSubtask();
--- End diff --
The number of bits to shift should be the same for all mappers, i.e., log2(numberOfParallelSubtasks()) = n.
You also need a task ID which is are the first n bits of a the subtask index (all other bits should be 0 anyways).
---
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.
---
[GitHub] flink pull request: [FLINK-2150] Added zipWithUniqueIds
Posted by vasia <gi...@git.apache.org>.
Github user vasia commented on a diff in the pull request:
https://github.com/apache/flink/pull/801#discussion_r33820633
--- Diff: docs/apis/zip_elements_guide.md ---
@@ -63,4 +63,44 @@ env.execute()
will yield the tuples: (0,A), (1,B), (2,C), (3,D), (4,E), (5,F)
+[Back to top](#top)
+
+### Zip with an Unique Identifier
+In many cases, one may not need to assign consecutive labels.
+`zipWIthUniqueId` works in a pipelined fashion, speeding up the label assignment process. This method receives a data set as input and returns a new data set of unique id, initial value tuples.
+For example, the following code:
+
+<div class="codetabs" markdown="1">
+<div data-lang="java" markdown="1">
+{% highlight java %}
+ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
+env.setParallelism(1);
+DataSet<String> in = env.fromElements("A", "B", "C", "D", "E", "F");
+
+DataSet<Tuple2<Long, String>> result = DataSetUtils.zipWithUniqueId(in);
+
+result.writeAsCsv(resultPath, "\n", ",");
+env.execute();
+{% endhighlight %}
+</div>
+
+<div data-lang="scala" markdown="1">
+{% highlight scala %}
+import org.apache.flink.api.scala._
+
+val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment
+env.setParallelism(1)
+val input: DataSet[String] = env.fromElements("A", "B", "C", "D", "E", "F")
+
+val result: DataSet[(Long, String)] = input.zipWithUniqueId
+
+result.writeAsCsv(resultPath, "\n", ",")
+env.execute()
+{% endhighlight %}
+</div>
+
+</div>
+
+will yield the tuples: (0,A), (2,B), (4,C), (6,D), (8,E), (10,F)
--- End diff --
is the result deterministic?
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by andralungu <gi...@git.apache.org>.
Github user andralungu commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-110502315
Hi @fhueske ,
To tell the truth, I was a bit reserved regarding your approach, so maybe we can discuss it a bit further! :) I updated the PR to contain what I understood should be done[Tell me if I got it right!].
Now the question is: what happens when you have more than 63 partitions? When you shift, won't you overcome Long 's bounds?
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by tillrohrmann <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] flink pull request: [FLINK-2150] Added zipWithUniqueIds
Posted by andralungu <gi...@git.apache.org>.
Github user andralungu commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-118171270
Merging...
---
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.
---
[GitHub] flink pull request: [FLINK-2150] Added zipWithUniqueIds
Posted by thvasilo <gi...@git.apache.org>.
Github user thvasilo commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-116312912
Thanks, Andra. I guess #832 is actually more related to what we want for FlinkML, but it's great to see these progressing, we'll definitely be using them as soon as they are merged.
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by andralungu <gi...@git.apache.org>.
Github user andralungu commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-110520392
I think I got it! Have a look now :)
---
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.
---
[GitHub] flink pull request: [FLINK-2150] Added zipWithUniqueIds
Posted by andralungu <gi...@git.apache.org>.
Github user andralungu commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-116287334
Hi @thvasilo ,
Sorry for the late reply... I stated in the `zipWithIndex` PR that I am waiting for that to be merged before I update this one :). So, here it is!
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:
https://github.com/apache/flink/pull/801#discussion_r32067943
--- Diff: flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/library/UniqueLabelAssignmentAlgorithm.java ---
@@ -0,0 +1,92 @@
+/*
+ * 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;
+
+ @Override
+ public void open(Configuration parameters) throws Exception {
+ super.open(parameters);
+ shifter = getRuntimeContext().getIndexOfThisSubtask();
+ }
+
+ @Override
+ public void mapPartition(Iterable<Vertex<String, Long>> vertices,
+ Collector<Tuple2<String, Long>> out) throws Exception {
+
+ for(Vertex<String, Long> v: vertices) {
+ out.collect(new Tuple2<String, Long>(v.getId(), start << shifter));
--- End diff --
After shifting the count by n bits, you need to set the first n bits to the task ID (of n bit length).
You might want to add a check, that you stay within long's value range.
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by tillrohrmann <gi...@git.apache.org>.
Github user tillrohrmann commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-110653949
If I'm not mistaken then something like
```
int log2(long value){
if(value & 0xffffffff00000000 > 0) {
64 - Integer.numberOfLeadingZeros((int)(value >> 32))
} else {
32 - Integer.numberOfLeadingZeros((int)value)
}
}
```
should do the trick.
For the generalization I think something like `dataSet.zipWithID()` with
```
class DataSet<T> {
public DataSet<Tuple2<Long, T>> zipWithID() {}
}
```
would be nice. But we should discuss it on the mailing list whether we want this to be part of the API or not. For the beginning, it could be added to some kind of utils class.
---
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.
---
[GitHub] flink pull request: [FLINK-2150][gelly] Added library method for a...
Posted by andralungu <gi...@git.apache.org>.
Github user andralungu commented on the pull request:
https://github.com/apache/flink/pull/801#issuecomment-110647258
Hi @tillrohrmann ,
For the log2 part, you mean something like this: ceil(log2(x)) = 32 - numberOfLeadingZeros(x - 1)? 32 because it's int, in this case it should be 64...
I started with gelly because I thought it would be nice to first break stuff in my own part of the woods :). I am in favour of generalising. What should we change for that?
---
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.
---