/** * Writes a DataStream to the standard output stream (stderr). * * <p>For each element of the DataStream the result of {@link Object#toString()} is written. * * <p>NOTE: This will print to stderr on the machine where the code is executed, i.e. the Flink * worker. * * @return The closed DataStream. */ @PublicEvolving public DataStreamSink<T> printToErr() { PrintSinkFunction<T> printFunction = new PrintSinkFunction<>(true); return addSink(printFunction).name("Print to Std. Err"); }
@Override public void open(Configuration parameters) throws Exception { super.open(parameters); StreamingRuntimeContext context = (StreamingRuntimeContext) getRuntimeContext(); writer.open(context.getIndexOfThisSubtask(), context.getNumberOfParallelSubtasks()); }
@Test public void testPrintSinkStdErr() throws Exception { PrintSinkFunction<String> printSink = new PrintSinkFunction<>(true); printSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0)); printSink.open(new Configuration()); printSink.invoke("hello world!", SinkContextUtil.forTimestamp(0)); assertEquals("Print to System.err", printSink.toString()); assertEquals("hello world!" + line, arrayErrorStream.toString()); printSink.close(); }
/** * Writes a DataStream to the standard output stream (stdout). * * <p>For each element of the DataStream the result of {@link Object#toString()} is written. * * <p>NOTE: This will print to stdout on the machine where the code is executed, i.e. the Flink * worker. * * @return The closed DataStream. */ @PublicEvolving public DataStreamSink<T> print() { PrintSinkFunction<T> printFunction = new PrintSinkFunction<>(); return addSink(printFunction).name("Print to Std. Out"); }
@Test public void testPrintSinkWithPrefix() throws Exception { PrintSinkFunction<String> printSink = new PrintSinkFunction<>(); printSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 2, 1)); printSink.open(new Configuration()); printSink.invoke("hello world!", SinkContextUtil.forTimestamp(0)); assertEquals("Print to System.out", printSink.toString()); assertEquals("2> hello world!" + line, arrayOutputStream.toString()); printSink.close(); }
@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; // set the prefix if we have a >1 parallelism prefix = (context.getNumberOfParallelSubtasks() > 1) ? ((context.getIndexOfThisSubtask() + 1) + "> ") : null; }
/** * Writes a DataStream to the standard output stream (stdout). * * <p>For each element of the DataStream the result of {@link Object#toString()} is written. * * <p>NOTE: This will print to stdout on the machine where the code is executed, i.e. the Flink * worker. * * @param sinkIdentifier The string to prefix the output with. * @return The closed DataStream. */ @PublicEvolving public DataStreamSink<T> print(String sinkIdentifier) { PrintSinkFunction<T> printFunction = new PrintSinkFunction<>(sinkIdentifier, false); return addSink(printFunction).name("Print to Std. Out"); }
@Test public void testPrintSinkStdOut() throws Exception { PrintSinkFunction<String> printSink = new PrintSinkFunction<>(); printSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0)); printSink.open(new Configuration()); printSink.invoke("hello world!", SinkContextUtil.forTimestamp(0)); assertEquals("Print to System.out", printSink.toString()); assertEquals("hello world!" + line, arrayOutputStream.toString()); printSink.close(); }
@Override public void open(Configuration parameters) throws Exception { super.open(parameters); StreamingRuntimeContext context = (StreamingRuntimeContext) getRuntimeContext(); writer.open(context.getIndexOfThisSubtask(), context.getNumberOfParallelSubtasks()); }
/** * Writes a DataStream to the standard output stream (stderr). * * <p>For each element of the DataStream the result of {@link Object#toString()} is written. * * <p>NOTE: This will print to stderr on the machine where the code is executed, i.e. the Flink * worker. * * @param sinkIdentifier The string to prefix the output with. * @return The closed DataStream. */ @PublicEvolving public DataStreamSink<T> printToErr(String sinkIdentifier) { PrintSinkFunction<T> printFunction = new PrintSinkFunction<>(sinkIdentifier, true); return addSink(printFunction).name("Print to Std. Err"); }
@Test public void testPrintSinkWithIdentifierAndPrefix() throws Exception { PrintSinkFunction<String> printSink = new PrintSinkFunction<>("mySink", false); printSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 2, 1)); printSink.open(new Configuration()); printSink.invoke("hello world!", SinkContextUtil.forTimestamp(0)); assertEquals("Print to System.out", printSink.toString()); assertEquals("mySink:2> hello world!" + line, arrayOutputStream.toString()); printSink.close(); }
@Override public void open(Configuration parameters) throws Exception { super.open(parameters); StreamingRuntimeContext context = (StreamingRuntimeContext) getRuntimeContext(); writer.open(context.getIndexOfThisSubtask(), context.getNumberOfParallelSubtasks()); }
@Override public void go() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.addSource(new SourceFunction<String>() { @Override public void run(SourceContext<String> ctx) throws Exception { sync.block(); } @Override public void cancel() { sync.releaseBlocker(); } }).addSink(new PrintSinkFunction()); env.execute(); }
@Test public void testPrintSinkWithIdentifierButNoPrefix() throws Exception { PrintSinkFunction<String> printSink = new PrintSinkFunction<>("mySink", false); printSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0)); printSink.open(new Configuration()); printSink.invoke("hello world!", SinkContextUtil.forTimestamp(0)); assertEquals("Print to System.out", printSink.toString()); assertEquals("mySink> hello world!" + line, arrayOutputStream.toString()); printSink.close(); }
public static void main(String[] args) throws Exception { final ParameterTool pt = ParameterTool.fromArgs(args); final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); setupEnvironment(env, pt); KeyedStream<Event, Integer> source = env.addSource(createEventSource(pt)) .name("EventSource") .uid("EventSource") .assignTimestampsAndWatermarks(createTimestampExtractor(pt)) .keyBy(Event::getKey); List<TypeSerializer<ComplexPayload>> stateSer = Collections.singletonList(new KryoSerializer<>(ComplexPayload.class, env.getConfig())); KeyedStream<Event, Integer> afterStatefulOperations = isOriginalJobVariant(pt) ? applyOriginalStatefulOperations(source, stateSer, Collections.emptyList()) : applyUpgradedStatefulOperations(source, stateSer, Collections.emptyList()); afterStatefulOperations .flatMap(createSemanticsCheckMapper(pt)) .name("SemanticsCheckMapper") .addSink(new PrintSinkFunction<>()); env.execute("General purpose test job"); }
.keyBy((KeySelector<Long, Long>) aLong -> aLong) .flatMap(new StateCreatingFlatMap(valueSize, killJvmOnFail)) .addSink(new PrintSinkFunction<>());
.name(SEMANTICS_CHECK_MAPPER_NAME) .uid("007") .addSink(new PrintSinkFunction<>()) .uid("008"); .uid("010") .name(SLIDING_WINDOW_CHECK_MAPPER_NAME) .addSink(new PrintSinkFunction<>()) .uid("011");
public static void main(String[] args) throws Exception { final ParameterTool pt = ParameterTool.fromArgs(args); final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); setupEnvironment(env, pt); final MonotonicTTLTimeProvider ttlTimeProvider = setBackendWithCustomTTLTimeProvider(env); TtlTestConfig config = TtlTestConfig.fromArgs(pt); StateTtlConfig ttlConfig = StateTtlConfig.newBuilder(config.ttl) .cleanupIncrementally(5, true) .cleanupFullSnapshot() .build(); env .addSource(new TtlStateUpdateSource(config.keySpace, config.sleepAfterElements, config.sleepTime)) .name("TtlStateUpdateSource") .keyBy(TtlStateUpdate::getKey) .flatMap(new TtlVerifyUpdateFunction(ttlConfig, ttlTimeProvider, config.reportStatAfterUpdatesNum)) .name("TtlVerifyUpdateFunction") .addSink(new PrintSinkFunction<>()) .name("PrintFailedVerifications"); env.execute("State TTL test job"); }
/** * Writes a DataStream to the standard output stream (stderr). * * <p>For each element of the DataStream the result of {@link Object#toString()} is written. * * @return The closed DataStream. */ @PublicEvolving public DataStreamSink<T> printToErr() { PrintSinkFunction<T> printFunction = new PrintSinkFunction<>(true); return addSink(printFunction); }
/** * Writes a DataStream to the standard output stream (stdout). * * <p>For each element of the DataStream the result of {@link Object#toString()} is written. * * @return The closed DataStream. */ @PublicEvolving public DataStreamSink<T> print() { PrintSinkFunction<T> printFunction = new PrintSinkFunction<>(); return addSink(printFunction); }