MartijnVisser commented on code in PR #29410:
URL: https://github.com/apache/flink/pull/29410#discussion_r4205091194
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/over/AbstractNonTimeUnboundedPrecedingOver.java:
##########
@@ -195,6 +199,10 @@ public void open(OpenContext openContext) throws Exception
{
sortKeyEqualiser =
generatedSortKeyEqualiser.newInstance(getRuntimeContext().getUserCodeClassLoader());
+ // Initialize accumulator equaliser
+ accEqualiser =
+
generatedAccEqualiser.newInstance(getRuntimeContext().getUserCodeClassLoader());
Review Comment:
I think the copy belongs here: copy on `accMapState` get and put, for every
accumulator. With that, LAG, ARRAY_AGG, BITMAP_BUILD_AGG and array or byte[]
UDAFs are correct on heap.
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecOverAggregate.java:
##########
@@ -407,6 +407,12 @@ private KeyedProcessFunction<RowData, RowData, RowData>
createUnboundedOverProce
new EqualiserCodeGenerator(sortKeyRowType,
ctx.classLoader())
.generateRecordEqualiser("FirstMatchingSortKeyEqualiser");
+ // RowData#equals throws on a RAW accumulator field and never
matches a
+ // BinaryRowData read back from state, so the comparison has
to be generated.
+ final GeneratedRecordEqualiser generatedAccEqualiser =
Review Comment:
State backed views compare equal here, so without FLINK-40737 heap COLLECT
and COUNT(DISTINCT) go from an exception to wrong results. I'd like this to
land together with that PR.
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/runtime/stream/sql/NonTimeOverAggregateITCase.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.runtime.stream.sql;
+
+import org.apache.flink.table.planner.factories.TestValuesTableFactory;
+import org.apache.flink.table.planner.runtime.utils.StreamingWithStateTestBase;
+import
org.apache.flink.testutils.junit.extensions.parameterized.ParameterizedTestExtension;
+import org.apache.flink.testutils.junit.extensions.parameterized.Parameters;
+import org.apache.flink.types.Row;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.CloseableIterator;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.TreeMap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
+
+/** Tests for OVER windows ordered by a non-time attribute. */
+@ExtendWith(ParameterizedTestExtension.class)
+public class NonTimeOverAggregateITCase extends StreamingWithStateTestBase {
+
+ public NonTimeOverAggregateITCase(StateBackendMode state) {
+ super(state);
+ }
+
+ @Parameters(name = "backend = {0}")
+ public static Collection<Object[]> parameters() {
+ return Arrays.asList(
+ new Object[][] {
+ {StreamingWithStateTestBase.HEAP_BACKEND()},
+ {StreamingWithStateTestBase.ROCKSDB_BACKEND()}
+ });
+ }
+
+ @BeforeEach
+ public void before() {
+ super.before();
+ String dataId =
+ TestValuesTableFactory.registerData(
+ Arrays.asList(
+ Row.of("a", 30, "p"), Row.of("a", 20, "q"),
Row.of("a", 10, "r")));
Review Comment:
These rows only insert at the front and UPDATE_BEFORE values are skipped
below, so this doesn't show. Can you add a row that lands in between and check
the retractions?
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/over/NonTimeRangeUnboundedPrecedingFunction.java:
##########
@@ -287,7 +289,7 @@ void processRemainingElements(
// Get previous accumulator
RowData prevAcc = accMapState.get(curSortKey);
- if (prevAcc.equals(currAcc)) {
+ if (accEqualiser.equals(prevAcc, currAcc)) {
Review Comment:
On heap, `accMapState.get` returns the stored accumulator and LAG and
ARRAY_AGG append to it in place. Rows 30, 20, 25 give ARRAY_AGG `[q, p, s]` for
25.
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/over/NonTimeRowsUnboundedPrecedingFunction.java:
##########
@@ -99,6 +100,7 @@ public NonTimeRowsUnboundedPrecedingFunction(
genAggsHandler,
genRecordEqualiser,
genSortKeyEqualiser,
+ genAccEqualiser,
Review Comment:
This can't land in either order with FLINK-40883: its tests use the old
constructor and its LAST_VALUE tests fail on `TestAccEqualiser`. The second one
to land also moves its comparisons to `accEqualiser`.
--
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]