This is an automated email from the ASF dual-hosted git repository.
sjwiesman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new 98ed08b [hotfix][util] fix partition utility
98ed08b is described below
commit 98ed08b8dbe52b7465409b6e437f0d1bbb88ec08
Author: Seth Wiesman <[email protected]>
AuthorDate: Wed Dec 16 08:59:55 2020 -0600
[hotfix][util] fix partition utility
This closes #14408
---
.../java/org/apache/flink/util/CollectionUtil.java | 1 +
.../org/apache/flink/util/CollectionUtilTest.java | 43 ++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
b/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
index 2a52efe..1a652a2 100644
--- a/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
+++ b/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
@@ -75,6 +75,7 @@ public final class CollectionUtil {
for (T element : elements) {
int bucket = index % numBuckets;
buckets.computeIfAbsent(bucket, key -> new
ArrayList<>(initialCapacity)).add(element);
+ index++;
}
return buckets.values();
diff --git
a/flink-core/src/test/java/org/apache/flink/util/CollectionUtilTest.java
b/flink-core/src/test/java/org/apache/flink/util/CollectionUtilTest.java
new file mode 100644
index 0000000..5a8abff
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/util/CollectionUtilTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Tests for java collection utilities.
+ */
+public class CollectionUtilTest {
+
+ @Test
+ public void testPartition() {
+ List<Integer> list = Arrays.asList(1, 2, 3, 4);
+ Collection<List<Integer>> partitioned =
CollectionUtil.partition(list, 4);
+
+ Assert.assertEquals("List partitioned into the an incorrect
number of partitions", 4, partitioned.size());
+ for (List<Integer> partition : partitioned) {
+ Assert.assertEquals("Unexpected number of elements in
partition", 1, partition.size());
+ }
+ }
+}