bvarghese1 commented on code in PR #25753: URL: https://github.com/apache/flink/pull/25753#discussion_r1908156348
########## flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/over/NonTimeUnboundedPrecedingFunction.java: ########## @@ -0,0 +1,591 @@ +/* + * 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.api.common.functions.OpenContext; +import org.apache.flink.api.common.state.MapState; +import org.apache.flink.api.common.state.MapStateDescriptor; +import org.apache.flink.api.common.state.ValueState; +import org.apache.flink.api.common.state.ValueStateDescriptor; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.java.typeutils.ListTypeInfo; +import org.apache.flink.streaming.api.functions.KeyedProcessFunction; +import org.apache.flink.table.api.DataTypes; +import org.apache.flink.table.data.GenericRowData; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.data.RowData.FieldGetter; +import org.apache.flink.table.data.utils.JoinedRowData; +import org.apache.flink.table.runtime.dataview.PerKeyStateDataViewStore; +import org.apache.flink.table.runtime.functions.KeyedProcessFunctionWithCleanupState; +import org.apache.flink.table.runtime.generated.AggsHandleFunction; +import org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction; +import org.apache.flink.table.runtime.generated.GeneratedRecordComparator; +import org.apache.flink.table.runtime.generated.GeneratedRecordEqualiser; +import org.apache.flink.table.runtime.generated.RecordEqualiser; +import org.apache.flink.table.runtime.typeutils.InternalTypeInfo; +import org.apache.flink.table.types.logical.LogicalType; +import org.apache.flink.table.types.logical.RowType; +import org.apache.flink.types.RowKind; +import org.apache.flink.util.Collector; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.ListIterator; + +/** A basic implementation to support non-time unbounded over aggregate with retract mode. */ +public class NonTimeUnboundedPrecedingFunction<K> + extends KeyedProcessFunctionWithCleanupState<K, RowData, RowData> { + private static final long serialVersionUID = 1L; + + private static final Logger LOG = + LoggerFactory.getLogger(NonTimeUnboundedPrecedingFunction.class); + + private final int keyIdx; + private final int sortKeyIdx; + private final FieldGetter sortKeyFieldGetter; + + private final GeneratedAggsHandleFunction genAggsHandler; + private final GeneratedRecordEqualiser generatedRecordEqualiser; + private final GeneratedRecordComparator generatedRecordComparator; + private final GeneratedRecordComparator keyGeneratedRecordComparator; + + // The util to compare two rows based on the sort attribute. + private transient Comparator<RowData> sortKeyComparator; + private transient Comparator<RowData> newSortKeyComparator; + // The record equaliser used to equal RowData. + private transient RecordEqualiser equaliser; + + private final LogicalType[] accTypes; + private final LogicalType[] inputFieldTypes; + protected transient JoinedRowData output; + + // state to hold the accumulators of the aggregations + private transient ValueState<RowData> accState; + // state to hold rows until state ttl expires + private transient ValueState<List<RowData>> inputState; + + // state to hold the Long ID counter + private transient ValueState<Long> idState; + + // state to hold a list of sorted keys with an artificial id + // The artificial id acts as the key in the valueMapState + private transient ValueState<List<RowData>> sortedKeyState; Review Comment: For time-ordered over aggregates, ORDER BY is only supported for 1 time-column and only in ASC order. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org