You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by rm...@apache.org on 2014/06/10 21:34:59 UTC

[02/34] git commit: Implement toString of CsvOutputFormat

Implement toString of CsvOutputFormat


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

Branch: refs/heads/release-0.5.1
Commit: bce608ca7a4e1a15992281379bff27285c7d99c0
Parents: 694b318
Author: sebastian kunert <sk...@gmail.com>
Authored: Mon May 26 21:03:14 2014 +0200
Committer: Robert Metzger <rm...@apache.org>
Committed: Tue Jun 10 21:24:14 2014 +0200

----------------------------------------------------------------------
 .../api/java/io/CsvOutputFormat.java            | 38 +++++++++++---------
 1 file changed, 21 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/bce608ca/stratosphere-java/src/main/java/eu/stratosphere/api/java/io/CsvOutputFormat.java
----------------------------------------------------------------------
diff --git a/stratosphere-java/src/main/java/eu/stratosphere/api/java/io/CsvOutputFormat.java b/stratosphere-java/src/main/java/eu/stratosphere/api/java/io/CsvOutputFormat.java
index 7db9bdc..73bc14f 100644
--- a/stratosphere-java/src/main/java/eu/stratosphere/api/java/io/CsvOutputFormat.java
+++ b/stratosphere-java/src/main/java/eu/stratosphere/api/java/io/CsvOutputFormat.java
@@ -28,7 +28,6 @@ import eu.stratosphere.api.java.typeutils.InputTypeConfigurable;
 import eu.stratosphere.types.TypeInformation;
 import eu.stratosphere.core.fs.Path;
 import eu.stratosphere.types.StringValue;
-
 /**
  * This is an OutputFormat to serialize {@link eu.stratosphere.api.java.tuple.Tuple}s to text. The output is
  * structured by record delimiters and field delimiters as common in CSV files.
@@ -40,11 +39,11 @@ public class CsvOutputFormat<T extends Tuple> extends FileOutputFormat<T> implem
 
 	@SuppressWarnings("unused")
 	private static final Log LOG = LogFactory.getLog(CsvOutputFormat.class);
-	
+
 	// --------------------------------------------------------------------------------------------
-	
+
 	public static final String DEFAULT_LINE_DELIMITER = CsvInputFormat.DEFAULT_LINE_DELIMITER;
-	
+
 	public static final String DEFAULT_FIELD_DELIMITER = String.valueOf(CsvInputFormat.DEFAULT_FIELD_DELIMITER);
 
 	// --------------------------------------------------------------------------------------------
@@ -68,7 +67,7 @@ public class CsvOutputFormat<T extends Tuple> extends FileOutputFormat<T> implem
 	/**
 	 * Creates an instance of CsvOutputFormat. Lines are separated by the newline character '\n',
 	 * fields are separated by ','.
-	 * 
+	 *
 	 * @param outputPath The path where the CSV file is written.
 	 */
 	public CsvOutputFormat(Path outputPath) {
@@ -78,7 +77,7 @@ public class CsvOutputFormat<T extends Tuple> extends FileOutputFormat<T> implem
 	/**
 	 * Creates an instance of CsvOutputFormat. Lines are separated by the newline character '\n',
 	 * fields by the given field delimiter.
-	 * 
+	 *
 	 * @param outputPath The path where the CSV file is written.
 	 * @param fieldDelimiter
 	 *            The delimiter that is used to separate fields in a tuple.
@@ -89,7 +88,7 @@ public class CsvOutputFormat<T extends Tuple> extends FileOutputFormat<T> implem
 
 	/**
 	 * Creates an instance of CsvOutputFormat.
-	 * 
+	 *
 	 * @param outputPath The path where the CSV file is written.
 	 * @param recordDelimiter
 	 *            The delimiter that is used to separate the tuples.
@@ -101,6 +100,7 @@ public class CsvOutputFormat<T extends Tuple> extends FileOutputFormat<T> implem
 		if (recordDelimiter == null) {
 			throw new IllegalArgumentException("RecordDelmiter shall not be null.");
 		}
+
 		if (fieldDelimiter == null) {
 			throw new IllegalArgumentException("FieldDelimiter shall not be null.");
 		}
@@ -109,13 +109,13 @@ public class CsvOutputFormat<T extends Tuple> extends FileOutputFormat<T> implem
 		this.recordDelimiter = recordDelimiter;
 		this.allowNullValues = false;
 	}
-	
+
 	/**
 	 * Configures the format to either allow null values (writing an empty field),
 	 * or to throw an exception when encountering a null field.
 	 * <p>
 	 * by default, null values are allowed.
-	 * 
+	 *
 	 * @param allowNulls Flag to indicate whether the output format should accept null values.
 	 */
 	public void setAllowNullValues(boolean allowNulls) {
@@ -125,7 +125,7 @@ public class CsvOutputFormat<T extends Tuple> extends FileOutputFormat<T> implem
 	/**
 	 * Sets the charset with which the CSV strings are written to the file.
 	 * If not specified, the output format uses the systems default character encoding.
-	 * 
+	 *
 	 * @param charsetName The name of charset to use for encoding the output.
 	 */
 	public void setCharsetName(String charsetName) {
@@ -138,13 +138,13 @@ public class CsvOutputFormat<T extends Tuple> extends FileOutputFormat<T> implem
 	 * all subclasses of the latter.
 	 * <p>
 	 * By default, strings are not quoted.
-	 * 
+	 *
 	 * @param quoteStrings Flag indicating whether string fields should be quoted.
 	 */
 	public void setQuoteStrings(boolean quoteStrings) {
 		this.quoteStrings = quoteStrings;
 	}
-	
+
 	// --------------------------------------------------------------------------------------------
 
 	@Override
@@ -198,18 +198,22 @@ public class CsvOutputFormat<T extends Tuple> extends FileOutputFormat<T> implem
 		// add the record delimiter
 		this.wrt.write(this.recordDelimiter);
 	}
-	
+
 	// --------------------------------------------------------------------------------------------
-	
-	/**
-	 * 
+	@Override
+	public String toString() {
+		return "CsvOutputFormat (path: " + this.getOutputFilePath() + ", delimiter: " + this.fieldDelimiter + ")";
+	}
+
+    /**
+	 *
 	 * The purpose of this method is solely to check whether the data type to be processed
 	 * is in fact a tuple type.
 	 */
 	@Override
 	public void setInputType(TypeInformation<?> type) {
 		if (!type.isTupleType()) {
-			throw new InvalidProgramException("The " + CsvOutputFormat.class.getSimpleName() + 
+			throw new InvalidProgramException("The " + CsvOutputFormat.class.getSimpleName() +
 				" can only be used to write tuple data sets.");
 		}
 	}