You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2021/01/11 08:19:31 UTC

[GitHub] [flink] godfreyhe opened a new pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

godfreyhe opened a new pull request #14605:
URL: https://github.com/apache/flink/pull/14605


   ## What is the purpose of the change
   
   *Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate*
   
   
   ## Brief change log
   
     - *Introduce StreamPhysicalOverAggregate, and make StreamExecOverAggregate only extended from ExecNode*
     - *Introduce StreamPhysicalPythonOverAggregate, and make StreamExecPythonOverAggregate only extended from ExecNode*
     - *Introduce BatchPhysicalOverAggregate, and make BatchExecOverAggregate only extended from ExecNode*
     - *Introduce BatchPhysicalPythonOverAggregate, and make BatchExecPythonOverAggregate only extended from ExecNode*
   
   ## Verifying this change
   
   This change is a refactoring rework covered by existing tests.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / **no**)
     - The serializers: (yes / **no** / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: (yes / **no** / don't know)
     - The S3 file system connector: (yes / **no** / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / **no**)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / **not documented**)
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757729308


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870",
       "triggerID" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "triggerType" : "PUSH"
     }, {
       "hash" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11930",
       "triggerID" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "1bbba19ff3ea721d502f433ba3e53936f3851799",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11981",
       "triggerID" : "1bbba19ff3ea721d502f433ba3e53936f3851799",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 1bbba19ff3ea721d502f433ba3e53936f3851799 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11981) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757701873


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit 3dd4ffb51cd59a27ac7bcefc74197e1f2e1bbdaa (Fri May 28 07:07:15 UTC 2021)
   
   **Warnings:**
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>


-- 
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757729308


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870",
       "triggerID" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "triggerType" : "PUSH"
     }, {
       "hash" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 02798e50851d0f9451baee20931ce1c9a4a74c00 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870) 
   * 55a64d4a7571435e96eece7db5aa2d919fd03de7 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] godfreyhe commented on a change in pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on a change in pull request #14605:
URL: https://github.com/apache/flink/pull/14605#discussion_r556397774



