flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject flink git commit: [FLINK-2090] [core] Truncate 'toString()' of CollectionInputFormat when the collection is huge
Date Tue, 09 Aug 2016 13:34:31 GMT
Repository: flink
Updated Branches:
  refs/heads/master 46b427fac -> b5d58934d


[FLINK-2090] [core] Truncate 'toString()' of CollectionInputFormat when the collection is
huge

This closes #2323


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/b5d58934
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/b5d58934
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/b5d58934

Branch: refs/heads/master
Commit: b5d58934d7124e0076e588e74485a60e7c1f484b
Parents: 46b427f
Author: Ivan Mushketyk <ivan.mushketik@gmail.com>
Authored: Mon Aug 1 20:39:17 2016 +0100
Committer: Stephan Ewen <sewen@apache.org>
Committed: Tue Aug 9 15:34:01 2016 +0200

----------------------------------------------------------------------
 .../api/java/io/CollectionInputFormat.java      | 19 +++++++++-
 .../api/java/io/CollectionInputFormatTest.java  | 39 +++++++++++++++++++-
 2 files changed, 56 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/b5d58934/flink-java/src/main/java/org/apache/flink/api/java/io/CollectionInputFormat.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/io/CollectionInputFormat.java
b/flink-java/src/main/java/org/apache/flink/api/java/io/CollectionInputFormat.java
index 0dad9e3..90e6712 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/io/CollectionInputFormat.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/io/CollectionInputFormat.java
@@ -41,6 +41,7 @@ import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
 public class CollectionInputFormat<T> extends GenericInputFormat<T> implements
NonParallelInput {
 
 	private static final long serialVersionUID = 1L;
+	private static final int MAX_TO_STRING_LEN = 100;
 
 	private TypeSerializer<T> serializer;
 
@@ -117,7 +118,23 @@ public class CollectionInputFormat<T> extends GenericInputFormat<T>
implements N
 	
 	@Override
 	public String toString() {
-		return this.dataSet.toString();
+		StringBuilder sb = new StringBuilder();
+		sb.append('[');
+
+		int num = 0;
+		for (T e : dataSet) {
+			sb.append(e);
+			if (num != dataSet.size() - 1) {
+				sb.append(", ");
+				if (sb.length() > MAX_TO_STRING_LEN) {
+					sb.append("...");
+					break;
+				}
+			}
+			num++;
+		}
+		sb.append(']');
+		return sb.toString();
 	}
 	
 	// --------------------------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/flink/blob/b5d58934/flink-java/src/test/java/org/apache/flink/api/java/io/CollectionInputFormatTest.java
----------------------------------------------------------------------
diff --git a/flink-java/src/test/java/org/apache/flink/api/java/io/CollectionInputFormatTest.java
b/flink-java/src/test/java/org/apache/flink/api/java/io/CollectionInputFormatTest.java
index 53523b0..3bb40eb 100644
--- a/flink-java/src/test/java/org/apache/flink/api/java/io/CollectionInputFormatTest.java
+++ b/flink-java/src/test/java/org/apache/flink/api/java/io/CollectionInputFormatTest.java
@@ -76,6 +76,13 @@ public class CollectionInputFormatTest {
 		public int hashCode() {
 			return id;
 		}
+
+		@Override
+		public String toString() {
+			return "ElementType{" +
+				"id=" + id +
+				'}';
+		}
 	}
 
 	@Test
@@ -253,7 +260,37 @@ public class CollectionInputFormatTest {
 			fail(e.getMessage());
 		}
 	}
-	
+
+	@Test
+	public void testToStringOnSmallCollection() {
+		ArrayList<ElementType> smallList = new ArrayList<>();
+		smallList.add(new ElementType(1));
+		smallList.add(new ElementType(2));
+		CollectionInputFormat<ElementType> inputFormat = new CollectionInputFormat<>(
+			smallList,
+			new TestSerializer(true, false)
+		);
+
+		assertEquals("[ElementType{id=1}, ElementType{id=2}]", inputFormat.toString());
+	}
+
+	@Test
+	public void testToStringOnBigCollection() {
+		ArrayList<ElementType> list = new ArrayList<>();
+		for (int i = 0; i < 10; i++) {
+			list.add(new ElementType(i));
+		}
+		CollectionInputFormat<ElementType> inputFormat = new CollectionInputFormat<>(
+			list,
+			new TestSerializer(true, false)
+		);
+
+		assertEquals(
+			"[ElementType{id=0}, ElementType{id=1}, ElementType{id=2}, " +
+			"ElementType{id=3}, ElementType{id=4}, ElementType{id=5}, ...]",
+			inputFormat.toString());
+	}
+
 	private static class TestException extends IOException{
 		private static final long serialVersionUID = 1L;
 	}


Mime
View raw message