xuyangzhong commented on code in PR #23752:
URL: https://github.com/apache/flink/pull/23752#discussion_r1445559559


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/hints/stream/StateTtlHintTest.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.hints.stream;
+
+import org.apache.flink.table.api.ExplainDetail;
+import org.apache.flink.table.api.TableConfig;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.planner.utils.PlanKind;
+import org.apache.flink.table.planner.utils.StreamTableTestUtil;
+import org.apache.flink.table.planner.utils.TableTestBase;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import scala.Enumeration;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Test for {@link org.apache.flink.table.planner.hint.StateTtlHint}. */
+class StateTtlHintTest extends TableTestBase {
+
+    protected StreamTableTestUtil util;
+
+    @BeforeEach
+    void before() {
+        util = streamTestUtil(TableConfig.getDefault());
+        util.tableEnv()
+                .executeSql(
+                        "CREATE TABLE T1 (\n"
+                                + "  a1 BIGINT,\n"
+                                + "  b1 VARCHAR\n"
+                                + ") WITH (\n"
+                                + " 'connector' = 'values'\n"
+                                + ")");
+        util.tableEnv()
+                .executeSql(
+                        "CREATE TABLE T2 (\n"
+                                + "  a2 BIGINT,\n"
+                                + "  b2 VARCHAR\n"
+                                + ") WITH (\n"
+                                + " 'connector' = 'values'\n"
+                                + ")");
+
+        util.tableEnv()
+                .executeSql(
+                        "CREATE TABLE T3 (\n"
+                                + "  a3 BIGINT,\n"
+                                + "  b3 VARCHAR\n"
+                                + ") WITH (\n"
+                                + " 'connector' = 'values'\n"
+                                + ")");
+
+        util.tableEnv().executeSql("CREATE View V4 as select a3 as a4, b3 as 
b4 from T3");
+
+        util.tableEnv()
+                .executeSql("create view V5 as select T1.* from T1 join T2 on 
T1.a1 = T2.a2");
+    }
+
+    @Test
+    void testSimpleJoinStateTtlHintWithEachSide() {
+        String sql =
+                "select /*+ STATE_TTL('T2' = '2d', 'T1' = '1d') */* from T1 
join T2 on T1.a1 = T2.a2";
+        verify(sql);
+    }
+
+    @Test
+    void testJoinStateTtlHintOnlyWithRightSide() {
+        String sql = "select /*+ STATE_TTL('T2' = '2d') */* from T1 join T2 on 
T1.a1 = T2.a2";
+        verify(sql);
+    }
+
+    @Test
+    void testJoinStateTtlHintWithContinuousJoin() {
+        String sql =
+                "select /*+ STATE_TTL('T2' = '2d', 'T3' = '3d', 'T1' = '1d') 
*/* from T1, T2, T3 where T1.a1 = T2.a2 and T2.b2 = T3.b3";
+        verify(sql);
+    }
+
+    @Test
+    void testJoinStateTtlHintWithMultiLevelJoin() {
+        String sql =
+                "select /*+ STATE_TTL('T2' = '2d', 'T3' = '3d', 'T1' = '1d') 
*/* from T1 "
+                        + "join (select T2.* from T2 join T3 on T2.b2 = T3.b3) 
TMP on T1.a1 = TMP.b2";
+        assertThatThrownBy(() -> verify(sql))
+                .isInstanceOf(ValidationException.class)
+                .hasMessageContaining(
+                        "The options of following hints cannot match the name 
of input tables or views: \n`%s` in `%s`",
+                        "T2, T3", "STATE_TTL");
+    }
+
+    @Test
+    void testJoinStateTtlHintWithOneUnknownTable() {
+        String sql =
+                "select /*+ STATE_TTL('T5' = '2d', 'T1' = '1d') */* from T1 
join T2 on T1.a1 = T2.a2";
+
+        assertThatThrownBy(() -> verify(sql))
+                .isInstanceOf(ValidationException.class)
+                .hasMessageContaining(
+                        "The options of following hints cannot match the name 
of input tables or views: \n`%s` in `%s`",
+                        "T5", "STATE_TTL");
+    }
+
+    @Test
+    void testJoinStateTtlHintWithTwoUnknownTables() {
+        String sql =
+                "select /*+ STATE_TTL('T5' = '2d', 'T6' = '1d') */* from T1 
join T2 on T1.a1 = T2.a2";
+
+        assertThatThrownBy(() -> verify(sql))
+                .isInstanceOf(ValidationException.class)
+                .hasMessageContaining(
+                        "The options of following hints cannot match the name 
of input tables or views: \n`%s` in `%s`",
+                        "T5, T6", "STATE_TTL");
+    }
+
+    @Test
+    void testJoinStateTtlHintWithView() {
+        String sql =
+                "select /*+ STATE_TTL('T1' = '2d', 'V4' = '1d') */* from T1 
join V4 on T1.a1 = V4.a4";
+        verify(sql);
+    }
+
+    @Test
+    void testJoinStateTtlHintWithUnknownView() {
+        String sql =
+                "select /*+ STATE_TTL('T1' = '2d', 'V8' = '1d') */* from T1 
join V4 on T1.a1 = V4.a4";
+        assertThatThrownBy(() -> verify(sql))
+                .isInstanceOf(ValidationException.class)
+                .hasMessageContaining(
+                        "The options of following hints cannot match the name 
of input tables or views: \n`%s` in `%s`",
+                        "V8", "STATE_TTL");
+    }
+
+    @Test
+    void testMultiJoinStateTtlHint() {

Review Comment:
   I agree there will be some correctness issues if the user uses the state ttl 
hint but the actual operator state ttl is different from expected. But query 
hint originally has the semantics of "suggestion", isn't it?
   I think having two different behaviors for join hints and state TTL hints, 
which are both types of query hints, could create some misunderstanding among 
users.
   If we need to explicitly throw an exception in a scenario where state ttl 
hint conflicts, then we also need to explicitly throw an exception in a 
scenario where state ttl hint is used but does not actually take effect. 
Throwing exceptions so frequently will harm users.
   Perhaps what we really need is how to correctly convey the warning 
information that this query hint is not used correctly to the user.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to