JingsongLi commented on a change in pull request #12314:
URL: https://github.com/apache/flink/pull/12314#discussion_r429745290
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java
##########
@@ -682,20 +682,60 @@ public void alterTable(CatalogBaseTable table,
ObjectIdentifier objectIdentifier
* Drops a table in a given fully qualified path.
*
* @param objectIdentifier The fully qualified path of the table to
drop.
- * @param ignoreIfNotExists If false exception will be thrown if the
table or database or catalog to be altered
+ * @param ignoreIfNotExists If false exception will be thrown if the
table to drop
* does not exist.
*/
public void dropTable(ObjectIdentifier objectIdentifier, boolean
ignoreIfNotExists) {
- if (temporaryTables.containsKey(objectIdentifier)) {
- throw new ValidationException(String.format(
- "Temporary table with identifier '%s' exists.
Drop it first before removing the permanent table.",
- objectIdentifier));
+ dropTableInternal(
+ objectIdentifier,
+ table -> table instanceof CatalogTable,
+ ignoreIfNotExists);
+ }
+
+ /**
+ * Drops a view in a given fully qualified path.
+ *
+ * @param objectIdentifier The fully qualified path of the view to drop.
+ * @param ignoreIfNotExists If false exception will be thrown if the
view to drop
+ * does not exist.
+ */
+ public void dropView(ObjectIdentifier objectIdentifier, boolean
ignoreIfNotExists) {
+ dropTableInternal(
+ objectIdentifier,
+ table -> table instanceof CatalogView,
+ ignoreIfNotExists);
+ }
+
+ private void dropTableInternal(
+ ObjectIdentifier objectIdentifier,
+ Predicate<CatalogBaseTable> filter,
+ boolean ignoreIfNotExists) {
+ final Optional<TableLookupResult> resultOpt =
getTable(objectIdentifier);
+ if (resultOpt.isPresent()) {
+ final TableLookupResult result = resultOpt.get();
+ if (filter.test(result.getTable())) {
+ if (result.isTemporary()) {
+ // Same name temporary table or view
exists.
+ throw new
ValidationException(String.format(
+ "Temporary table or
view with identifier '%s' exists. "
+ + "Drop
it first before removing the permanent table or view.",
+ objectIdentifier));
+ }
+ } else if (!ignoreIfNotExists) {
+ // To drop a table but the object identifier
represents a view(or vise versa).
+ throw new ValidationException(String.format(
+ "Table or view with identifier
'%s' does not exist.",
+
objectIdentifier.asSummaryString()));
+ } else {
+ // Table or view does not exist with
ignoreIfNotExists true, do nothing.
+ return;
+ }
}
execute(
Review comment:
Can you move this `execute` into `if (filter.test(result.getTable()))`?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]