PHILO-HE commented on code in PR #10548:
URL:
https://github.com/apache/incubator-gluten/pull/10548#discussion_r2309322581
##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/WindowUtils.java:
##########
@@ -39,6 +39,7 @@ public static Tuple5<Long, Long, Long, Integer, Integer>
extractWindowParameters
int rowtimeIndex = -1;
int windowType = -1;
WindowSpec windowSpec = windowing.getWindow();
+ System.out.println("WindowSpec " + windowSpec);
Review Comment:
ditto.
##########
gluten-flink/planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecGroupWindowAggregate.java:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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.gluten.rexnode.AggregateCallConverter;
+import org.apache.gluten.rexnode.Utils;
+import org.apache.gluten.table.runtime.operators.GlutenVectorOneInputOperator;
+import org.apache.gluten.util.LogicalTypeConverter;
+import org.apache.gluten.util.PlanNodeIdGenerator;
+
+import io.github.zhztheplayer.velox4j.aggregate.Aggregate;
+import io.github.zhztheplayer.velox4j.expression.FieldAccessTypedExpr;
+import io.github.zhztheplayer.velox4j.plan.GroupWindowAggregationNode;
+import io.github.zhztheplayer.velox4j.plan.GroupWindowAggsHandlerNode;
+import io.github.zhztheplayer.velox4j.plan.HashPartitionFunctionSpec;
+import io.github.zhztheplayer.velox4j.plan.PartitionFunctionSpec;
+import io.github.zhztheplayer.velox4j.plan.PlanNode;
+import io.github.zhztheplayer.velox4j.plan.StatefulPlanNode;
+import io.github.zhztheplayer.velox4j.plan.StreamWindowPartitionFunctionSpec;
+
+import org.apache.flink.FlinkVersion;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.api.operators.SimpleOperatorFactory;
+import org.apache.flink.streaming.api.transformations.OneInputTransformation;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.planner.delegation.PlannerBase;
+import org.apache.flink.table.planner.plan.logical.LogicalWindow;
+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.nodes.exec.ExecEdge;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNode;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeMetadata;
+import org.apache.flink.table.planner.plan.nodes.exec.InputProperty;
+import org.apache.flink.table.planner.plan.nodes.exec.utils.ExecNodeUtil;
+import org.apache.flink.table.planner.plan.utils.KeySelectorUtil;
+import org.apache.flink.table.planner.plan.utils.WindowEmitStrategy;
+import org.apache.flink.table.planner.utils.TableConfigUtils;
+import org.apache.flink.table.runtime.groupwindow.NamedWindowProperty;
+import org.apache.flink.table.runtime.keyselector.RowDataKeySelector;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+import org.apache.flink.table.runtime.util.TimeWindowUtil;
+import org.apache.flink.table.types.logical.RowType;
+
+import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.apache.calcite.rel.core.AggregateCall;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.time.ZoneId;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static
org.apache.flink.table.planner.plan.utils.AggregateUtil.hasRowIntervalType;
+import static
org.apache.flink.table.planner.plan.utils.AggregateUtil.isRowtimeAttribute;
+import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Stream {@link ExecNode} for either group window aggregate or group window
table aggregate.
+ *
+ * <p>The differences between {@link StreamExecWindowAggregate} and {@link
+ * StreamExecGroupWindowAggregate} is that, this node is translated from
window TVF syntax, but the
+ * * other is from the legacy GROUP WINDOW FUNCTION syntax. In the long
future, {@link
+ * StreamExecGroupWindowAggregate} will be dropped.
+ */
+@ExecNodeMetadata(
+ name = "stream-exec-group-window-aggregate",
+ version = 1,
+ consumedOptions = {
+ "table.local-time-zone",
+ "table.exec.mini-batch.enabled",
+ "table.exec.mini-batch.size"
+ },
+ producedTransformations =
StreamExecGroupWindowAggregate.GROUP_WINDOW_AGGREGATE_TRANSFORMATION,
+ minPlanVersion = FlinkVersion.v1_15,
+ minStateVersion = FlinkVersion.v1_15)
+public class StreamExecGroupWindowAggregate extends StreamExecAggregateBase {
+
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(StreamExecGroupWindowAggregate.class);
+
+ public static final String GROUP_WINDOW_AGGREGATE_TRANSFORMATION =
"group-window-aggregate";
+
+ public static final String FIELD_NAME_WINDOW = "window";
+ public static final String FIELD_NAME_NAMED_WINDOW_PROPERTIES =
"namedWindowProperties";
+
+ @JsonProperty(FIELD_NAME_GROUPING)
+ private final int[] grouping;
+
+ @JsonProperty(FIELD_NAME_AGG_CALLS)
+ private final AggregateCall[] aggCalls;
+
+ @JsonProperty(FIELD_NAME_WINDOW)
+ private final LogicalWindow window;
+
+ @JsonProperty(FIELD_NAME_NAMED_WINDOW_PROPERTIES)
+ private final NamedWindowProperty[] namedWindowProperties;
+
+ @JsonProperty(FIELD_NAME_NEED_RETRACTION)
+ private final boolean needRetraction;
+
+ public StreamExecGroupWindowAggregate(
+ ReadableConfig tableConfig,
+ int[] grouping,
+ AggregateCall[] aggCalls,
+ LogicalWindow window,
+ NamedWindowProperty[] namedWindowProperties,
+ boolean needRetraction,
+ InputProperty inputProperty,
+ RowType outputType,
+ String description) {
+ this(
+ ExecNodeContext.newNodeId(),
+ ExecNodeContext.newContext(StreamExecGroupWindowAggregate.class),
+
ExecNodeContext.newPersistedConfig(StreamExecGroupWindowAggregate.class,
tableConfig),
+ grouping,
+ aggCalls,
+ window,
+ namedWindowProperties,
+ needRetraction,
+ Collections.singletonList(inputProperty),
+ outputType,
+ description);
+ }
+
+ @JsonCreator
+ public StreamExecGroupWindowAggregate(
+ @JsonProperty(FIELD_NAME_ID) int id,
+ @JsonProperty(FIELD_NAME_TYPE) ExecNodeContext context,
+ @JsonProperty(FIELD_NAME_CONFIGURATION) ReadableConfig persistedConfig,
+ @JsonProperty(FIELD_NAME_GROUPING) int[] grouping,
+ @JsonProperty(FIELD_NAME_AGG_CALLS) AggregateCall[] aggCalls,
+ @JsonProperty(FIELD_NAME_WINDOW) LogicalWindow window,
+ @JsonProperty(FIELD_NAME_NAMED_WINDOW_PROPERTIES) NamedWindowProperty[]
namedWindowProperties,
+ @JsonProperty(FIELD_NAME_NEED_RETRACTION) boolean needRetraction,
+ @JsonProperty(FIELD_NAME_INPUT_PROPERTIES) List<InputProperty>
inputProperties,
+ @JsonProperty(FIELD_NAME_OUTPUT_TYPE) RowType outputType,
+ @JsonProperty(FIELD_NAME_DESCRIPTION) String description) {
+ super(id, context, persistedConfig, inputProperties, outputType,
description);
+ checkArgument(inputProperties.size() == 1);
+ this.grouping = checkNotNull(grouping);
+ this.aggCalls = checkNotNull(aggCalls);
+ this.window = checkNotNull(window);
+ this.namedWindowProperties = checkNotNull(namedWindowProperties);
+ this.needRetraction = needRetraction;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Transformation<RowData> translateToPlanInternal(
+ PlannerBase planner, ExecNodeConfig config) {
+ final boolean isCountWindow;
+ System.out.println("Window: " + window);
+ System.out.println("WindowOutput: " + getOutputType());
+ // System.out.println("WindowSpec: " + window.getWindow());
Review Comment:
Please remove the three lines of debug code above or use `logger.debug`
instead.
##########
gluten-flink/planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecWindowAggregate.java:
##########
@@ -0,0 +1,333 @@
+/*
+ * 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.gluten.rexnode.AggregateCallConverter;
+import org.apache.gluten.rexnode.Utils;
+import org.apache.gluten.rexnode.WindowUtils;
+import org.apache.gluten.table.runtime.operators.GlutenVectorOneInputOperator;
+import org.apache.gluten.util.LogicalTypeConverter;
+import org.apache.gluten.util.PlanNodeIdGenerator;
+
+import io.github.zhztheplayer.velox4j.aggregate.Aggregate;
+import io.github.zhztheplayer.velox4j.aggregate.AggregateStep;
+import io.github.zhztheplayer.velox4j.expression.FieldAccessTypedExpr;
+import io.github.zhztheplayer.velox4j.plan.AggregationNode;
+import io.github.zhztheplayer.velox4j.plan.EmptyNode;
+import io.github.zhztheplayer.velox4j.plan.HashPartitionFunctionSpec;
+import io.github.zhztheplayer.velox4j.plan.PartitionFunctionSpec;
+import io.github.zhztheplayer.velox4j.plan.PlanNode;
+import io.github.zhztheplayer.velox4j.plan.StatefulPlanNode;
+import io.github.zhztheplayer.velox4j.plan.StreamWindowAggregationNode;
+import io.github.zhztheplayer.velox4j.plan.StreamWindowPartitionFunctionSpec;
+
+import org.apache.flink.FlinkVersion;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.tuple.Tuple5;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.api.operators.SimpleOperatorFactory;
+import org.apache.flink.streaming.api.transformations.OneInputTransformation;
+import org.apache.flink.table.data.RowData;
+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.logical.WindowingStrategy;
+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.ExecNodeConfig;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeMetadata;
+import org.apache.flink.table.planner.plan.nodes.exec.InputProperty;
+import org.apache.flink.table.planner.plan.nodes.exec.utils.ExecNodeUtil;
+import org.apache.flink.table.planner.plan.utils.AggregateInfoList;
+import org.apache.flink.table.planner.plan.utils.KeySelectorUtil;
+import org.apache.flink.table.planner.utils.JavaScalaConversionUtil;
+import org.apache.flink.table.planner.utils.TableConfigUtils;
+import
org.apache.flink.table.runtime.generated.GeneratedNamespaceAggsHandleFunction;
+import org.apache.flink.table.runtime.groupwindow.NamedWindowProperty;
+import org.apache.flink.table.runtime.groupwindow.WindowProperty;
+import org.apache.flink.table.runtime.keyselector.RowDataKeySelector;
+import org.apache.flink.table.runtime.operators.window.TimeWindow;
+import
org.apache.flink.table.runtime.operators.window.tvf.common.WindowAssigner;
+import
org.apache.flink.table.runtime.operators.window.tvf.slicing.SliceSharedAssigner;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+import org.apache.flink.table.runtime.util.TimeWindowUtil;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.RowType;
+
+import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.commons.math3.util.ArithmeticUtils;
+
+import javax.annotation.Nullable;
+
+import java.time.ZoneId;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.TimeZone;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Stream {@link ExecNode} for window table-valued based aggregate.
+ *
+ * <p>The differences between {@link StreamExecWindowAggregate} and {@link
+ * StreamExecGroupWindowAggregate} is that, this node is translated from
window TVF syntax, but the
+ * other is from the legacy GROUP WINDOW FUNCTION syntax. In the long future,
{@link
+ * StreamExecGroupWindowAggregate} will be dropped.
+ */
+@ExecNodeMetadata(
+ name = "stream-exec-window-aggregate",
+ version = 1,
+ consumedOptions = "table.local-time-zone",
+ producedTransformations =
StreamExecWindowAggregate.WINDOW_AGGREGATE_TRANSFORMATION,
+ minPlanVersion = FlinkVersion.v1_15,
+ minStateVersion = FlinkVersion.v1_15)
+public class StreamExecWindowAggregate extends StreamExecWindowAggregateBase {
+
+ public static final String WINDOW_AGGREGATE_TRANSFORMATION =
"window-aggregate";
+
+ private static final long WINDOW_AGG_MEMORY_RATIO = 100;
+
+ public static final String FIELD_NAME_WINDOWING = "windowing";
+ public static final String FIELD_NAME_NAMED_WINDOW_PROPERTIES =
"namedWindowProperties";
+
+ @JsonProperty(FIELD_NAME_GROUPING)
+ private final int[] grouping;
+
+ @JsonProperty(FIELD_NAME_AGG_CALLS)
+ private final AggregateCall[] aggCalls;
+
+ @JsonProperty(FIELD_NAME_WINDOWING)
+ private final WindowingStrategy windowing;
+
+ @JsonProperty(FIELD_NAME_NAMED_WINDOW_PROPERTIES)
+ private final NamedWindowProperty[] namedWindowProperties;
+
+ @JsonProperty(FIELD_NAME_NEED_RETRACTION)
+ private final boolean needRetraction;
+
+ public StreamExecWindowAggregate(
+ ReadableConfig tableConfig,
+ int[] grouping,
+ AggregateCall[] aggCalls,
+ WindowingStrategy windowing,
+ NamedWindowProperty[] namedWindowProperties,
+ Boolean needRetraction,
+ InputProperty inputProperty,
+ RowType outputType,
+ String description) {
+ this(
+ ExecNodeContext.newNodeId(),
+ ExecNodeContext.newContext(StreamExecWindowAggregate.class),
+ ExecNodeContext.newPersistedConfig(StreamExecWindowAggregate.class,
tableConfig),
+ grouping,
+ aggCalls,
+ windowing,
+ namedWindowProperties,
+ needRetraction,
+ Collections.singletonList(inputProperty),
+ outputType,
+ description);
+ }
+
+ @JsonCreator
+ public StreamExecWindowAggregate(
+ @JsonProperty(FIELD_NAME_ID) int id,
+ @JsonProperty(FIELD_NAME_TYPE) ExecNodeContext context,
+ @JsonProperty(FIELD_NAME_CONFIGURATION) ReadableConfig persistedConfig,
+ @JsonProperty(FIELD_NAME_GROUPING) int[] grouping,
+ @JsonProperty(FIELD_NAME_AGG_CALLS) AggregateCall[] aggCalls,
+ @JsonProperty(FIELD_NAME_WINDOWING) WindowingStrategy windowing,
+ @JsonProperty(FIELD_NAME_NAMED_WINDOW_PROPERTIES) NamedWindowProperty[]
namedWindowProperties,
+ @Nullable @JsonProperty(FIELD_NAME_NEED_RETRACTION) Boolean
needRetraction,
+ @JsonProperty(FIELD_NAME_INPUT_PROPERTIES) List<InputProperty>
inputProperties,
+ @JsonProperty(FIELD_NAME_OUTPUT_TYPE) RowType outputType,
+ @JsonProperty(FIELD_NAME_DESCRIPTION) String description) {
+ super(id, context, persistedConfig, inputProperties, outputType,
description);
+ this.grouping = checkNotNull(grouping);
+ this.aggCalls = checkNotNull(aggCalls);
+ this.windowing = checkNotNull(windowing);
+ this.namedWindowProperties = checkNotNull(namedWindowProperties);
+ this.needRetraction = Optional.ofNullable(needRetraction).orElse(false);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Transformation<RowData> translateToPlanInternal(
+ PlannerBase planner, ExecNodeConfig config) {
+ final ExecEdge inputEdge = getInputEdges().get(0);
+ final Transformation<RowData> inputTransform =
+ (Transformation<RowData>) inputEdge.translateToPlan(planner);
+ final RowType inputRowType = (RowType) inputEdge.getOutputType();
+
+ final ZoneId shiftTimeZone =
+ TimeWindowUtil.getShiftTimeZone(
+ windowing.getTimeAttributeType(),
TableConfigUtils.getLocalTimeZone(config));
+ final WindowAssigner windowAssigner = createWindowAssigner(windowing,
shiftTimeZone);
Review Comment:
`shiftTimeZone` and `windowAssigner` are not used after the modification.
Maybe, we can remove it.
##########
gluten-flink/planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecGroupWindowAggregate.java:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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.gluten.rexnode.AggregateCallConverter;
+import org.apache.gluten.rexnode.Utils;
+import org.apache.gluten.table.runtime.operators.GlutenVectorOneInputOperator;
+import org.apache.gluten.util.LogicalTypeConverter;
+import org.apache.gluten.util.PlanNodeIdGenerator;
+
+import io.github.zhztheplayer.velox4j.aggregate.Aggregate;
+import io.github.zhztheplayer.velox4j.expression.FieldAccessTypedExpr;
+import io.github.zhztheplayer.velox4j.plan.GroupWindowAggregationNode;
+import io.github.zhztheplayer.velox4j.plan.GroupWindowAggsHandlerNode;
+import io.github.zhztheplayer.velox4j.plan.HashPartitionFunctionSpec;
+import io.github.zhztheplayer.velox4j.plan.PartitionFunctionSpec;
+import io.github.zhztheplayer.velox4j.plan.PlanNode;
+import io.github.zhztheplayer.velox4j.plan.StatefulPlanNode;
+import io.github.zhztheplayer.velox4j.plan.StreamWindowPartitionFunctionSpec;
+
+import org.apache.flink.FlinkVersion;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.api.operators.SimpleOperatorFactory;
+import org.apache.flink.streaming.api.transformations.OneInputTransformation;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.planner.delegation.PlannerBase;
+import org.apache.flink.table.planner.plan.logical.LogicalWindow;
+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.nodes.exec.ExecEdge;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNode;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeMetadata;
+import org.apache.flink.table.planner.plan.nodes.exec.InputProperty;
+import org.apache.flink.table.planner.plan.nodes.exec.utils.ExecNodeUtil;
+import org.apache.flink.table.planner.plan.utils.KeySelectorUtil;
+import org.apache.flink.table.planner.plan.utils.WindowEmitStrategy;
+import org.apache.flink.table.planner.utils.TableConfigUtils;
+import org.apache.flink.table.runtime.groupwindow.NamedWindowProperty;
+import org.apache.flink.table.runtime.keyselector.RowDataKeySelector;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+import org.apache.flink.table.runtime.util.TimeWindowUtil;
+import org.apache.flink.table.types.logical.RowType;
+
+import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.apache.calcite.rel.core.AggregateCall;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.time.ZoneId;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static
org.apache.flink.table.planner.plan.utils.AggregateUtil.hasRowIntervalType;
+import static
org.apache.flink.table.planner.plan.utils.AggregateUtil.isRowtimeAttribute;
+import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Stream {@link ExecNode} for either group window aggregate or group window
table aggregate.
+ *
+ * <p>The differences between {@link StreamExecWindowAggregate} and {@link
+ * StreamExecGroupWindowAggregate} is that, this node is translated from
window TVF syntax, but the
+ * * other is from the legacy GROUP WINDOW FUNCTION syntax. In the long
future, {@link
+ * StreamExecGroupWindowAggregate} will be dropped.
+ */
+@ExecNodeMetadata(
+ name = "stream-exec-group-window-aggregate",
+ version = 1,
+ consumedOptions = {
+ "table.local-time-zone",
+ "table.exec.mini-batch.enabled",
+ "table.exec.mini-batch.size"
+ },
+ producedTransformations =
StreamExecGroupWindowAggregate.GROUP_WINDOW_AGGREGATE_TRANSFORMATION,
+ minPlanVersion = FlinkVersion.v1_15,
+ minStateVersion = FlinkVersion.v1_15)
+public class StreamExecGroupWindowAggregate extends StreamExecAggregateBase {
+
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(StreamExecGroupWindowAggregate.class);
+
+ public static final String GROUP_WINDOW_AGGREGATE_TRANSFORMATION =
"group-window-aggregate";
+
+ public static final String FIELD_NAME_WINDOW = "window";
+ public static final String FIELD_NAME_NAMED_WINDOW_PROPERTIES =
"namedWindowProperties";
+
+ @JsonProperty(FIELD_NAME_GROUPING)
+ private final int[] grouping;
+
+ @JsonProperty(FIELD_NAME_AGG_CALLS)
+ private final AggregateCall[] aggCalls;
+
+ @JsonProperty(FIELD_NAME_WINDOW)
+ private final LogicalWindow window;
+
+ @JsonProperty(FIELD_NAME_NAMED_WINDOW_PROPERTIES)
+ private final NamedWindowProperty[] namedWindowProperties;
+
+ @JsonProperty(FIELD_NAME_NEED_RETRACTION)
+ private final boolean needRetraction;
+
+ public StreamExecGroupWindowAggregate(
+ ReadableConfig tableConfig,
+ int[] grouping,
+ AggregateCall[] aggCalls,
+ LogicalWindow window,
+ NamedWindowProperty[] namedWindowProperties,
+ boolean needRetraction,
+ InputProperty inputProperty,
+ RowType outputType,
+ String description) {
+ this(
+ ExecNodeContext.newNodeId(),
+ ExecNodeContext.newContext(StreamExecGroupWindowAggregate.class),
+
ExecNodeContext.newPersistedConfig(StreamExecGroupWindowAggregate.class,
tableConfig),
+ grouping,
+ aggCalls,
+ window,
+ namedWindowProperties,
+ needRetraction,
+ Collections.singletonList(inputProperty),
+ outputType,
+ description);
+ }
+
+ @JsonCreator
+ public StreamExecGroupWindowAggregate(
+ @JsonProperty(FIELD_NAME_ID) int id,
+ @JsonProperty(FIELD_NAME_TYPE) ExecNodeContext context,
+ @JsonProperty(FIELD_NAME_CONFIGURATION) ReadableConfig persistedConfig,
+ @JsonProperty(FIELD_NAME_GROUPING) int[] grouping,
+ @JsonProperty(FIELD_NAME_AGG_CALLS) AggregateCall[] aggCalls,
+ @JsonProperty(FIELD_NAME_WINDOW) LogicalWindow window,
+ @JsonProperty(FIELD_NAME_NAMED_WINDOW_PROPERTIES) NamedWindowProperty[]
namedWindowProperties,
+ @JsonProperty(FIELD_NAME_NEED_RETRACTION) boolean needRetraction,
+ @JsonProperty(FIELD_NAME_INPUT_PROPERTIES) List<InputProperty>
inputProperties,
+ @JsonProperty(FIELD_NAME_OUTPUT_TYPE) RowType outputType,
+ @JsonProperty(FIELD_NAME_DESCRIPTION) String description) {
+ super(id, context, persistedConfig, inputProperties, outputType,
description);
+ checkArgument(inputProperties.size() == 1);
+ this.grouping = checkNotNull(grouping);
+ this.aggCalls = checkNotNull(aggCalls);
+ this.window = checkNotNull(window);
+ this.namedWindowProperties = checkNotNull(namedWindowProperties);
+ this.needRetraction = needRetraction;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Transformation<RowData> translateToPlanInternal(
+ PlannerBase planner, ExecNodeConfig config) {
+ final boolean isCountWindow;
+ System.out.println("Window: " + window);
+ System.out.println("WindowOutput: " + getOutputType());
+ // System.out.println("WindowSpec: " + window.getWindow());
+ if (window instanceof TumblingGroupWindow) {
+ isCountWindow = hasRowIntervalType(((TumblingGroupWindow)
window).size());
+ } else if (window instanceof SlidingGroupWindow) {
+ isCountWindow = hasRowIntervalType(((SlidingGroupWindow) window).size());
+ } else {
+ isCountWindow = false;
+ }
+
+ if (isCountWindow && grouping.length > 0 && config.getStateRetentionTime()
< 0) {
+ LOGGER.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 ExecEdge inputEdge = getInputEdges().get(0);
+ final Transformation<RowData> inputTransform =
+ (Transformation<RowData>) inputEdge.translateToPlan(planner);
+ final RowType inputRowType = (RowType) inputEdge.getOutputType();
+
+ final int inputTimeFieldIndex;
+ if (isRowtimeAttribute(window.timeAttribute())) {
+ inputTimeFieldIndex = window.timeAttribute().getFieldIndex();
+ if (inputTimeFieldIndex < 0) {
+ throw new TableException(
+ "Group window must defined on a time attribute, "
+ + "but the time attribute can't be found.\n"
+ + "This should never happen. Please file an issue.");
+ }
+ } else {
+ inputTimeFieldIndex = -1;
+ }
+
+ final ZoneId shiftTimeZone =
+ TimeWindowUtil.getShiftTimeZone(
+ window.timeAttribute().getOutputDataType().getLogicalType(),
+ TableConfigUtils.getLocalTimeZone(config));
Review Comment:
`shiftTimeZone` is not actually used. Do we still need it? If not, please
remove it.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]