ggjh-159 commented on code in PR #13730:
URL: https://github.com/apache/gluten/pull/13730#discussion_r4691963205


##########
gluten-flink/planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecGroupWindowAggregate.java:
##########
@@ -178,69 +186,124 @@ protected Transformation<RowData> 
translateToPlanInternal(
     } 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.");
+    checkArgument(
+        !isCountWindow,
+        "VELOX_UNSUPPORTED: group window aggregation does not support 
row-count windows "
+            + "(CountTumbling/CountSliding are out of scope)");
+    checkArgument(
+        !config.get(
+            ConfigOptions.key("table.exec.emit.early-fire.enabled")
+                .booleanType()
+                .defaultValue(false)),
+        "VELOX_UNSUPPORTED: group window aggregation does not support the 
early-fire EMIT "
+            + "strategy (table.exec.emit.early-fire.enabled)");
+    checkArgument(
+        config
+                .getOptional(
+                    ConfigOptions.key("table.exec.emit.early-fire.delay")
+                        .durationType()
+                        .noDefaultValue())
+                .orElse(Duration.ZERO)
+                .toMillis()
+            <= 0,
+        "VELOX_UNSUPPORTED: group window aggregation does not support the 
early-fire EMIT "
+            + "strategy (table.exec.emit.early-fire.delay)");
+    checkArgument(
+        !config.get(
+            ConfigOptions.key("table.exec.emit.late-fire.enabled")
+                .booleanType()
+                .defaultValue(false)),
+        "VELOX_UNSUPPORTED: group window aggregation does not support the 
late-fire EMIT "
+            + "strategy (table.exec.emit.late-fire.enabled)");
+    checkArgument(
+        config
+                .getOptional(
+                    ConfigOptions.key("table.exec.emit.allow-lateness")
+                        .durationType()
+                        .noDefaultValue())
+                .orElse(Duration.ZERO)
+                .toMillis()
+            <= 0,
+        "VELOX_UNSUPPORTED: group window aggregation does not support non-zero 
allowed "
+            + "lateness (table.exec.emit.allow-lateness)");
+    checkArgument(
+        isRowtimeAttribute(window.timeAttribute()),
+        "VELOX_UNSUPPORTED: group window aggregation requires a rowtime time 
attribute "
+            + "(processing-time windows are out of scope)");
+    if (!(window instanceof SessionGroupWindow
+        || window instanceof TumblingGroupWindow
+        || window instanceof SlidingGroupWindow)) {
+      throw new TableException(
+          "VELOX_UNSUPPORTED: group window aggregation supports SESSION / 
TUMBLE / "
+              + "HOP windows only, window was: "
+              + window.toString());
     }
+    // --- End of fail-loud faces ---
 
     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 org.apache.flink.table.types.logical.RowType inputRowType =
+        (org.apache.flink.table.types.logical.RowType) 
inputEdge.getOutputType();
+
+    final int inputTimeFieldIndex = window.timeAttribute().getFieldIndex();
+    checkArgument(
+        inputTimeFieldIndex >= 0,
+        "Group window must be defined on a time attribute, but the time 
attribute can't be "
+            + "found.\nThis should never happen. Please file an issue.");
 
     WindowEmitStrategy emitStrategy = WindowEmitStrategy.apply(config, window);
 
-    // --- Begin Gluten-specific code changes ---
-    // TODO: velox window not equal to flink window.
     io.github.zhztheplayer.velox4j.type.RowType inputType =
         (io.github.zhztheplayer.velox4j.type.RowType) 
LogicalTypeConverter.toVLType(inputRowType);
     io.github.zhztheplayer.velox4j.type.RowType outputType =
         (io.github.zhztheplayer.velox4j.type.RowType)
             LogicalTypeConverter.toVLType(getOutputType());
-    List<FieldAccessTypedExpr> groupingKeys = 
Utils.generateFieldAccesses(inputType, grouping);
     List<Aggregate> aggregates = AggregateCallConverter.toAggregates(aggCalls, 
inputType);

Review Comment:
   AggregateCallConverter.toAggregate always passes a null mask, so the FILTER 
