AHeise commented on code in PR #29929:
URL: https://github.com/apache/flink/pull/29929#discussion_r4598004619


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java:
##########
@@ -886,6 +887,29 @@ public boolean dropTemporaryModel(String path) {
         }
     }
 
+    @Override
+    public boolean dropMaterializedTable(String path) {
+        return dropMaterializedTable(path, true);
+    }
+
+    @Override
+    public boolean dropMaterializedTable(String path, boolean 
ignoreIfNotExists) {
+        Preconditions.checkNotNull(path, "Path must not be null.");
+        final ObjectIdentifier identifier = getObjectIdentifierFromPath(path);
+        if (ignoreIfNotExists && !isPermanentMaterializedTable(identifier)) {
+            return false;
+        }
+        executeInternal(new DropMaterializedTableOperation(identifier, 
ignoreIfNotExists));

Review Comment:
   Instead of documenting the difference to SQL, could we fix `DROP 
MATERIALIZED TABLE IF EXISTS` itself? `DROP TABLE IF EXISTS <view>` / `DROP 
VIEW IF EXISTS <table>` and `CatalogManager.dropMaterializedTable` all treat an 
object of the wrong kind as absent. Only 
`DefaultMaterializedTableExecutor#callDropMaterializedTableOperation` throws, 
because it checks `catalog.tableExists` (true for any kind) and then 
`getCatalogMaterializedTable`. If it looked up the permanent object via 
`getUnresolvedTable` (public with this PR) and skipped on a non-MT under `IF 
EXISTS`, SQL and `dropMaterializedTable` would agree and the docs' "semantics 
of DROP MATERIALIZED TABLE" would hold.
   
   One caveat: the check must not go through `getTableOrError`, or a temporary 
view shadowing an MT would silently skip. That case could throw a clear "drop 
the temporary object first" error, which would also replace today's misleading 
"is not a materialized table". Since this changes SQL behavior, maybe a 
separate ticket and a preliminary commit (or PR)?



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/TableEnvironment.java:
##########
@@ -1477,6 +1477,44 @@ void createTemporarySystemFunction(
      */
     boolean dropTemporaryModel(String path);
 
+    /**
+     * Drops a materialized table registered in the given path.
+     *
+     * <p>If its continuous refresh job is running, it is cancelled before the 
materialized table is
+     * removed from the catalog. Dropping a materialized table in full refresh 
mode requires a
+     * workflow scheduler and fails on a plain {@link TableEnvironment}.
+     *
+     * <p>This method can only drop permanent objects. If a temporary table or 
view in the given
+     * path shadows the materialized table, a {@link ValidationException} is 
thrown. Drop the
+     * temporary object first using {@link #dropTemporaryTable} or {@link 
#dropTemporaryView}.
+     *
+     * @param path The given path under which the materialized table will be 
dropped. See also the
+     *     {@link TableEnvironment} class description for the format of the 
path.
+     * @return true if a materialized table was found in the given path and 
the drop was executed,

Review Comment:
   Nit: `dropTable(String)` and `dropView(String)` both say "Compared to SQL, 
this method will not throw an error if the table does not exist. Use {@link 
#dropTable(java.lang.String, boolean)} to change the default behavior." Could 
the 1-arg `dropMaterializedTable` carry the same sentence, so the 
`ignoreIfNotExists = true` default and the overload are explicit?



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