##########
File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecOverAggregate.java
##########
@@ -0,0 +1,380 @@
+/*
+ * 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.planner.plan.nodes.exec.stream;
+
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.streaming.api.functions.KeyedProcessFunction;
+import org.apache.flink.streaming.api.operators.KeyedProcessOperator;
+import org.apache.flink.streaming.api.transformations.OneInputTransformation;
+import org.apache.flink.table.api.TableConfig;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.planner.calcite.FlinkTypeFactory;
+import org.apache.flink.table.planner.codegen.CodeGeneratorContext;
+import org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator;
+import org.apache.flink.table.planner.delegation.PlannerBase;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecEdge;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNode;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeBase;
+import org.apache.flink.table.planner.plan.nodes.exec.utils.OverSpec;
+import org.apache.flink.table.planner.plan.utils.AggregateInfoList;
+import org.apache.flink.table.planner.plan.utils.AggregateUtil;
+import org.apache.flink.table.planner.plan.utils.KeySelectorUtil;
+import org.apache.flink.table.planner.plan.utils.OverAggregateUtil;
+import org.apache.flink.table.planner.utils.JavaScalaConversionUtil;
+import org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction;
+import org.apache.flink.table.runtime.keyselector.RowDataKeySelector;
+import org.apache.flink.table.runtime.operators.over.ProcTimeRangeBoundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.ProcTimeRowsBoundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.ProcTimeUnboundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.RowTimeRangeBoundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.RowTimeRangeUnboundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.RowTimeRowsBoundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.RowTimeRowsUnboundedPrecedingFunction;
+import org.apache.flink.table.runtime.types.LogicalTypeDataTypeConverter;
+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.table.types.logical.TimestampKind;
+import org.apache.flink.table.types.logical.TimestampType;
+
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.tools.RelBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.IntStream;
+
+/** Stream {@link ExecNode} for time-based over operator. */
+public class StreamExecOverAggregate extends ExecNodeBase<RowData>
+        implements StreamExecNode<RowData> {
+    private static final Logger LOG = LoggerFactory.getLogger(StreamExecOverAggregate.class);
+
+    private final OverSpec overSpec;
+
+    public StreamExecOverAggregate(
+            OverSpec overSpec, ExecEdge inputEdge, RowType outputType, String description) {
+        super(Collections.singletonList(inputEdge), outputType, description);
+        this.overSpec = overSpec;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    protected Transformation<RowData> translateToPlanInternal(PlannerBase planner) {
+        if (overSpec.getGroups().size() > 1) {
+            throw new TableException("All aggregates must be computed on the same window.");
+        }
+
+        final OverSpec.GroupSpec group = overSpec.getGroups().get(0);
+        final int[] orderKeys = group.getSort().getFieldIndices();
+        final boolean[] isAscendingOrders = group.getSort().getAscendingOrders();
+        if (orderKeys.length != 1 || isAscendingOrders.length != 1) {
+            throw new TableException("The window can only be ordered by a single time column.");
+        }
+
+        if (!isAscendingOrders[0]) {
+            throw new TableException("The window can only be ordered in ASCENDING mode.");
+        }
+
+        final int[] partitionKeys = overSpec.getPartition().getFieldIndices();
+        final TableConfig tableConfig = planner.getTableConfig();
+        if (partitionKeys.length > 0 && tableConfig.getMinIdleStateRetentionTime() < 0) {
+            LOG.warn(
+                    "No state retention interval configured for a query which accumulates state. "
+                            + "Please provide a query configuration with valid retention interval to prevent "
+                            + "excessive state size. You may specify a retention time of 0 to not clean up the state.");
+        }
+
+        final ExecNode<RowData> inputNode = (ExecNode<RowData>) getInputNodes().get(0);
+        final Transformation<RowData> inputTransform = inputNode.translateToPlan(planner);
+        final RowType inputRowType = (RowType) inputNode.getOutputType();
+
+        final int orderKey = orderKeys[0];
+        final LogicalType orderKeyType = inputRowType.getFields().get(orderKey).getType();
+        // check time field && identify window rowtime attribute
+        final int rowTimeIdx;
+        if (orderKeyType instanceof TimestampType
+                && ((TimestampType) orderKeyType).getKind() == TimestampKind.ROWTIME) {
+            rowTimeIdx = orderKey;
+        } else if (orderKeyType instanceof TimestampType
+                && ((TimestampType) orderKeyType).getKind() == TimestampKind.PROCTIME) {
+            rowTimeIdx = -1;
+        } else {
+            throw new TableException(
+                    "OVER windows' ordering in stream mode must be defined on a time attribute.");
+        }
+
+        final List<RexLiteral> constants = overSpec.getConstants();
+        final List<String> fieldNames = new ArrayList<>(inputRowType.getFieldNames());
+        final List<LogicalType> fieldTypes = new ArrayList<>(inputRowType.getChildren());
+        IntStream.range(0, constants.size()).forEach(i -> fieldNames.add("TMP" + i));
+        for (int i = 0; i < constants.size(); ++i) {
+            fieldNames.add("TMP" + i);
+            fieldTypes.add(FlinkTypeFactory.toLogicalType(constants.get(i).getType()));
+        }
+
+        final RowType aggInputRowType =
+                RowType.of(
+                        fieldTypes.toArray(new LogicalType[0]), fieldNames.toArray(new String[0]));

Review comment:
       I think it's easy for debug




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757729308


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 02798e50851d0f9451baee20931ce1c9a4a74c00 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] godfreyhe closed pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
godfreyhe closed pull request #14605:
URL: https://github.com/apache/flink/pull/14605


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757729308


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870",
       "triggerID" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 02798e50851d0f9451baee20931ce1c9a4a74c00 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757729308


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870",
       "triggerID" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "triggerType" : "PUSH"
     }, {
       "hash" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11930",
       "triggerID" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "1bbba19ff3ea721d502f433ba3e53936f3851799",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11981",
       "triggerID" : "1bbba19ff3ea721d502f433ba3e53936f3851799",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 55a64d4a7571435e96eece7db5aa2d919fd03de7 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11930) 
   * 1bbba19ff3ea721d502f433ba3e53936f3851799 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11981) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757729308


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870",
       "triggerID" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "triggerType" : "PUSH"
     }, {
       "hash" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11930",
       "triggerID" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 02798e50851d0f9451baee20931ce1c9a4a74c00 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870) 
   * 55a64d4a7571435e96eece7db5aa2d919fd03de7 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11930) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] godfreyhe commented on a change in pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on a change in pull request #14605:
