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_r209237840
 
 

 ##########
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/sink/PrintSinkFunction.java
 ##########
 @@ -70,15 +83,29 @@ public void open(Configuration parameters) throws 
Exception {
                // get the target stream
                stream = target == STD_OUT ? System.out : System.err;
 
+               /**
+                * Four possible format options:
+                *      sinkId:taskId> output  <- sink id provided, parallelism 
> 1
+                *      sinkId> output         <- sink id provided, parallelism 
== 1
+                *      taskId> output         <- no sink id provided, 
parallelism > 1
+                *      output                 <- no sink id provided, 
parallelism == 1
+                */
+
                // set the prefix if we have a >1 parallelism
                prefix = (context.getNumberOfParallelSubtasks() > 1) ?
                                ((context.getIndexOfThisSubtask() + 1) + "> ") 
: null;
+
+               if (prefix == null) {
 
 Review comment:
   Don't use nulls here. In this case we can easily use empty string for the 
same purpose and it will be safer (no possible NPE).
   
   Btw, rephrasing this logic like that:
   ```
   completedPrefix = sinkIdentifier;
   
   if (context.getNumberOfParallelSubtasks() > 1)) {
     if (!completedPrefix.isEmpty()) {
       completedPrefix += ":";
     }
     completedPrefix += (context.getIndexOfThisSubtask() + 1);
   }
   
   if (!completedPrefix.isEmpty()) {
     completedPrefix += ">";
   }
   ```
   (optionally with ternary operator instead of some 'if' statements - that's 
only a matter of taste) simplifies the logic and deduplicate some of the 
code/constants.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to