clause of an aggregate call is dropped before it reaches the plan: a legacy 
group window query with COUNT(x) FILTER (WHERE ...) passes every 
translation-time guard and then aggregates every row silently, whereas Flink's 
group window aggregation honors the filter (AggsHandlerCodeGenerator builds a 
filter expression from the call's filterArg for every aggregate). Please 
support the filter: pass the call's filterArg through as the Aggregate mask (a 
BOOLEAN input column, which is what velox's Aggregate::mask takes) and apply it 
in the accumulate path the way HashAggregation does - run AggregationMasks over 
the input rows and hand each aggregate its activeRows selectivity vector 
instead of the full rows when calling addSingleGroupRawInput - and add a SQL 
test with a filtered aggregate; until that lands, reject aggregate calls with a 
FILTER at translation time with VELOX_UNSUPPORTED rather than aggregating all r
 ows.



##########
gluten-flink/planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecGroupWindowAggregate.java:
##########
@@ -178,69 +186,124 @@ protected Transformation<RowData> 
translateToPlanInternal(
     } 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.");
+    checkArgument(
+        !isCountWindow,
+        "VELOX_UNSUPPORTED: group window aggregation does not support 
row-count windows "
+            + "(CountTumbling/CountSliding are out of scope)");
+    checkArgument(
+        !config.get(
+            ConfigOptions.key("table.exec.emit.early-fire.enabled")
+                .booleanType()
+                .defaultValue(false)),
+        "VELOX_UNSUPPORTED: group window aggregation does not support the 
early-fire EMIT "
+            + "strategy (table.exec.emit.early-fire.enabled)");
+    checkArgument(
+        config
+                .getOptional(
+                    ConfigOptions.key("table.exec.emit.early-fire.delay")
+                        .durationType()
+                        .noDefaultValue())
+                .orElse(Duration.ZERO)
+                .toMillis()
+            <= 0,
+        "VELOX_UNSUPPORTED: group window aggregation does not support the 
early-fire EMIT "
+            + "strategy (table.exec.emit.early-fire.delay)");
+    checkArgument(
+        !config.get(
+            ConfigOptions.key("table.exec.emit.late-fire.enabled")
+                .booleanType()
+                .defaultValue(false)),
+        "VELOX_UNSUPPORTED: group window aggregation does not support the 
late-fire EMIT "
+            + "strategy (table.exec.emit.late-fire.enabled)");
+    checkArgument(
+        config
+                .getOptional(
+                    ConfigOptions.key("table.exec.emit.allow-lateness")
+                        .durationType()
+                        .noDefaultValue())
+                .orElse(Duration.ZERO)
+                .toMillis()
+            <= 0,
+        "VELOX_UNSUPPORTED: group window aggregation does not support non-zero 
allowed "
+            + "lateness (table.exec.emit.allow-lateness)");
+    checkArgument(
+        isRowtimeAttribute(window.timeAttribute()),

Review Comment:
   The rowtime guard accepts every rowtime attribute, including TIMESTAMP_LTZ, 
but the window operator it translates to aligns windows and renders the time 
attributes on the UTC wall clock without the session-time-zone shift Flink 
applies to TIMESTAMP_LTZ attributes (TimeWindowUtil.getShiftTimeZone), so an 
LTZ query under a non-UTC table.local-time-zone produces different window 
boundaries and window_start / window_end / rowtime values than Flink. Please 
reject a TIMESTAMP_LTZ time attribute at translation time with the same 
VELOX_UNSUPPORTED message until the operator applies the shift time zone, and 
add the case to the fail-loud tests.



##########
gluten-flink/ut/src/test/java/org/apache/gluten/planner/StreamExecGroupWindowAggregateWindowAggTest.java:
##########
@@ -0,0 +1,280 @@
+/*
+ * 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.gluten.planner;
+
+import org.apache.gluten.table.runtime.operators.GlutenWindowOneInputOperator;
+
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.transformations.OneInputTransformation;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.Tumble;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.table.planner.factories.TestValuesTableFactory;
+import 
org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecGroupWindowAggregate;
+import org.apache.flink.types.Row;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.table.api.Expressions.$;
+import static org.apache.flink.table.api.Expressions.lit;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
+
+/**
+ * Planner-level tests for the gluten override of {@link 
StreamExecGroupWindowAggregate}: the
+ * translated transformation stays non-keyed (the user key belongs to the 
velox keyed state backend
+ * and the upstream exchange, so no Flink state key selector may be declared - 
the q11 regression
+ * line), the operator is the {@link GlutenWindowOneInputOperator} subclass, 
and the fail-loud faces
+ * of the P0 scope: row-count windows, non-default EMIT strategies, 
processing-time attributes, and
+ * the TUMBLE / HOP windows phased into the next stage.
+ */
+public class StreamExecGroupWindowAggregateWindowAggTest {
+
+  @Test
+  public void sessionWindowTransformationStaysNonKeyed() {

Review Comment:
   The repository carries no SQL-level test for legacy group window 
aggregation: the translation test only inspects the transformation and the 
fail-loud guards, and the runtime test covers the RocksDB rejection and the 
clone, so window boundaries, late-row dropping, empty-window suppression, 
SESSION merging, HOP overlap and the emitted time attributes are executed by no 
test in the repository. Please add GlutenStreamingTestBase-style SQL tests for 
a TUMBLE (aligned boundaries, watermark-driven firing), a HOP (one row landing 
in both covering windows, each firing on its own), a SESSION (adjacent windows 
merging, disjoint windows firing independently), late-row dropping, and the 
output values including window_start / window_end / rowtime with COUNT(*) and 
SUM.



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

Reply via email to