T
- Tuple type, any instance of T
at runtime must be
serializable.K
- Key type.public interface TWindow<T,K> extends TopologyElement
TStream
. Logically a Window
represents an continuously updated ordered list of tuples according to the
criteria that created it. For example s.last(10)
declares a window that at any time contains the last ten tuples seen on
stream s
, while
s.last(5,
TimeUnit.SECONDS)
is a window that always contains all tuples present on stream
s
in the last five seconds.
Typically windows are partitioned by a key which means the window's configuration
is independently maintained for each key seen on the stream.
For example with a window created using last(3)
then each key has its own window partition containing the last
three tuples with the same key.
A partitioned window is created by calling key(Function)
or key()
.
When a window is not partitioned it acts as though it has
a single partition with a constant key with the value Integer.valueOf(0)
.
Modifier and Type | Method and Description |
---|---|
<A> TStream<A> |
aggregate(Function<java.util.List<T>,A> aggregator,
long period,
java.util.concurrent.TimeUnit unit)
Declares a stream that containing tuples that represent an aggregation of
this window.
|
<A> TStream<A> |
aggregate(Function<java.util.List<T>,A> aggregator)
Declares a stream that containing tuples that represent an aggregation of
this window.
|
TStream<T> |
getStream()
Get this window's stream.
|
java.lang.Class<T> |
getTupleClass()
Class of the tuples in this window.
|
java.lang.reflect.Type |
getTupleType()
Type of the tuples in this window.
|
boolean |
isKeyed()
Is the window keyed.
|
TWindow<T,T> |
key()
Return a keyed (partitioned) window that has the same
configuration as this window with each tuple being the key.
|
<U> TWindow<T,U> |
key(Function<? super T,? extends U> keyFunction)
Return a keyed (partitioned) window that has the same
configuration as this window with the each tuple's
key defined by a function.
|
builder, topology
<A> TStream<A> aggregate(Function<java.util.List<T>,A> aggregator)
aggregator.call(tuples)
is called, where tuples
is an
List
that containing all the tuples in the current window.
The List
is stable during the method call, and returns the
tuples in order of insertion into the window, from oldest to newest. aggregator
- Logic to aggregation the complete window contents.<A> TStream<A> aggregate(Function<java.util.List<T>,A> aggregator, long period, java.util.concurrent.TimeUnit unit)
period
(with unit unit
)
aggregator.call(tuples)
is called, where tuples
is an
List
that containing all the tuples in the current window.
The List
is stable during the method call, and returns the
tuples in order of insertion into the window, from oldest to newest. period
seconds (according to unit
) aggregation of this window or window
partition.aggregator
- Logic to aggregation the complete window contents.period
- Approximately how often to perform the aggregation.unit
- Time unit for period
.java.lang.Class<T> getTupleClass()
getTupleType()
is a Class
object.null
if getTupleType()
is not a Class
object.java.lang.reflect.Type getTupleType()
<U> TWindow<T,U> key(Function<? super T,? extends U> keyFunction)
keyFunction
.
All tuples that have the same key will
be processed as an independent window. For example,
with a window created using last(3)
then each key has its own window containing the last
three tuples with the same key.
U
- Type of the key.keyFunction
- Function that gets the key from a tuple.
The key function must be stateless.TWindow<T,T> key()
key(Function)
boolean isKeyed()
true
if the window is keyed, false
if it is not keyed.key(Function)
,
key()