AHeise commented on code in PR #29881:
URL: https://github.com/apache/flink/pull/29881#discussion_r4543008692
##########
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:
Good catch, the key never matched for schemas restored from type strings,
which is exactly the persistent-catalog case. It's now keyed on `(identifier,
expandedQuery)`, and the test declares its view columns as type strings
(`column("a", "INT")`), so the depth test covers it.
##########
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:
The cache lives on `CatalogManager`, not on the catalog, and only for one
outermost `resolveCatalogView` call: it's created on entry and dropped in
`finally`. So a catalog instance reused across queries, or even across
environments, never sees earlier resolutions. Only concurrent statements on one
`CatalogManager` could overlap, and that's not supported (the gateway
serializes operations per session). Added
`testEveryStatementResolvesViewsAgain`, which runs two queries against the same
catalog, recreates `t` in between, and checks the second query looks up
everything again and plans against the new `t`.
--
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]