Github user twalthr commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3364#discussion_r104721437
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/aggregate/DataSetSlideWindowAggReduceCombineFunction.scala
 ---
    @@ -0,0 +1,88 @@
    +/*
    + * 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.aggregate
    +
    +import java.lang.Iterable
    +
    +import org.apache.flink.api.common.functions.CombineFunction
    +import org.apache.flink.types.Row
    +
    +/**
    +  * Wraps the aggregate logic inside of
    +  * [[org.apache.flink.api.java.operators.GroupReduceOperator]] and
    +  * [[org.apache.flink.api.java.operators.GroupCombineOperator]].
    +  *
    +  * It is used for sliding on batch for both time and count-windows.
    +  *
    +  * @param aggregates aggregate functions.
    +  * @param groupKeysMapping index mapping of group keys between 
intermediate aggregate Row
    +  *                         and output Row.
    +  * @param aggregateMapping index mapping between aggregate function list 
and aggregated value
    +  *                         index in output Row.
    +  * @param intermediateRowArity intermediate row field count
    +  * @param finalRowArity output row field count
    +  * @param finalRowWindowStartPos relative window-start position to last 
field of output row
    +  * @param finalRowWindowEndPos relative window-end position to last field 
of output row
    +  * @param windowSize size of the window, used to determine window-end for 
output row
    +  */
    +class DataSetSlideWindowAggReduceCombineFunction(
    +    aggregates: Array[Aggregate[_ <: Any]],
    +    groupKeysMapping: Array[(Int, Int)],
    +    aggregateMapping: Array[(Int, Int)],
    +    intermediateRowArity: Int,
    +    finalRowArity: Int,
    +    finalRowWindowStartPos: Option[Int],
    +    finalRowWindowEndPos: Option[Int],
    +    windowSize: Long)
    +  extends DataSetSlideWindowAggReduceGroupFunction(
    +    aggregates,
    +    groupKeysMapping,
    +    aggregateMapping,
    +    intermediateRowArity,
    +    finalRowArity,
    +    finalRowWindowStartPos,
    +    finalRowWindowEndPos,
    +    windowSize)
    +  with CombineFunction[Row, Row] {
    +
    +  override def combine(records: Iterable[Row]): Row = {
    +    // initiate intermediate aggregate value
    +    aggregates.foreach(_.initiate(aggregateBuffer))
    +
    +    val iterator = records.iterator()
    +    while (iterator.hasNext) {
    +      val record = iterator.next()
    +      aggregates.foreach(_.merge(record, aggregateBuffer))
    +
    +      // check if this record is the last record
    +      if (!iterator.hasNext) {
    +        // set group keys to aggregateBuffer
    +        for (i <- groupKeysMapping.indices) {
    +          aggregateBuffer.setField(i, record.getField(i))
    +        }
    +
    +        aggregateBuffer.setField(windowStartFieldPos, 
record.getField(windowStartFieldPos))
    +
    +        return aggregateBuffer
    +      }
    +    }
    +
    +    // this code path should never be reached as we return before the loop 
finishes
    +    throw new IllegalArgumentException("Group is empty. This should never 
happen.")
    --- End diff --
    
    I cannot remove it. The compiler complains otherwise.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to