Java Code Examples for org.apache.flink.streaming.runtime.streamrecord.StreamRecord#hasTimestamp()

The following examples show how to use org.apache.flink.streaming.runtime.streamrecord.StreamRecord#hasTimestamp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractStreamOperatorTestHarness.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public <X> void collect(OutputTag<X> outputTag, StreamRecord<X> record) {
	sideOutputSerializer = outputTag.getTypeInfo().createSerializer(executionConfig);

	ConcurrentLinkedQueue<Object> sideOutputList = sideOutputLists.get(outputTag);
	if (sideOutputList == null) {
		sideOutputList = new ConcurrentLinkedQueue<>();
		sideOutputLists.put(outputTag, sideOutputList);
	}
	if (record.hasTimestamp()) {
		sideOutputList.add(new StreamRecord<>(sideOutputSerializer.copy(record.getValue()), record.getTimestamp()));
	} else {
		sideOutputList.add(new StreamRecord<>(sideOutputSerializer.copy(record.getValue())));
	}

}
 
Example 2
Source File: AbstractStreamOperatorTestHarness.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public <X> void collect(OutputTag<X> outputTag, StreamRecord<X> record) {
	sideOutputSerializer = TypeExtractor.getForObject(record.getValue()).createSerializer(executionConfig);

	ConcurrentLinkedQueue<Object> sideOutputList = sideOutputLists.get(outputTag);
	if (sideOutputList == null) {
		sideOutputList = new ConcurrentLinkedQueue<>();
		sideOutputLists.put(outputTag, sideOutputList);
	}
	if (record.hasTimestamp()) {
		sideOutputList.add(new StreamRecord<>(sideOutputSerializer.copy(record.getValue()), record.getTimestamp()));
	} else {
		sideOutputList.add(new StreamRecord<>(sideOutputSerializer.copy(record.getValue())));
	}

}
 
Example 3
Source File: EventTimeOrderingOperator.java    From flink-connectors with Apache License 2.0 6 votes vote down vote up
@Override
public void processElement(StreamRecord<T> element) throws Exception {
    if (!element.hasTimestamp()) {
        // elements with no time component are simply forwarded.
        // likely cause: the time characteristic of the program is not event-time.
        output.collect(element);
        return;
    }

    // In event-time processing we assume correctness of the watermark.
    // Events with timestamp smaller than (or equal to) the last seen watermark are considered late.
    // FUTURE: emit late elements to a side output

    if (element.getTimestamp() > lastWatermark) {
        // we have an event with a valid timestamp, so
        // we buffer it until we receive the proper watermark.
        saveRegisterWatermarkTimer();
        bufferEvent(element);
    }
}
 
Example 4
Source File: AbstractStreamOperatorTestHarness.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public <X> void collect(OutputTag<X> outputTag, StreamRecord<X> record) {
	sideOutputSerializer = TypeExtractor.getForObject(record.getValue()).createSerializer(executionConfig);

	ConcurrentLinkedQueue<Object> sideOutputList = sideOutputLists.get(outputTag);
	if (sideOutputList == null) {
		sideOutputList = new ConcurrentLinkedQueue<>();
		sideOutputLists.put(outputTag, sideOutputList);
	}
	if (record.hasTimestamp()) {
		sideOutputList.add(new StreamRecord<>(sideOutputSerializer.copy(record.getValue()), record.getTimestamp()));
	} else {
		sideOutputList.add(new StreamRecord<>(sideOutputSerializer.copy(record.getValue())));
	}

}
 
Example 5
Source File: AbstractStreamOperatorTestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(StreamRecord<OUT> element) {
	if (outputSerializer == null) {
		outputSerializer = TypeExtractor.getForObject(element.getValue()).createSerializer(executionConfig);
	}
	if (element.hasTimestamp()) {
		outputList.add(new StreamRecord<>(outputSerializer.copy(element.getValue()), element.getTimestamp()));
	} else {
		outputList.add(new StreamRecord<>(outputSerializer.copy(element.getValue())));
	}
}
 
Example 6
Source File: AbstractStreamOperatorTestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(StreamRecord<OUT> element) {
	if (outputSerializer == null) {
		outputSerializer = TypeExtractor.getForObject(element.getValue()).createSerializer(executionConfig);
	}
	if (element.hasTimestamp()) {
		outputList.add(new StreamRecord<>(outputSerializer.copy(element.getValue()), element.getTimestamp()));
	} else {
		outputList.add(new StreamRecord<>(outputSerializer.copy(element.getValue())));
	}
}
 
Example 7
Source File: MultipleInputStreamTaskTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<T> element) throws Exception {
	if (!openCalled) {
		Assert.fail("Open was not called before run.");
	}
	if (element.hasTimestamp()) {
		output.collect(new StreamRecord<>(element.getValue().toString(), element.getTimestamp()));
	}
	else {
		output.collect(new StreamRecord<>(element.getValue().toString()));
	}
}
 
