LadyForest commented on code in PR #22593:
URL: https://github.com/apache/flink/pull/22593#discussion_r1215371248


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/runtime/stream/jsonplan/ConfigureOperatorLevelStateTtlJsonITCase.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.jsonplan;
+
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.planner.factories.TestValuesTableFactory;
+import org.apache.flink.table.planner.utils.JsonPlanTestBase;
+import org.apache.flink.table.planner.utils.JsonTestUtils;
+
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Tests for configuring operator-level state TTL via {@link
+ * org.apache.flink.table.api.CompiledPlan}.
+ */
+public class ConfigureOperatorLevelStateTtlJsonITCase extends JsonPlanTestBase 
{
+
+    @Test
+    public void testDifferentStateTtlForDifferentOneInputOperator() throws 
Exception {
+        String dataId =
+                TestValuesTableFactory.registerRowData(
+                        Arrays.asList(
+                                GenericRowData.of(1, 
StringData.fromString("Tom"), 1, 199.9d),
+                                GenericRowData.of(2, 
StringData.fromString("Jerry"), 2, 99.9d),
+                                GenericRowData.of(1, 
StringData.fromString("Tom"), 1, 199.9d),
+                                GenericRowData.of(3, 
StringData.fromString("Tom"), 1, 29.9d),
+                                GenericRowData.of(4, 
StringData.fromString("Olivia"), 1, 100d),
+                                GenericRowData.of(4, 
StringData.fromString("Olivia"), 1, 100d),
+                                GenericRowData.of(2, 
StringData.fromString("Jerry"), 2, 99.9d),
+                                GenericRowData.of(5, 
StringData.fromString("Michael"), 3, 599.9d),
+                                GenericRowData.of(6, 
StringData.fromString("Olivia"), 3, 1000d)));
+        createTestSourceTable(
+                "Orders",
+                new String[] {
+                    "`order_id` INT", "`buyer` STRING", "`quantity` INT", 
"`amount` DOUBLE"
+                },
+                null,
+                getProperties(dataId, 1, "2s"));
+
+        createTestNonInsertOnlyValuesSinkTable(
+                "OrdersStats",
+                "`buyer` STRING",
+                "`ord_cnt` BIGINT",
+                "`quantity_cnt` BIGINT",
+                "`total_amount` DOUBLE");
+        compileSqlAndExecutePlan(
+                        "INSERT INTO OrdersStats \n"
+                                + "SELECT buyer, COUNT(1) AS ord_cnt, 
SUM(quantity) AS quantity_cnt, SUM(amount) AS total_amount FROM (\n"
+                                + "SELECT *, ROW_NUMBER() OVER(PARTITION BY 
order_id, buyer, quantity, amount ORDER BY proctime() ASC) AS rk FROM Orders) 
tmp\n"
+                                + "WHERE rk = 1\n"
+                                + "GROUP BY buyer",
+                        json -> {
+                            try {
+                                JsonNode target = 
JsonTestUtils.readFromString(json);
+                                JsonTestUtils.setExecNodeStateMetadata(
+                                        target, "stream-exec-deduplicate", 0, 
6000L);
+                                JsonTestUtils.setExecNodeStateMetadata(

Review Comment:
   Commenting out this line means that the TTL of the deduplication node will 
take the default value of 0, which means that the status will never expire. 
However, the actual effect is the same as setting a TTL of 6 or 8 seconds.
   
   I think this case demonstrates the significance of supporting operator-level 
TTL configuration. That is to say, as long as we ensure that the data 
calculation results remain unchanged, we do not need to unnecessarily extend 
the state TTL for the sake of a long-period state of a certain operator.
   
   Let me add more description to the case.



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

Reply via email to