Search in sources :

Example 1 with PerWindowStateDataViewStore

use of org.apache.flink.table.runtime.dataview.PerWindowStateDataViewStore in project flink by apache.

the class WindowOperator method open.

@Override
public void open() throws Exception {
    super.open();
    collector = new TimestampedCollector<>(output);
    collector.eraseTimestamp();
    internalTimerService = getInternalTimerService("window-timers", windowSerializer, this);
    triggerContext = new TriggerContext();
    triggerContext.open();
    StateDescriptor<ValueState<RowData>, RowData> windowStateDescriptor = new ValueStateDescriptor<>("window-aggs", new RowDataSerializer(accumulatorTypes));
    this.windowState = (InternalValueState<K, W, RowData>) getOrCreateKeyedState(windowSerializer, windowStateDescriptor);
    if (produceUpdates) {
        LogicalType[] valueTypes = ArrayUtils.addAll(aggResultTypes, windowPropertyTypes);
        StateDescriptor<ValueState<RowData>, RowData> previousStateDescriptor = new ValueStateDescriptor<>("previous-aggs", new RowDataSerializer(valueTypes));
        this.previousState = (InternalValueState<K, W, RowData>) getOrCreateKeyedState(windowSerializer, previousStateDescriptor);
    }
    compileGeneratedCode();
    WindowContext windowContext = new WindowContext();
    windowAggregator.open(new PerWindowStateDataViewStore(getKeyedStateBackend(), windowSerializer, getRuntimeContext()));
    if (windowAssigner instanceof MergingWindowAssigner) {
        this.windowFunction = new MergingWindowProcessFunction<>((MergingWindowAssigner<W>) windowAssigner, windowAggregator, windowSerializer, allowedLateness);
    } else if (windowAssigner instanceof PanedWindowAssigner) {
        this.windowFunction = new PanedWindowProcessFunction<>((PanedWindowAssigner<W>) windowAssigner, windowAggregator, allowedLateness);
    } else {
        this.windowFunction = new GeneralWindowProcessFunction<>(windowAssigner, windowAggregator, allowedLateness);
    }
    windowFunction.open(windowContext);
    // metrics
    this.numLateRecordsDropped = metrics.counter(LATE_ELEMENTS_DROPPED_METRIC_NAME);
    this.lateRecordsDroppedRate = metrics.meter(LATE_ELEMENTS_DROPPED_RATE_METRIC_NAME, new MeterView(numLateRecordsDropped));
    this.watermarkLatency = metrics.gauge(WATERMARK_LATENCY_METRIC_NAME, () -> {
        long watermark = internalTimerService.currentWatermark();
        if (watermark < 0) {
            return 0L;
        } else {
            return internalTimerService.currentProcessingTime() - watermark;
        }
    });
}
Also used : GeneralWindowProcessFunction(org.apache.flink.table.runtime.operators.window.internal.GeneralWindowProcessFunction) LogicalType(org.apache.flink.table.types.logical.LogicalType) MeterView(org.apache.flink.metrics.MeterView) PanedWindowAssigner(org.apache.flink.table.runtime.operators.window.assigners.PanedWindowAssigner) MergingWindowAssigner(org.apache.flink.table.runtime.operators.window.assigners.MergingWindowAssigner) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) RowData(org.apache.flink.table.data.RowData) InternalValueState(org.apache.flink.runtime.state.internal.InternalValueState) ValueState(org.apache.flink.api.common.state.ValueState) PerWindowStateDataViewStore(org.apache.flink.table.runtime.dataview.PerWindowStateDataViewStore) PanedWindowProcessFunction(org.apache.flink.table.runtime.operators.window.internal.PanedWindowProcessFunction) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer)

Example 2 with PerWindowStateDataViewStore

use of org.apache.flink.table.runtime.dataview.PerWindowStateDataViewStore in project flink by apache.

the class AbstractWindowAggProcessor method open.

@Override
public void open(Context<Long> context) throws Exception {
    this.ctx = context;
    final LongSerializer namespaceSerializer = LongSerializer.INSTANCE;
    ValueState<RowData> state = ctx.getKeyedStateBackend().getOrCreateKeyedState(namespaceSerializer, new ValueStateDescriptor<>("window-aggs", accSerializer));
    this.windowState = new WindowValueState<>((InternalValueState<RowData, Long, RowData>) state);
    this.clockService = ClockService.of(ctx.getTimerService());
    this.windowTimerService = new WindowTimerServiceImpl(ctx.getTimerService(), shiftTimeZone);
    this.aggregator = genAggsHandler.newInstance(ctx.getRuntimeContext().getUserCodeClassLoader());
    this.aggregator.open(new PerWindowStateDataViewStore(ctx.getKeyedStateBackend(), namespaceSerializer, ctx.getRuntimeContext()));
    this.windowBuffer = windowBufferFactory.create(ctx.getOperatorOwner(), ctx.getMemoryManager(), ctx.getMemorySize(), ctx.getRuntimeContext(), windowTimerService, ctx.getKeyedStateBackend(), windowState, isEventTime, shiftTimeZone);
    this.reuseOutput = new JoinedRowData();
    this.currentProgress = Long.MIN_VALUE;
    this.nextTriggerProgress = Long.MIN_VALUE;
}
Also used : RowData(org.apache.flink.table.data.RowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) InternalValueState(org.apache.flink.runtime.state.internal.InternalValueState) LongSerializer(org.apache.flink.api.common.typeutils.base.LongSerializer) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) PerWindowStateDataViewStore(org.apache.flink.table.runtime.dataview.PerWindowStateDataViewStore) WindowTimerServiceImpl(org.apache.flink.table.runtime.operators.window.slicing.WindowTimerServiceImpl)

Aggregations

InternalValueState (org.apache.flink.runtime.state.internal.InternalValueState)2 RowData (org.apache.flink.table.data.RowData)2 PerWindowStateDataViewStore (org.apache.flink.table.runtime.dataview.PerWindowStateDataViewStore)2 ValueState (org.apache.flink.api.common.state.ValueState)1 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)1 LongSerializer (org.apache.flink.api.common.typeutils.base.LongSerializer)1 MeterView (org.apache.flink.metrics.MeterView)1 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)1 MergingWindowAssigner (org.apache.flink.table.runtime.operators.window.assigners.MergingWindowAssigner)1 PanedWindowAssigner (org.apache.flink.table.runtime.operators.window.assigners.PanedWindowAssigner)1 GeneralWindowProcessFunction (org.apache.flink.table.runtime.operators.window.internal.GeneralWindowProcessFunction)1 PanedWindowProcessFunction (org.apache.flink.table.runtime.operators.window.internal.PanedWindowProcessFunction)1 WindowTimerServiceImpl (org.apache.flink.table.runtime.operators.window.slicing.WindowTimerServiceImpl)1 RowDataSerializer (org.apache.flink.table.runtime.typeutils.RowDataSerializer)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1