Search code examples
apache-flink

Are `stream.addSink(new PrintSinkFunction<>())` and `stream.print()` the same in Flink


I've seen both stream.addSink(new PrintSinkFunction<>()) and stream.print(), wondering if there is any difference between them at all.

Based on https://github.com/apache/flink/blob/b2a342c6a6ef154ed3c1a44826ce2be14e538386/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/DataStream.java#L972-L973, they are essentially the same except for the .name("Print to Std. Out") part, right?


Solution

  • Yes, this is the same and stream.print() is just a shortcut for stream.addSink(new PrintSinkFunction<>()).name("Print to Std. Out"); :

    @PublicEvolving
    public DataStreamSink<T> print() {
        PrintSinkFunction<T> printFunction = new PrintSinkFunction<>();
        return addSink(printFunction).name("Print to Std. Out");
    }