URL: https://github.com/apache/flink/pull/14605#discussion_r556399309



##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/nodes/physical/batch/BatchPhysicalOverAggregateBase.scala
##########
@@ -18,88 +18,50 @@
 
 package org.apache.flink.table.planner.plan.nodes.physical.batch
 
-import org.apache.flink.table.data.RowData
-import org.apache.flink.table.functions.UserDefinedFunction
+import org.apache.flink.table.api.TableException
 import org.apache.flink.table.planner.CalcitePair
-import org.apache.flink.table.planner.calcite.FlinkTypeFactory
 import org.apache.flink.table.planner.plan.`trait`.{FlinkRelDistribution, FlinkRelDistributionTraitDef}
 import org.apache.flink.table.planner.plan.cost.{FlinkCost, FlinkCostFactory}
-import org.apache.flink.table.planner.plan.nodes.exec.{LegacyBatchExecNode, ExecEdge}
-import org.apache.flink.table.planner.plan.nodes.physical.batch.OverWindowMode.OverWindowMode
 import org.apache.flink.table.planner.plan.rules.physical.batch.BatchExecJoinRuleBase
+import org.apache.flink.table.planner.plan.utils.OverAggregateUtil.splitOutOffsetOrInsensitiveGroup
 import org.apache.flink.table.planner.plan.utils.{FlinkRelOptUtil, OverAggregateUtil, RelExplainUtil}
 
-import com.google.common.collect.ImmutableList
 import org.apache.calcite.plan._
 import org.apache.calcite.rel.RelDistribution.Type._
 import org.apache.calcite.rel._
 import org.apache.calcite.rel.`type`.RelDataType
 import org.apache.calcite.rel.core.Window.Group
 import org.apache.calcite.rel.core.{AggregateCall, Window}
 import org.apache.calcite.rel.metadata.RelMetadataQuery
-import org.apache.calcite.rex.RexLiteral
-import org.apache.calcite.sql.fun.SqlLeadLagAggFunction
-import org.apache.calcite.tools.RelBuilder
 import org.apache.calcite.util.ImmutableIntList
 
 import java.util
 
 import scala.collection.JavaConversions._
