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

The following examples show how to use org.apache.flink.streaming.runtime.streamrecord.StreamRecord#getTimestamp() . 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: WindowOperatorMigrationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
	if (o1 instanceof Watermark || o2 instanceof Watermark) {
		return 0;
	} else {
		StreamRecord<Tuple3<String, Long, Long>> sr0 = (StreamRecord<Tuple3<String, Long, Long>>) o1;
		StreamRecord<Tuple3<String, Long, Long>> sr1 = (StreamRecord<Tuple3<String, Long, Long>>) o2;
		if (sr0.getTimestamp() != sr1.getTimestamp()) {
			return (int) (sr0.getTimestamp() - sr1.getTimestamp());
		}
		int comparison = sr0.getValue().f0.compareTo(sr1.getValue().f0);
		if (comparison != 0) {
			return comparison;
		} else {
			comparison = (int) (sr0.getValue().f1 - sr1.getValue().f1);
			if (comparison != 0) {
				return comparison;
			}
			return (int) (sr0.getValue().f1 - sr1.getValue().f1);
		}
	}
}
 
Example 2
Source File: WindowOperatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
	if (o1 instanceof Watermark || o2 instanceof Watermark) {
		return 0;
	} else {
		StreamRecord<Tuple3<String, Long, Long>> sr0 = (StreamRecord<Tuple3<String, Long, Long>>) o1;
		StreamRecord<Tuple3<String, Long, Long>> sr1 = (StreamRecord<Tuple3<String, Long, Long>>) o2;
		if (sr0.getTimestamp() != sr1.getTimestamp()) {
			return (int) (sr0.getTimestamp() - sr1.getTimestamp());
		}
		int comparison = sr0.getValue().f0.compareTo(sr1.getValue().f0);
		if (comparison != 0) {
			return comparison;
		} else {
			comparison = (int) (sr0.getValue().f1 - sr1.getValue().f1);
			if (comparison != 0) {
				return comparison;
			}
			return (int) (sr0.getValue().f2 - sr1.getValue().f2);
		}
	}
}
 
Example 3
Source File: AsyncWaitOperatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
	if (o1 instanceof Watermark || o2 instanceof Watermark) {
		return 0;
	} else {
		StreamRecord<Integer> sr0 = (StreamRecord<Integer>) o1;
		StreamRecord<Integer> sr1 = (StreamRecord<Integer>) o2;

		if (sr0.getTimestamp() != sr1.getTimestamp()) {
			return (int) (sr0.getTimestamp() - sr1.getTimestamp());
		}

		int comparison = sr0.getValue().compareTo(sr1.getValue());
		if (comparison != 0) {
			return comparison;
		} else {
			return sr0.getValue() - sr1.getValue();
		}
	}
}
 
Example 4
Source File: WindowOperatorTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
	if (o1 instanceof Watermark || o2 instanceof Watermark) {
		return 0;
	} else {
		StreamRecord<Tuple2<String, Integer>> sr0 = (StreamRecord<Tuple2<String, Integer>>) o1;
		StreamRecord<Tuple2<String, Integer>> sr1 = (StreamRecord<Tuple2<String, Integer>>) o2;
		if (sr0.getTimestamp() != sr1.getTimestamp()) {
			return (int) (sr0.getTimestamp() - sr1.getTimestamp());
		}
		int comparison = sr0.getValue().f0.compareTo(sr1.getValue().f0);
		if (comparison != 0) {
			return comparison;
		} else {
			return sr0.getValue().f1 - sr1.getValue().f1;
		}
	}
}
 
Example 5
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 6
Source File: WindowOperatorMigrationTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
	if (o1 instanceof Watermark || o2 instanceof Watermark) {
		return 0;
	} else {
		StreamRecord<Tuple2<K, Integer>> sr0 = (StreamRecord<Tuple2<K, Integer>>) o1;
		StreamRecord<Tuple2<K, Integer>> sr1 = (StreamRecord<Tuple2<K, Integer>>) o2;
		if (sr0.getTimestamp() != sr1.getTimestamp()) {
			return (int) (sr0.getTimestamp() - sr1.getTimestamp());
		}
		int comparison = sr0.getValue().f0.compareTo(sr1.getValue().f0);
		if (comparison != 0) {
			return comparison;
		} else {
			return sr0.getValue().f1 - sr1.getValue().f1;
		}
	}
}
 
