flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aljoscha <...@git.apache.org>
Subject [GitHub] flink pull request: [FLINK-1967] Introduce (Event)time in Streamin...
Date Fri, 03 Jul 2015 13:38:50 GMT
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/879#discussion_r33864220
  
    --- Diff: flink-staging/flink-streaming/flink-streaming-core/src/main/java/org/apache/flink/streaming/runtime/streamrecord/StreamRecord.java
---
    @@ -17,87 +17,104 @@
     
     package org.apache.flink.streaming.runtime.streamrecord;
     
    -import java.io.Serializable;
    -
    -import org.apache.flink.api.java.functions.KeySelector;
    -import org.apache.flink.api.java.tuple.Tuple;
    +import org.joda.time.Instant;
     
     /**
    - * Object for wrapping a tuple or other object with ID used for sending records
    - * between streaming task in Apache Flink stream processing.
    + * One value in a data stream. This stores the value and the associated timestamp.
      */
    -public class StreamRecord<T> implements Serializable {
    -	private static final long serialVersionUID = 1L;
    +public class StreamRecord<T> {
     
    -	private T streamObject;
    -	public boolean isTuple;
    +	// We store it as Object so that we can reuse a StreamElement for emitting
    +	// elements of a different type while still reusing the timestamp.
    +	private Object value;
    +	private Instant timestamp;
     
     	/**
    -	 * Creates an empty StreamRecord
    +	 * Creates a new {@link StreamRecord} wrapping the given value. The timestamp is set
to the
    +	 * result of {@code new Instant(0)}.
     	 */
    -	public StreamRecord() {
    +	public StreamRecord(T value) {
    +		this(value, new Instant(0));
     	}
     
     	/**
    -	 * Gets the wrapped object from the StreamRecord
    -	 * 
    -	 * @return The object wrapped
    +	 * Creates a new {@link StreamRecord} wrapping the given value. The timestamp is set
to the
    +	 * given timestamp.
     	 */
    -	public T getObject() {
    -		return streamObject;
    +	public StreamRecord(T value, Instant timestamp) {
    +		this.value = value;
    +		this.timestamp = timestamp;
     	}
     
    +
     	/**
    -	 * Gets the field of the contained object at the given position. If a tuple
    -	 * is wrapped then the getField method is invoked. If the StreamRecord
    -	 * contains and object of Basic types only position 0 could be returned.
    -	 * 
    -	 * @param pos
    -	 *            Position of the field to get.
    -	 * @return Returns the object contained in the position.
    +	 * Returns the value wrapped in this stream value.
     	 */
    -	public Object getField(int pos) {
    -		if (isTuple) {
    -			return ((Tuple) streamObject).getField(pos);
    -		} else {
    -			if (pos == 0) {
    -				return streamObject;
    -			} else {
    -				throw new IndexOutOfBoundsException();
    -			}
    -		}
    +	@SuppressWarnings("unchecked")
    +	public T getValue() {
    +		return (T) value;
    --- End diff --
    
    But then it just requires casts in another place...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message