[ 
https://issues.apache.org/jira/browse/FLINK-9850?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16580949#comment-16580949
 ] 

ASF GitHub Bot commented on FLINK-9850:
---------------------------------------

pnowojski commented on a change in pull request #6367: [FLINK-9850] Add a 
string to the print method to identify output for DataStream
URL: https://github.com/apache/flink/pull/6367#discussion_r210239256
 
 

 ##########
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/sink/PrintSinkFunction.java
 ##########
 @@ -18,81 +18,74 @@
 package org.apache.flink.streaming.api.functions.sink;
 
 import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.api.common.functions.util.TaskOutputWriter;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
 
-import java.io.PrintStream;
-
 /**
  * Implementation of the SinkFunction writing every tuple to the standard
  * output or standard error stream.
  *
- * @param <IN>
- *            Input record type
+ * <p>
+ * Four possible format options:
+ *     {@code sinkIdentifier}:taskId> output  <- {@code sinkIdentifier} 
provided, parallelism > 1
+ *     {@code sinkIdentifier}> output         <- {@code sinkIdentifier} 
provided, parallelism == 1
+ *  taskId> output                                        <- no {@code 
sinkIdentifier} provided, parallelism > 1
+ *  output                                                <- no {@code 
sinkIdentifier} provided, parallelism == 1
+ * </p>
+ *
+ * @param <IN> Input record type
  */
 @PublicEvolving
 public class PrintSinkFunction<IN> extends RichSinkFunction<IN> {
-       private static final long serialVersionUID = 1L;
 
-       private static final boolean STD_OUT = false;
-       private static final boolean STD_ERR = true;
+       private static final long serialVersionUID = 1L;
 
-       private boolean target;
-       private transient PrintStream stream;
-       private transient String prefix;
+       private final TaskOutputWriter<IN> writer;
 
        /**
         * Instantiates a print sink function that prints to standard out.
         */
-       public PrintSinkFunction() {}
+       public PrintSinkFunction() {
+               writer = new TaskOutputWriter<>();
+       }
 
        /**
         * Instantiates a print sink function that prints to standard out.
         *
         * @param stdErr True, if the format should print to standard error 
instead of standard out.
         */
-       public PrintSinkFunction(boolean stdErr) {
-               target = stdErr;
-       }
-
-       public void setTargetToStandardOut() {
-               target = STD_OUT;
+       public PrintSinkFunction(final boolean stdErr) {
+               writer = new TaskOutputWriter<>(stdErr);
        }
 
-       public void setTargetToStandardErr() {
-               target = STD_ERR;
+       /**
+        * Instantiates a print sink function that prints to standard out and 
gives a sink identifier.
+        *
+        * @param stdErr True, if the format should print to standard error 
instead of standard out.
+        * @param sinkIdentifier Message that identify sink and is prefixed to 
the output of the value
+        */
+       public PrintSinkFunction(final String sinkIdentifier, final boolean 
stdErr) {
+               writer = new TaskOutputWriter<>(sinkIdentifier, stdErr);
        }
 
        @Override
        public void open(Configuration parameters) throws Exception {
                super.open(parameters);
                StreamingRuntimeContext context = (StreamingRuntimeContext) 
getRuntimeContext();
-               // get the target stream
-               stream = target == STD_OUT ? System.out : System.err;
+               int taskNumber = context.getIndexOfThisSubtask();
 
 Review comment:
   nit: inline those variables?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Add a string to the print method to identify output for DataStream
> ------------------------------------------------------------------
>
>                 Key: FLINK-9850
>                 URL: https://issues.apache.org/jira/browse/FLINK-9850
>             Project: Flink
>          Issue Type: New Feature
>          Components: DataStream API
>            Reporter: Hequn Cheng
>            Assignee: vinoyang
>            Priority: Major
>              Labels: pull-request-available
>
> The output of the print method of {[DataSet}} allows the user to supply a 
> String to identify the output(see 
> [FLINK-1486|https://issues.apache.org/jira/browse/FLINK-1486]). But 
> {[DataStream}} doesn't support now. It is valuable to add this feature for 
> {{DataStream}}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to