-import scala.collection.mutable.ArrayBuffer
 
 /**
-  * Batch physical RelNode for sort-based over [[Window]] aggregate.
-  */
-abstract class BatchExecOverAggregateBase(
+ * Base batch physical RelNode for sort-based over [[Window]] aggregate.
+ */
+abstract class BatchPhysicalOverAggregateBase(
     cluster: RelOptCluster,
-    relBuilder: RelBuilder,
     traitSet: RelTraitSet,
     inputRel: RelNode,
     outputRowType: RelDataType,
     inputRowType: RelDataType,
-    grouping: Array[Int],
-    orderKeyIndices: Array[Int],
-    orders: Array[Boolean],
-    nullIsLasts: Array[Boolean],
-    windowGroupToAggCallToAggFunction: Seq[
-      (Window.Group, Seq[(AggregateCall, UserDefinedFunction)])],
+    windowGroups: Seq[Window.Group],
     logicWindow: Window)
   extends SingleRel(cluster, traitSet, inputRel)
-  with BatchPhysicalRel
-  with LegacyBatchExecNode[RowData] {
-
-  protected lazy val modeToGroupToAggCallToAggFunction:
-    Seq[(OverWindowMode, Window.Group, Seq[(AggregateCall, UserDefinedFunction)])] =
-    splitOutOffsetOrInsensitiveGroup()
+  with BatchPhysicalRel {
 
-  protected val constants: ImmutableList[RexLiteral] = logicWindow.constants
-  protected val inputTypeWithConstants: RelDataType = {
-    val constantTypes = constants.map(c => FlinkTypeFactory.toLogicalType(c.getType))
-    val inputTypeNamesWithConstants =
-      inputType.getFieldNames ++ constants.indices.map(i => "TMP" + i)
-    val inputTypesWithConstants = inputType.getChildren ++ constantTypes
-    cluster.getTypeFactory.asInstanceOf[FlinkTypeFactory]
-      .buildRelNodeRowType(inputTypeNamesWithConstants, inputTypesWithConstants)
+  val partitionKeyIndices: Array[Int] = windowGroups.head.keys.toArray
+  windowGroups.tail.foreach { g =>
+    if (!util.Arrays.equals(partitionKeyIndices, g.keys.toArray)) {
+      throw new TableException("" +
+        "BatchPhysicalOverAggregateBase requires all groups should have same partition key.")
+    }
   }
 
-  lazy val aggregateCalls: Seq[AggregateCall] =
-    windowGroupToAggCallToAggFunction.flatMap(_._2).map(_._1)
-
-  protected lazy val inputType = FlinkTypeFactory.toLogicalRowType(inputRowType)
-
-  protected def isUnboundedWindow(group: Window.Group) =
-    group.lowerBound.isUnbounded && group.upperBound.isUnbounded
-
-  protected def isUnboundedPrecedingWindow(group: Window.Group) =
-    group.lowerBound.isUnbounded && !group.upperBound.isUnbounded
-
-  protected def isUnboundedFollowingWindow(group: Window.Group) =
-    !group.lowerBound.isUnbounded && group.upperBound.isUnbounded
-
-  protected def isSlidingWindow(group: Window.Group) =
-    !group.lowerBound.isUnbounded && !group.upperBound.isUnbounded
-
-  def getGrouping: Array[Int] = grouping
+  protected lazy val newWindowGroups: Seq[Group] = splitOutOffsetOrInsensitiveGroup(windowGroups)

Review comment:
       how about `offsetAndInsensitiveSensitiveGroups`




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757729308


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870",
       "triggerID" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "triggerType" : "PUSH"
     }, {
       "hash" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11930",
       "triggerID" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 55a64d4a7571435e96eece7db5aa2d919fd03de7 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11930) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757729308


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870",
       "triggerID" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "triggerType" : "PUSH"
     }, {
       "hash" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11930",
       "triggerID" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "1bbba19ff3ea721d502f433ba3e53936f3851799",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "1bbba19ff3ea721d502f433ba3e53936f3851799",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 55a64d4a7571435e96eece7db5aa2d919fd03de7 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11930) 
   * 1bbba19ff3ea721d502f433ba3e53936f3851799 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757729308


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870",
       "triggerID" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "triggerType" : "PUSH"
     }, {
       "hash" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11930",
       "triggerID" : "55a64d4a7571435e96eece7db5aa2d919fd03de7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "1bbba19ff3ea721d502f433ba3e53936f3851799",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11981",
       "triggerID" : "1bbba19ff3ea721d502f433ba3e53936f3851799",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3dd4ffb51cd59a27ac7bcefc74197e1f2e1bbdaa",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "3dd4ffb51cd59a27ac7bcefc74197e1f2e1bbdaa",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 1bbba19ff3ea721d502f433ba3e53936f3851799 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11981) 
   * 3dd4ffb51cd59a27ac7bcefc74197e1f2e1bbdaa UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757701873


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit 6db626f5e47ae523ed8d35ec6c6971a6ad4934d8 (Mon Jan 11 08:22:49 UTC 2021)
   
   **Warnings:**
    * **1 pom.xml files were touched**: Check for build and licensing issues.
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-757729308


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870",
       "triggerID" : "02798e50851d0f9451baee20931ce1c9a4a74c00",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 02798e50851d0f9451baee20931ce1c9a4a74c00 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=11870) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] wenlong88 commented on a change in pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