Example 8
Source File: TimestampsAndWatermarksOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(final StreamRecord<T> element) throws Exception {
	final T event = element.getValue();
	final long previousTimestamp = element.hasTimestamp() ? element.getTimestamp() : Long.MIN_VALUE;
	final long newTimestamp = timestampAssigner.extractTimestamp(event, previousTimestamp);

	element.setTimestamp(newTimestamp);
	output.collect(element);
	watermarkGenerator.onEvent(event, newTimestamp, wmOutput);
}
 
Example 9
Source File: TimestampedValue.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a TimestampedValue from given {@link StreamRecord}.
 *
 * @param streamRecord The StreamRecord object from which TimestampedValue is to be created.
    */
public static <T> TimestampedValue<T> from(StreamRecord<T> streamRecord) {
	if (streamRecord.hasTimestamp()) {
		return new TimestampedValue<>(streamRecord.getValue(), streamRecord.getTimestamp());
	} else {
		return new TimestampedValue<>(streamRecord.getValue());
	}
}
 
Example 10
Source File: TimestampedCollector.java    From flink with Apache License 2.0 5 votes vote down vote up
public void setTimestamp(StreamRecord<?> timestampBase) {
	if (timestampBase.hasTimestamp()) {
		reuse.setTimestamp(timestampBase.getTimestamp());
	} else {
		reuse.eraseTimestamp();
	}
}
 
Example 11
Source File: TimestampITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<Integer> element) throws Exception {
	if (element.hasTimestamp()) {
		Assert.fail("Timestamps are not properly handled.");
	}
	output.collect(element);
}
 
Example 12
Source File: TimestampITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<Integer> element) throws Exception {
	if (element.hasTimestamp()) {
		Assert.fail("Timestamps are not properly handled.");
	}
	output.collect(element);
}
 
Example 13
Source File: TimestampedValue.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a TimestampedValue from given {@link StreamRecord}.
 *
 * @param streamRecord The StreamRecord object from which TimestampedValue is to be created.
    */
public static <T> TimestampedValue<T> from(StreamRecord<T> streamRecord) {
	if (streamRecord.hasTimestamp()) {
		return new TimestampedValue<>(streamRecord.getValue(), streamRecord.getTimestamp());
	} else {
		return new TimestampedValue<>(streamRecord.getValue());
	}
}
 
Example 14
Source File: StreamRecordQueueEntry.java    From flink with Apache License 2.0 5 votes vote down vote up
public StreamRecordQueueEntry(StreamRecord<?> streamRecord) {
	super(streamRecord);

	hasTimestamp = streamRecord.hasTimestamp();
	timestamp = streamRecord.getTimestamp();

	resultFuture = new CompletableFuture<>();
}
 
Example 15
Source File: TimestampedCollector.java    From flink with Apache License 2.0 5 votes vote down vote up
public void setTimestamp(StreamRecord<?> timestampBase) {
	if (timestampBase.hasTimestamp()) {
		reuse.setTimestamp(timestampBase.getTimestamp());
	} else {
		reuse.eraseTimestamp();
	}
}
 
Example 16
Source File: TimestampITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<Integer> element) throws Exception {
	if (element.hasTimestamp()) {
		Assert.fail("Timestamps are not properly handled.");
	}
	output.collect(element);
}
 
Example 17
Source File: AbstractStreamOperatorTestHarness.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(StreamRecord<OUT> element) {
	if (outputSerializer == null) {
		outputSerializer = TypeExtractor.getForObject(element.getValue()).createSerializer(executionConfig);
	}
	if (element.hasTimestamp()) {
		outputList.add(new StreamRecord<>(outputSerializer.copy(element.getValue()), element.getTimestamp()));
	} else {
		outputList.add(new StreamRecord<>(outputSerializer.copy(element.getValue())));
	}
}
 
Example 18
Source File: TimestampedValue.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a TimestampedValue from given {@link StreamRecord}.
 *
 * @param streamRecord The StreamRecord object from which TimestampedValue is to be created.
    */
public static <T> TimestampedValue<T> from(StreamRecord<T> streamRecord) {
	if (streamRecord.hasTimestamp()) {
		return new TimestampedValue<>(streamRecord.getValue(), streamRecord.getTimestamp());
	} else {
		return new TimestampedValue<>(streamRecord.getValue());
	}
}
 
Example 19
Source File: StreamRecordQueueEntry.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public StreamRecordQueueEntry(StreamRecord<?> streamRecord) {
	super(streamRecord);

	hasTimestamp = streamRecord.hasTimestamp();
	timestamp = streamRecord.getTimestamp();

	resultFuture = new CompletableFuture<>();
}
 
Example 20
Source File: TimestampedCollector.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public void setTimestamp(StreamRecord<?> timestampBase) {
	if (timestampBase.hasTimestamp()) {
		reuse.setTimestamp(timestampBase.getTimestamp());
	} else {
		reuse.eraseTimestamp();
	}
}