Apache Flink streaming core library providing fundamental building blocks for scalable stream data processing.
—
Flink's windowing system enables grouping and aggregating stream data over time or count-based intervals. Windows provide the foundation for stateful stream processing operations.
Base class for creating different types of windows.
public abstract class WindowingHelper<T> {
// Factory methods for different window types
}Create windows based on processing time or event time intervals.
public class Time<T> extends WindowingHelper<T> {
// Factory methods
public static <T> Time<T> of(long length, TimeUnit timeUnit);
public static <T> Time<T> of(long length, TimeUnit timeUnit, long delay);
}Usage Examples:
import org.apache.flink.streaming.api.windowing.helper.Time;
import java.util.concurrent.TimeUnit;
// 5-second tumbling window
WindowedDataStream<String> windowedStream = keyedStream
.window(Time.of(5, TimeUnit.SECONDS));
// 10-second window with 2-second delay
WindowedDataStream<String> delayedWindow = keyedStream
.window(Time.of(10, TimeUnit.SECONDS, 2000));Create windows based on element count.
public class Count<T> extends WindowingHelper<T> {
// Factory methods
public static <T> Count<T> of(long windowSize);
public static <T> Count<T> of(long windowSize, long slideSize);
}Usage Examples:
import org.apache.flink.streaming.api.windowing.helper.Count;
// Tumbling window of 100 elements
WindowedDataStream<String> countWindow = keyedStream
.window(Count.of(100));
// Sliding window of 100 elements, sliding by 50
WindowedDataStream<String> slidingWindow = keyedStream
.window(Count.of(100, 50));Create windows based on data-driven thresholds using delta functions.
public class Delta<T> extends WindowingHelper<T> {
public Delta(double threshold, DeltaFunction<T> deltaFunction, T initVal);
}
public interface DeltaFunction<T> {
double getDelta(T oldDataPoint, T newDataPoint);
}Usage Example:
import org.apache.flink.streaming.api.windowing.helper.Delta;
import org.apache.flink.streaming.api.windowing.deltafunction.DeltaFunction;
// Delta window for numeric values
DeltaFunction<Double> deltaFunction = (oldValue, newValue) -> Math.abs(newValue - oldValue);
WindowedDataStream<Double> deltaWindow = numericKeyedStream
.window(new Delta<>(0.5, deltaFunction, 0.0));Determines when to trigger window evaluation.
public interface TriggerPolicy<T> {
boolean notifyTrigger(T datapoint);
}Determines which elements to evict from the window.
public interface EvictionPolicy<T> {
int notifyEviction(T datapoint, boolean triggered, EvictionPoint evictionPoint);
}public class TimeTriggerPolicy<T> implements TriggerPolicy<T> {
// Time-based triggering
}
public class CountTriggerPolicy<T> implements TriggerPolicy<T> {
// Count-based triggering
}
public class DeltaTriggerPolicy<T> implements TriggerPolicy<T> {
// Delta-based triggering
}public class TimeEvictionPolicy<T> implements EvictionPolicy<T> {
// Time-based eviction
}
public class CountEvictionPolicy<T> implements EvictionPolicy<T> {
// Count-based eviction
}Stream with windowing applied, providing operations on windowed data.
public class WindowedDataStream<T> {
// Aggregation operations
public DataStream<T> reduce(ReduceFunction<T> reducer);
public <R> DataStream<R> fold(R initialValue, FoldFunction<T, R> folder);
public <R> DataStream<R> mapWindow(WindowMapFunction<T, R> windowMapper);
}Usage Examples:
// Reduce operation on windowed data
DataStream<Integer> sums = windowedStream
.reduce((a, b) -> a + b);
// Fold operation with initial value
DataStream<String> concatenated = windowedStream
.fold("", (acc, value) -> acc + value);
// Map entire window contents
DataStream<Integer> windowCounts = windowedStream
.mapWindow(values -> {
int count = 0;
for (String value : values) count++;
return count;
});Interface for storing window contents.
public interface WindowBuffer<T> {
void store(T element);
Iterable<T> getElements();
void evict(int numToEvict);
int size();
}public class BasicWindowBuffer<T> implements WindowBuffer<T> {
// Basic implementation for tumbling windows
}
public class SlidingWindowBuffer<T> implements WindowBuffer<T> {
// Implementation for sliding windows
}// Window-related operator types
public class WindowingOperator<T> extends OneInputStreamOperator<T, StreamWindow<T>> {
// Internal windowing operator implementation
}
public class StreamWindowTypeInfo<T> {
// Type information for windowed streams
}
// Field extraction for windowing
public class FieldsFromTuple {
// Extract fields from tuples for window keys
}
public class FieldsFromArray {
// Extract fields from arrays for window keys
}Install with Tessl CLI
npx tessl i tessl/maven-org-apache-flink--flink-streaming-core