Repository: apache/flink
File: flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/operators/over/SumLongAggsHandleFunction.java (Java)

Code before:
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.flink.table.runtime.operators.over;

import org.apache.flink.table.data.GenericRowData;
import org.apache.flink.table.data.RowData;
import org.apache.flink.table.runtime.dataview.StateDataViewStore;
import org.apache.flink.table.runtime.generated.AggsHandleFunction;

/** Test {@link AggsHandleFunction}. */
public class SumLongAggsHandleFunction implements AggsHandleFunction {

    private final int inputIndex;
    private Long sum;

    public SumLongAggsHandleFunction(int inputIndex) {
        this.inputIndex = inputIndex;
    }

    @Override
    public void open(StateDataViewStore store) throws Exception {}

    @Override
    public void accumulate(RowData input) throws Exception {
        sum += input.getLong(inputIndex);
    }

    @Override
    public void retract(RowData input) throws Exception {
        sum -= input.getLong(inputIndex);
    }

    @Override
    public void merge(RowData accumulator) throws Exception {
        sum += accumulator.getLong(0);
    }

Review comment (suggestion):
nit:
```suggestion
class SumLongAggsHandleFunction implements AggsHandleFunction {
```
no need to have it public if it is used in same package only

Code after:
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.flink.table.runtime.operators.over;

import org.apache.flink.table.data.GenericRowData;
import org.apache.flink.table.data.RowData;
import org.apache.flink.table.runtime.dataview.StateDataViewStore;
import org.apache.flink.table.runtime.generated.AggsHandleFunction;

/** Test {@link AggsHandleFunction}. */
class SumLongAggsHandleFunction implements AggsHandleFunction {

    private final int inputIndex;
    private Long sum;

    public SumLongAggsHandleFunction(int inputIndex) {
        this.inputIndex = inputIndex;
    }

    @Override
    public void open(StateDataViewStore store) throws Exception {}

    @Override
    public void accumulate(RowData input) throws Exception {
        sum += input.getLong(inputIndex);
    }

    @Override
    public void retract(RowData input) throws Exception {
        sum -= input.getLong(inputIndex);
    }

    @Override
    public void merge(RowData accumulator) throws Exception {
        sum += accumulator.getLong(0);
    }