wenlong88 commented on a change in pull request #14605:
URL: https://github.com/apache/flink/pull/14605#discussion_r556283456



##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/codegen/over/MultiFieldRangeBoundComparatorCodeGenerator.scala
##########
@@ -48,9 +46,14 @@ class MultiFieldRangeBoundComparatorCodeGenerator(
     }
 
     val ctx = CodeGeneratorContext(conf)
-
     val compareCode = GenerateUtils.generateRowCompare(

Review comment:
       use the new method accepts sortSpec

##########
File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecOverAggregate.java
##########
@@ -0,0 +1,380 @@
+/*
+ * 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.planner.plan.nodes.exec.stream;
+
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.streaming.api.functions.KeyedProcessFunction;
+import org.apache.flink.streaming.api.operators.KeyedProcessOperator;
+import org.apache.flink.streaming.api.transformations.OneInputTransformation;
+import org.apache.flink.table.api.TableConfig;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.planner.calcite.FlinkTypeFactory;
+import org.apache.flink.table.planner.codegen.CodeGeneratorContext;
+import org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator;
+import org.apache.flink.table.planner.delegation.PlannerBase;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecEdge;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNode;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeBase;
+import org.apache.flink.table.planner.plan.nodes.exec.utils.OverSpec;
+import org.apache.flink.table.planner.plan.utils.AggregateInfoList;
+import org.apache.flink.table.planner.plan.utils.AggregateUtil;
+import org.apache.flink.table.planner.plan.utils.KeySelectorUtil;
+import org.apache.flink.table.planner.plan.utils.OverAggregateUtil;
+import org.apache.flink.table.planner.utils.JavaScalaConversionUtil;
+import org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction;
+import org.apache.flink.table.runtime.keyselector.RowDataKeySelector;
+import org.apache.flink.table.runtime.operators.over.ProcTimeRangeBoundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.ProcTimeRowsBoundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.ProcTimeUnboundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.RowTimeRangeBoundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.RowTimeRangeUnboundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.RowTimeRowsBoundedPrecedingFunction;
+import org.apache.flink.table.runtime.operators.over.RowTimeRowsUnboundedPrecedingFunction;
+import org.apache.flink.table.runtime.types.LogicalTypeDataTypeConverter;
+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.table.types.logical.TimestampKind;
+import org.apache.flink.table.types.logical.TimestampType;
+
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.tools.RelBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.IntStream;
+
+/** Stream {@link ExecNode} for time-based over operator. */
+public class StreamExecOverAggregate extends ExecNodeBase<RowData>
+        implements StreamExecNode<RowData> {
+    private static final Logger LOG = LoggerFactory.getLogger(StreamExecOverAggregate.class);
+
+    private final OverSpec overSpec;
+
+    public StreamExecOverAggregate(
+            OverSpec overSpec, ExecEdge inputEdge, RowType outputType, String description) {
+        super(Collections.singletonList(inputEdge), outputType, description);
+        this.overSpec = overSpec;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    protected Transformation<RowData> translateToPlanInternal(PlannerBase planner) {
+        if (overSpec.getGroups().size() > 1) {
+            throw new TableException("All aggregates must be computed on the same window.");
+        }
+
+        final OverSpec.GroupSpec group = overSpec.getGroups().get(0);
+        final int[] orderKeys = group.getSort().getFieldIndices();
+        final boolean[] isAscendingOrders = group.getSort().getAscendingOrders();
+        if (orderKeys.length != 1 || isAscendingOrders.length != 1) {
+            throw new TableException("The window can only be ordered by a single time column.");
+        }
+
+        if (!isAscendingOrders[0]) {
+            throw new TableException("The window can only be ordered in ASCENDING mode.");
+        }
+
+        final int[] partitionKeys = overSpec.getPartition().getFieldIndices();
+        final TableConfig tableConfig = planner.getTableConfig();
+        if (partitionKeys.length > 0 && tableConfig.getMinIdleStateRetentionTime() < 0) {
+            LOG.warn(
+                    "No state retention interval configured for a query which accumulates state. "
+                            + "Please provide a query configuration with valid retention interval to prevent "
+                            + "excessive state size. You may specify a retention time of 0 to not clean up the state.");
+        }
+
+        final ExecNode<RowData> inputNode = (ExecNode<RowData>) getInputNodes().get(0);
+        final Transformation<RowData> inputTransform = inputNode.translateToPlan(planner);
+        final RowType inputRowType = (RowType) inputNode.getOutputType();
+
+        final int orderKey = orderKeys[0];
+        final LogicalType orderKeyType = inputRowType.getFields().get(orderKey).getType();
+        // check time field && identify window rowtime attribute
+        final int rowTimeIdx;
+        if (orderKeyType instanceof TimestampType
+                && ((TimestampType) orderKeyType).getKind() == TimestampKind.ROWTIME) {
+            rowTimeIdx = orderKey;
+        } else if (orderKeyType instanceof TimestampType
+                && ((TimestampType) orderKeyType).getKind() == TimestampKind.PROCTIME) {
+            rowTimeIdx = -1;
+        } else {
+            throw new TableException(
+                    "OVER windows' ordering in stream mode must be defined on a time attribute.");
+        }
+
+        final List<RexLiteral> constants = overSpec.getConstants();
+        final List<String> fieldNames = new ArrayList<>(inputRowType.getFieldNames());
+        final List<LogicalType> fieldTypes = new ArrayList<>(inputRowType.getChildren());
+        IntStream.range(0, constants.size()).forEach(i -> fieldNames.add("TMP" + i));
+        for (int i = 0; i < constants.size(); ++i) {
+            fieldNames.add("TMP" + i);
+            fieldTypes.add(FlinkTypeFactory.toLogicalType(constants.get(i).getType()));
+        }
+
+        final RowType aggInputRowType =
+                RowType.of(
+                        fieldTypes.toArray(new LogicalType[0]), fieldNames.toArray(new String[0]));

Review comment:
       not need to create the fieldName?

##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/nodes/physical/batch/BatchPhysicalOverAggregateBase.scala
##########
@@ -18,88 +18,50 @@
 
 package org.apache.flink.table.planner.plan.nodes.physical.batch
 
-import org.apache.flink.table.data.RowData
-import org.apache.flink.table.functions.UserDefinedFunction
+import org.apache.flink.table.api.TableException
 import org.apache.flink.table.planner.CalcitePair
-import org.apache.flink.table.planner.calcite.FlinkTypeFactory
 import org.apache.flink.table.planner.plan.`trait`.{FlinkRelDistribution, FlinkRelDistributionTraitDef}
 import org.apache.flink.table.planner.plan.cost.{FlinkCost, FlinkCostFactory}
-import org.apache.flink.table.planner.plan.nodes.exec.{LegacyBatchExecNode, ExecEdge}
-import org.apache.flink.table.planner.plan.nodes.physical.batch.OverWindowMode.OverWindowMode
 import org.apache.flink.table.planner.plan.rules.physical.batch.BatchExecJoinRuleBase
+import org.apache.flink.table.planner.plan.utils.OverAggregateUtil.splitOutOffsetOrInsensitiveGroup
 import org.apache.flink.table.planner.plan.utils.{FlinkRelOptUtil, OverAggregateUtil, RelExplainUtil}
 
-import com.google.common.collect.ImmutableList
 import org.apache.calcite.plan._
 import org.apache.calcite.rel.RelDistribution.Type._
 import org.apache.calcite.rel._
 import org.apache.calcite.rel.`type`.RelDataType
 import org.apache.calcite.rel.core.Window.Group
 import org.apache.calcite.rel.core.{AggregateCall, Window}
 import org.apache.calcite.rel.metadata.RelMetadataQuery
-import org.apache.calcite.rex.RexLiteral
-import org.apache.calcite.sql.fun.SqlLeadLagAggFunction
-import org.apache.calcite.tools.RelBuilder
 import org.apache.calcite.util.ImmutableIntList
 
 import java.util
 
 import scala.collection.JavaConversions._
-import scala.collection.mutable.ArrayBuffer
 
 /**
-  * Batch physical RelNode for sort-based over [[Window]] aggregate.
-  */
-abstract class BatchExecOverAggregateBase(
+ * Base batch physical RelNode for sort-based over [[Window]] aggregate.
+ */
+abstract class BatchPhysicalOverAggregateBase(
     cluster: RelOptCluster,
-    relBuilder: RelBuilder,
     traitSet: RelTraitSet,
     inputRel: RelNode,
     outputRowType: RelDataType,
     inputRowType: RelDataType,
-    grouping: Array[Int],
-    orderKeyIndices: Array[Int],
-    orders: Array[Boolean],
-    nullIsLasts: Array[Boolean],
-    windowGroupToAggCallToAggFunction: Seq[
-      (Window.Group, Seq[(AggregateCall, UserDefinedFunction)])],
+    windowGroups: Seq[Window.Group],
     logicWindow: Window)
   extends SingleRel(cluster, traitSet, inputRel)
-  with BatchPhysicalRel
-  with LegacyBatchExecNode[RowData] {
-
-  protected lazy val modeToGroupToAggCallToAggFunction:
-    Seq[(OverWindowMode, Window.Group, Seq[(AggregateCall, UserDefinedFunction)])] =
-    splitOutOffsetOrInsensitiveGroup()
+  with BatchPhysicalRel {
 
-  protected val constants: ImmutableList[RexLiteral] = logicWindow.constants
-  protected val inputTypeWithConstants: RelDataType = {
-    val constantTypes = constants.map(c => FlinkTypeFactory.toLogicalType(c.getType))
-    val inputTypeNamesWithConstants =
-      inputType.getFieldNames ++ constants.indices.map(i => "TMP" + i)
-    val inputTypesWithConstants = inputType.getChildren ++ constantTypes
-    cluster.getTypeFactory.asInstanceOf[FlinkTypeFactory]
-      .buildRelNodeRowType(inputTypeNamesWithConstants, inputTypesWithConstants)
+  val partitionKeyIndices: Array[Int] = windowGroups.head.keys.toArray
+  windowGroups.tail.foreach { g =>
+    if (!util.Arrays.equals(partitionKeyIndices, g.keys.toArray)) {
+      throw new TableException("" +
+        "BatchPhysicalOverAggregateBase requires all groups should have same partition key.")
+    }
   }
 
-  lazy val aggregateCalls: Seq[AggregateCall] =
-    windowGroupToAggCallToAggFunction.flatMap(_._2).map(_._1)
-
-  protected lazy val inputType = FlinkTypeFactory.toLogicalRowType(inputRowType)
-
-  protected def isUnboundedWindow(group: Window.Group) =
-    group.lowerBound.isUnbounded && group.upperBound.isUnbounded
-
-  protected def isUnboundedPrecedingWindow(group: Window.Group) =
-    group.lowerBound.isUnbounded && !group.upperBound.isUnbounded
-
-  protected def isUnboundedFollowingWindow(group: Window.Group) =
-    !group.lowerBound.isUnbounded && group.upperBound.isUnbounded
-
-  protected def isSlidingWindow(group: Window.Group) =
-    !group.lowerBound.isUnbounded && !group.upperBound.isUnbounded
-
-  def getGrouping: Array[Int] = grouping
+  protected lazy val newWindowGroups: Seq[Group] = splitOutOffsetOrInsensitiveGroup(windowGroups)

Review comment:
       how about a more specified name?maybe reOrganizedGroups?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] godfreyhe commented on pull request #14605: [FLINK-20883][table-planner-blink] Separate the implementation of BatchExecOverAggregate and StreamExecOverAggregate

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on pull request #14605:
URL: https://github.com/apache/flink/pull/14605#issuecomment-759903000


   Thanks for the review, I will fix the conflicts in my local and merge the pr


----------------------------------------------------------------
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:
users@infra.apache.org