gustavodemorais commented on code in PR #29881:
URL: https://github.com/apache/flink/pull/29881#discussion_r4541173816


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java:
##########
@@ -2596,4 +2636,36 @@ public void alterDatabase(
                                         newDatabase,
                                         ignoreIfNotExists)));
     }
+
+    /** Identifies a view definition whose resolution can be reused. */
+    private static final class ViewResolutionKey {
+        private final ObjectIdentifier identifier;
+        private final String expandedQuery;
+        private final Schema unresolvedSchema;
+
+        private ViewResolutionKey(ObjectIdentifier identifier, CatalogView 
view) {
+            this.identifier = identifier;
+            this.expandedQuery = view.getExpandedQuery();
+            this.unresolvedSchema = view.getUnresolvedSchema();

Review Comment:
   `UnresolvedDataType` has no `equals`, so views with string-typed columns 
never hit the cache. That's exactly the persistent-catalog case this PR 
targets. Could we key on `(identifier, expandedQuery)` or the resolved schema 
instead, and add a test with string-typed columns?



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/catalog/NestedViewResolutionTest.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.catalog;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogView;
+import org.apache.flink.table.catalog.GenericInMemoryCatalog;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests resolution of nested views stored unresolved in a catalog, as 
persistent catalogs do.
+ * Resolving such a view parses its query, so the resolution of a view 
referenced from other views
+ * must be reused instead of being repeated for every lookup.
+ */
+class NestedViewResolutionTest {
+
+    private static final int DEPTH = 6;
+
+    private final Map<String, Integer> lookups = new HashMap<>();
+
+    private TableEnvironment tEnv;
+    private GenericInMemoryCatalog catalog;
+
+    @BeforeEach
+    void setUp() {
+        tEnv = TableEnvironment.create(EnvironmentSettings.inStreamingMode());
+        catalog = new LookupCountingCatalog();
+        tEnv.registerCatalog("cat", catalog);
+        tEnv.useCatalog("cat");
+        tEnv.executeSql(
+                "CREATE TABLE t (a INT, ts TIMESTAMP(3), WATERMARK FOR ts AS 
ts)"
+                        + " WITH ('connector' = 'datagen')");
+    }
+
+    @Test

Review Comment:
   Could we add a test that runs two statements, ideally recreating `t` in 
between, and checks the second one resolves everything again? Today nothing 
would catch a leaked cache.



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