Example 7
Source File: WindowOperatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
	if (o1 instanceof Watermark || o2 instanceof Watermark) {
		return 0;
	} else {
		StreamRecord<Tuple2<String, Integer>> sr0 = (StreamRecord<Tuple2<String, Integer>>) o1;
		StreamRecord<Tuple2<String, Integer>> sr1 = (StreamRecord<Tuple2<String, Integer>>) o2;
		if (sr0.getTimestamp() != sr1.getTimestamp()) {
			return (int) (sr0.getTimestamp() - sr1.getTimestamp());
		}
		int comparison = sr0.getValue().f0.compareTo(sr1.getValue().f0);
		if (comparison != 0) {
			return comparison;
		} else {
			return sr0.getValue().f1 - sr1.getValue().f1;
		}
	}
}
 
Example 8
Source File: AsyncWaitOperatorTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
	if (o1 instanceof Watermark || o2 instanceof Watermark) {
		return 0;
	} else {
		StreamRecord<Integer> sr0 = (StreamRecord<Integer>) o1;
		StreamRecord<Integer> sr1 = (StreamRecord<Integer>) o2;

		if (sr0.getTimestamp() != sr1.getTimestamp()) {
			return (int) (sr0.getTimestamp() - sr1.getTimestamp());
		}

		int comparison = sr0.getValue().compareTo(sr1.getValue());
		if (comparison != 0) {
			return comparison;
		} else {
			return sr0.getValue() - sr1.getValue();
		}
	}
}
 
Example 9
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 (timestampsEnabled) {
		if (element.getTimestamp() != element.getValue()) {
			Assert.fail("Timestamps are not properly handled.");
		}
	}
	output.collect(element);
}
 
Example 10
Source File: Kafka010ITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<Long> element) throws Exception {
	elCount++;
	if (element.getValue() * 2 != element.getTimestamp()) {
		throw new RuntimeException("Invalid timestamp: " + element);
	}
}
 
Example 11
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 12
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 13
Source File: StreamRecordComparator.java    From bahir-flink with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(StreamRecord<IN> o1, StreamRecord<IN> o2) {
    if (o1.getTimestamp() < o2.getTimestamp()) {
        return -1;
    } else if (o1.getTimestamp() > o2.getTimestamp()) {
        return 1;
    } else {
        return 0;
    }
}
 
Example 14
Source File: StreamRecordComparator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(StreamRecord<IN> o1, StreamRecord<IN> o2) {
	if (o1.getTimestamp() < o2.getTimestamp()) {
		return -1;
	} else if (o1.getTimestamp() > o2.getTimestamp()) {
		return 1;
	} else {
		return 0;
	}
}
 
Example 15
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 16
Source File: Kafka010ITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<Long> element) throws Exception {
	elCount++;
	if (element.getValue() * 2 != element.getTimestamp()) {
		throw new RuntimeException("Invalid timestamp: " + element);
	}
}
 
Example 17
Source File: Kafka011ITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<Long> element) throws Exception {
	elCount++;
	if (element.getValue() * 2 != element.getTimestamp()) {
		throw new RuntimeException("Invalid timestamp: " + element);
	}
}
 
Example 18
Source File: WindowOperator.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Decide if a record is currently late, based on current watermark and allowed lateness.
 *
 * @param element The element to check
 * @return The element for which should be considered when sideoutputs
 */
protected boolean isElementLate(StreamRecord<IN> element){
	return (windowAssigner.isEventTime()) &&
		(element.getTimestamp() + allowedLateness <= internalTimerService.currentWatermark());
}
 
Example 19
Source File: WindowOperator.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Decide if a record is currently late, based on current watermark and allowed lateness.
 *
 * @param element The element to check
 * @return The element for which should be considered when sideoutputs
 */
protected boolean isElementLate(StreamRecord<IN> element){
	return (windowAssigner.isEventTime()) &&
		(element.getTimestamp() + allowedLateness <= internalTimerService.currentWatermark());
}
 
Example 20
Source File: WindowOperator.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Decide if a record is currently late, based on current watermark and allowed lateness.
 *
 * @param element The element to check
 * @return The element for which should be considered when sideoutputs
 */
protected boolean isElementLate(StreamRecord<IN> element){
	return (windowAssigner.isEventTime()) &&
		(element.getTimestamp() + allowedLateness <= internalTimerService.currentWatermark());
}