slinkydeveloper commented on a change in pull request #18349:
URL: https://github.com/apache/flink/pull/18349#discussion_r785791088



##########
File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/ContextResolvedTable.java
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.catalog;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.util.Preconditions;
+
+import javax.annotation.Nullable;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * This class contains information about a table, its {@link ResolvedSchema}, 
its options and its
+ * relationship with a {@link Catalog}, if any.
+ *
+ * <p>There can be 3 kinds of {@link ContextResolvedTable}:
+ *
+ * <ul>
+ *   <li>A permanent table: a table which is stored in a {@link Catalog} and 
has an associated
+ *       unique {@link ObjectIdentifier}.
+ *   <li>A temporary table: a table which is stored in the {@link 
CatalogManager}, has an associated
+ *       unique {@link ObjectIdentifier} and it's flagged as temporary.
+ *   <li>A anonymous/inline table: a table which is not stored in a catalog 
and doesn't have an
+ *       associated unique {@link ObjectIdentifier}.
+ * </ul>
+ *
+ * <p>The different handling of temporary and permanent tables is {@link 
Catalog} and {@link
+ * CatalogManager} instance specific, hence for these two kind of tables, an 
instance of this object
+ * represents the relationship between the specific {@link 
ResolvedCatalogBaseTable} instance and
+ * the specific {@link Catalog}/{@link CatalogManager} instances. For example, 
the same {@link
+ * ResolvedCatalogBaseTable} can be temporary for one catalog, but permanent 
for another one.
+ */
+@Internal
+public class ContextResolvedTable {
+
+    private final @Nullable ObjectIdentifier objectIdentifier;
+    private final @Nullable Catalog catalog;
+    private final ResolvedCatalogBaseTable<?> resolvedTable;
+
+    public static ContextResolvedTable permanent(
+            ObjectIdentifier identifier,
+            Catalog catalog,
+            ResolvedCatalogBaseTable<?> resolvedTable) {
+        return new ContextResolvedTable(
+                identifier, Preconditions.checkNotNull(catalog), 
resolvedTable);
+    }
+
+    public static ContextResolvedTable temporary(
+            ObjectIdentifier identifier, ResolvedCatalogBaseTable<?> 
resolvedTable) {
+        return new ContextResolvedTable(identifier, null, resolvedTable);
+    }
+
+    public static ContextResolvedTable anonymous(ResolvedCatalogBaseTable<?> 
resolvedTable) {
+        return new ContextResolvedTable(null, null, resolvedTable);
+    }
+
+    private ContextResolvedTable(
+            @Nullable ObjectIdentifier objectIdentifier,
+            @Nullable Catalog catalog,
+            ResolvedCatalogBaseTable<?> resolvedTable) {
+        this.objectIdentifier = objectIdentifier;
+        this.catalog = catalog;
+        this.resolvedTable = resolvedTable;
+    }
+
+    public boolean isAnonymous() {
+        return objectIdentifier == null;
+    }
+
+    /** @return true if the table is temporary. An anonymous table is always 
temporary. */
+    public boolean isTemporary() {
+        return catalog == null;
+    }
+
+    public boolean isPermanent() {
+        return !isTemporary();
+    }
+
+    /** Returns empty if {@link #isAnonymous()} is true. */
+    public Optional<ObjectIdentifier> getIdentifier() {
+        return Optional.ofNullable(objectIdentifier);
+    }
+
+    /** Returns empty if {@link #isPermanent()} is false. */
+    public Optional<Catalog> getCatalog() {
+        return Optional.ofNullable(catalog);
+    }
+
+    /** Returns a fully resolved catalog object. */
+    @SuppressWarnings("unchecked")
+    public <T extends ResolvedCatalogBaseTable<?>> T getResolvedTable() {
+        return (T) resolvedTable;
+    }
+
+    public ResolvedSchema getResolvedSchema() {
+        return resolvedTable.getResolvedSchema();
+    }
+
+    /** Returns the original metadata object returned by the catalog. */
+    @SuppressWarnings("unchecked")
+    public <T extends CatalogBaseTable> T getTable() {
+        return (T) resolvedTable.getOrigin();
+    }
+
+    /**
+     * Copy the {@link ContextResolvedTable}, replacing the underlying {@link 
CatalogTable} options.
+     */
+    public ContextResolvedTable copy(Map<String, String> newOptions) {
+        if (resolvedTable.getTableKind() == CatalogBaseTable.TableKind.VIEW) {
+            throw new TableException("Cannot copy VIEW with new options.");
+        }
+        return new ContextResolvedTable(
+                objectIdentifier, catalog, ((ResolvedCatalogTable) 
resolvedTable).copy(newOptions));
+    }
+
+    @Override
+    public String toString() {

Review comment:
       I kept it for debugging but i'm not relying on it anymore




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