Esempio n. 1
0
 /**
  * Writes the DataStream to a socket as a byte array. The format of the output is specified by a
  * {@link SerializationSchema}.
  *
  * @param hostName host of the socket
  * @param port port of the socket
  * @param schema schema for serialization
  * @return the closed DataStream
  */
 @PublicEvolving
 public DataStreamSink<T> writeToSocket(String hostName, int port, SerializationSchema<T> schema) {
   DataStreamSink<T> returnStream = addSink(new SocketClientSink<>(hostName, port, schema, 0));
   returnStream.setParallelism(
       1); // It would not work if multiple instances would connect to the same port
   return returnStream;
 }
Esempio n. 2
0
  /**
   * Adds the given sink to this DataStream. Only streams with sinks added will be executed once the
   * {@link StreamExecutionEnvironment#execute()} method is called.
   *
   * @param sinkFunction The object containing the sink's invoke function.
   * @return The closed DataStream.
   */
  public DataStreamSink<T> addSink(SinkFunction<T> sinkFunction) {

    // read the output type of the input Transform to coax out errors about MissingTypeInfo
    transformation.getOutputType();

    // configure the type if needed
    if (sinkFunction instanceof InputTypeConfigurable) {
      ((InputTypeConfigurable) sinkFunction).setInputType(getType(), getExecutionConfig());
    }

    StreamSink<T> sinkOperator = new StreamSink<>(clean(sinkFunction));

    DataStreamSink<T> sink = new DataStreamSink<>(this, sinkOperator);

    getExecutionEnvironment().addOperator(sink.getTransformation());
    return sink;
  }