HuangXingBo commented on a change in pull request #14775:
URL: https://github.com/apache/flink/pull/14775#discussion_r569213485



##########
File path: 
flink-python/src/main/java/org/apache/flink/table/runtime/operators/python/aggregate/PythonStreamGroupWindowAggregateOperator.java
##########
@@ -0,0 +1,342 @@
+/*
+ * 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.python.aggregate;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.fnexecution.v1.FlinkFnApi;
+import org.apache.flink.streaming.api.operators.InternalTimer;
+import org.apache.flink.streaming.api.operators.InternalTimerService;
+import org.apache.flink.streaming.api.operators.Triggerable;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.UpdatableRowData;
+import org.apache.flink.table.expressions.ValueLiteralExpression;
+import org.apache.flink.table.functions.python.PythonAggregateFunctionInfo;
+import org.apache.flink.table.planner.plan.logical.LogicalWindow;
+import org.apache.flink.table.planner.plan.logical.SessionGroupWindow;
+import org.apache.flink.table.planner.plan.logical.SlidingGroupWindow;
+import org.apache.flink.table.planner.plan.logical.TumblingGroupWindow;
+import org.apache.flink.table.planner.plan.utils.AggregateUtil;
+import org.apache.flink.table.planner.typeutils.DataViewUtils;
+import org.apache.flink.table.runtime.operators.window.CountWindow;
+import org.apache.flink.table.runtime.operators.window.TimeWindow;
+import org.apache.flink.table.runtime.operators.window.Window;
+import 
org.apache.flink.table.runtime.operators.window.assigners.WindowAssigner;
+import org.apache.flink.table.types.logical.BigIntType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.logical.TinyIntType;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** The Python Group Window AggregateFunction operator for the blink planner. 
*/
+@Internal
+public class PythonStreamGroupWindowAggregateOperator<K, W extends Window>
+        extends AbstractPythonStreamAggregateOperator implements 
Triggerable<K, W> {
+
+    private static final long serialVersionUID = 1L;
+
+    @VisibleForTesting
+    static final String STREAM_GROUP_WINDOW_AGGREGATE_URN =
+            "flink:transform:stream_group_window_aggregate:v1";
+
+    @VisibleForTesting static final byte REGISTER_EVENT_TIMER = 0;
+
+    @VisibleForTesting static final byte REGISTER_PROCESSING_TIMER = 1;
+
+    @VisibleForTesting static final byte DELETE_EVENT_TIMER = 2;
+
+    @VisibleForTesting static final byte DELETE_PROCESSING_TIMER = 4;
+
+    /** True if the count(*) agg is inserted by the planner. */
+    private final boolean countStarInserted;
+
+    /** The row time index of the input data. */
+    @VisibleForTesting final int inputTimeFieldIndex;
+
+    /**
+     * The allowed lateness for elements. This is used for:
+     *
+     * <ul>
+     *   <li>Deciding if an element should be dropped from a window due to 
lateness.
+     *   <li>Clearing the state of a window if the system time passes the 
{@code window.maxTimestamp
+     *       + allowedLateness} landmark.
+     * </ul>
+     */
+    @VisibleForTesting final long allowedLateness;
+
+    /**
+     * The Infos of the Window. 0 -> start of the Window. 1 -> end of the 
Window. 2 -> row time of
+     * the Window. 3 -> proc time of the Window.
+     */
+    private final int[] namedProperties;
+
+    /** A {@link WindowAssigner} assigns zero or more {@link Window Windows} 
to an element. */
+    @VisibleForTesting final WindowAssigner<W> windowAssigner;
+
+    /** Window Type includes Tumble window, Sliding window and Session Window. 
*/
+    private transient FlinkFnApi.GroupWindow.WindowType windowType;
+
+    /** Whether it is a row time window. */
+    private transient boolean isRowTime;
+
+    /** Whether it is a Time Window. */
+    private transient boolean isTimeWindow;
+
+    /** Window size. */
+    private transient long size;
+
+    /** Window slide. */
+    private transient long slide;
+
+    /** For serializing the window in checkpoints. */
+    @VisibleForTesting transient TypeSerializer<W> windowSerializer;
+
+    /** Interface for working with time and timers. */
+    private transient InternalTimerService<W> internalTimerService;
+
+    private UpdatableRowData reuseTimerData;
+
+    private int timerDataLength;
+
+    private int keyLength;
+
+    public PythonStreamGroupWindowAggregateOperator(
+            Configuration config,
+            RowType inputType,
+            RowType outputType,
+            PythonAggregateFunctionInfo[] aggregateFunctions,
+            DataViewUtils.DataViewSpec[][] dataViewSpecs,
+            int[] grouping,
+            int indexOfCountStar,
+            boolean generateUpdateBefore,
+            boolean countStarInserted,
+            int inputTimeFieldIndex,
+            WindowAssigner<W> windowAssigner,
+            LogicalWindow window,
+            long allowedLateness,
+            int[] namedProperties) {
+        super(
+                config,
+                inputType,
+                outputType,
+                aggregateFunctions,
+                dataViewSpecs,
+                grouping,
+                indexOfCountStar,
+                generateUpdateBefore);
+        this.countStarInserted = countStarInserted;
+        this.inputTimeFieldIndex = inputTimeFieldIndex;
+        this.windowAssigner = windowAssigner;
+        this.allowedLateness = allowedLateness;
+        this.namedProperties = namedProperties;
+        buildWindow(window);
+    }
+
+    @Override
+    public void open() throws Exception {
+        windowSerializer = windowAssigner.getWindowSerializer(new 
ExecutionConfig());
+        internalTimerService = getInternalTimerService("window-timers", 
windowSerializer, this);
+        if (isTimeWindow) {

Review comment:
       Yes. make sense.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to