Github user fhueske commented on a diff in the pull request:
https://github.com/apache/flink/pull/3364#discussion_r104522343
--- Diff:
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/plan/nodes/dataset/DataSetWindowAggregate.scala
---
@@ -280,6 +285,138 @@ class DataSetWindowAggregate(
}
}
+ private def createEventTimeSlidingWindowDataSet(
+ inputDS: DataSet[Row],
+ isTimeWindow: Boolean,
+ isParserCaseSensitive: Boolean)
+ : DataSet[Row] = {
+
+ // create MapFunction for initializing the aggregations
+ // it aligns the rowtime for pre-tumbling in case of a time-window for
incremental aggregates
+ val mapFunction = createDataSetWindowPrepareMapFunction(
+ window,
+ namedAggregates,
+ grouping,
+ inputType,
+ isParserCaseSensitive)
+
+ val mappedDataSet = inputDS
+ .map(mapFunction)
+ .name(prepareOperatorName)
+
+ val mapReturnType = mappedDataSet.getType
+
+ val rowTypeInfo = FlinkTypeFactory.toInternalRowTypeInfo(getRowType)
+ val groupingKeys = grouping.indices.toArray
+
+ // do incremental aggregation if possible
+ val isIncremental = doAllSupportPartialAggregation(
+ namedAggregates.map(_.getKey),
+ inputType,
+ grouping.length)
+
+ val preparedDataSet = if (isTimeWindow) {
+ // time window
+
+ if (isIncremental) {
+ // incremental aggregates
+
+ val groupingKeysAndAlignedRowtime = groupingKeys :+
mapReturnType.getArity - 1
+
+ // create GroupReduceFunction
+ // for pre-tumbling and replicating/omitting the content for each
pane
+ val prepareReduceFunction =
createDataSetSlideWindowPrepareGroupReduceFunction(
+ window,
+ namedAggregates,
+ grouping,
+ inputType,
+ isParserCaseSensitive)
+
+ mappedDataSet.asInstanceOf[DataSet[Row]]
+ .groupBy(groupingKeysAndAlignedRowtime: _*)
+ .reduceGroup(prepareReduceFunction) // pre-tumbles and
replicates/omits
+ .name(prepareOperatorName)
+ } else {
+ // non-incremental aggregates
+
+ // create FlatMapFunction
+ // for replicating/omitting the content for each pane
+ val prepareFlatMapFunction =
createDataSetSlideWindowPrepareFlatMapFunction(
+ window,
+ namedAggregates,
+ grouping,
+ inputType,
+ isParserCaseSensitive)
+
+ mappedDataSet
+ .flatMap(prepareFlatMapFunction) // replicates/omits
+ }
+ } else {
+ // count window
+
+ // grouped window
+ if (groupingKeys.length > 0) {
+
+ if (isIncremental) {
+ // incremental aggregates
+
+ // create GroupReduceFunction
+ // for pre-tumbling and replicating/omitting the content for
each pane
+ val prepareReduceFunction =
createDataSetSlideWindowPrepareGroupReduceFunction(
+ window,
+ namedAggregates,
+ grouping,
+ inputType,
+ isParserCaseSensitive)
+
+ mappedDataSet.asInstanceOf[DataSet[Row]]
+ .groupBy(groupingKeys: _*)
+ // sort on time field, it's the last element in the row
+ .sortGroup(mapReturnType.getArity - 1, Order.ASCENDING)
+ .reduceGroup(prepareReduceFunction) // pre-tumbles and
replicates/omits
--- End diff --
Only do this if the tumble size is > 1?
---
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.
---