Search in sources :

Example 1 with AggsHandleFunction

use of org.apache.flink.table.runtime.generated.AggsHandleFunction in project flink by apache.

the class NonBufferOverWindowOperator method open.

@Override
public void open() throws Exception {
    super.open();
    ClassLoader cl = getUserCodeClassloader();
    serializer = (AbstractRowDataSerializer) getOperatorConfig().getTypeSerializerIn1(cl);
    partitionComparator = genComparator.newInstance(cl);
    genComparator = null;
    collector = new StreamRecordCollector<>(output);
    processors = new AggsHandleFunction[aggsHandlers.length];
    joinedRows = new JoinedRowData[aggsHandlers.length];
    for (int i = 0; i < aggsHandlers.length; i++) {
        AggsHandleFunction func = aggsHandlers[i].newInstance(cl);
        func.open(new PerKeyStateDataViewStore(getRuntimeContext()));
        processors[i] = func;
        joinedRows[i] = new JoinedRowData();
    }
    aggsHandlers = null;
}
Also used : JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) AggsHandleFunction(org.apache.flink.table.runtime.generated.AggsHandleFunction) GeneratedAggsHandleFunction(org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction) PerKeyStateDataViewStore(org.apache.flink.table.runtime.dataview.PerKeyStateDataViewStore)

Example 2 with AggsHandleFunction

use of org.apache.flink.table.runtime.generated.AggsHandleFunction in project flink by apache.

the class NonBufferOverWindowOperator method processElement.

@Override
public void processElement(StreamRecord<RowData> element) throws Exception {
    RowData input = element.getValue();
    boolean changePartition = lastInput == null || partitionComparator.compare(lastInput, input) != 0;
    // calculate the ACC
    RowData output = input;
    for (int i = 0; i < processors.length; i++) {
        AggsHandleFunction processor = processors[i];
        if (changePartition || resetAccumulators[i]) {
            processor.setAccumulators(processor.createAccumulators());
        }
        // TODO Reform AggsHandleFunction.getValue instead of use JoinedRowData. Multilayer
        // JoinedRowData is slow.
        processor.accumulate(input);
        RowData value = processor.getValue();
        output = joinedRows[i].replace(output, value);
    }
    collector.collect(output);
    if (changePartition) {
        lastInput = serializer.copy(input);
    }
}
Also used : RowData(org.apache.flink.table.data.RowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) AggsHandleFunction(org.apache.flink.table.runtime.generated.AggsHandleFunction) GeneratedAggsHandleFunction(org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction)

Aggregations

JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)2 AggsHandleFunction (org.apache.flink.table.runtime.generated.AggsHandleFunction)2 GeneratedAggsHandleFunction (org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction)2 RowData (org.apache.flink.table.data.RowData)1 PerKeyStateDataViewStore (org.apache.flink.table.runtime.dataview.PerKeyStateDataViewStore)1