[ 
https://issues.apache.org/jira/browse/FLINK-22272?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17320767#comment-17320767
 ] 

wangzeyu edited comment on FLINK-22272 at 4/14/21, 9:04 AM:
------------------------------------------------------------

So here's my solution , in class org.apache.flink.table.catalog.CatalogManager
{code:java}
private void dropTableInternal(
        ObjectIdentifier objectIdentifier, boolean ignoreIfNotExists, boolean 
isDropTable) {
    Predicate<CatalogBaseTable> filter =
            isDropTable
                    ? table -> table instanceof CatalogTable
                    : table -> table instanceof CatalogView;
    // Same name temporary table or view exists.
    if (filter.test(temporaryTables.get(objectIdentifier))) {
        String tableOrView = isDropTable ? "table" : "view";
        throw new ValidationException(
                String.format(
                        "Temporary %s with identifier '%s' exists. "
                                + "Drop it first before removing the permanent 
%s.",
                        tableOrView, objectIdentifier, tableOrView));
    }
        execute(
                (catalog, path) -> catalog.dropTable(path, ignoreIfNotExists),
                objectIdentifier,
                ignoreIfNotExists,
                "DropTable");
}
{code}
And in order to support the issue [FLINK-17756]  , add some code in 
org.apache.flink.table.catalog.hive.HiveCatalog
{code:java}
@Override
public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists)
        throws TableNotExistException, CatalogException {
    checkNotNull(tablePath, "tablePath cannot be null");

    if ( TableType.valueOf(getHiveTable(tablePath).getTableType()) != 
TableType.VIRTUAL_VIEW) {
        try {
            client.dropTable(
                    tablePath.getDatabaseName(),
                    tablePath.getObjectName(),
                    // Indicate whether associated data should be deleted.
                    // Set to 'true' for now because Flink tables shouldn't 
have data in Hive. Can
                    // be changed later if necessary
                    true,
                    ignoreIfNotExists);
        } catch (NoSuchObjectException e) {
            if (!ignoreIfNotExists) {
                throw new TableNotExistException(getName(), tablePath);
            }
        } catch (TException e) {
            throw new CatalogException(
                    String.format("Failed to drop table %s", 
tablePath.getFullName()), e);
        }
    }
}
{code}


was (Author: wangzeyu):
So here's my solution , in class org.apache.flink.table.catalog.CatalogManager
{code:java}
private void dropTableInternal(
        ObjectIdentifier objectIdentifier, boolean ignoreIfNotExists, boolean 
isDropTable) {
    Predicate<CatalogBaseTable> filter =
            isDropTable
                    ? table -> table instanceof CatalogTable
                    : table -> table instanceof CatalogView;
    // Same name temporary table or view exists.
    if (filter.test(temporaryTables.get(objectIdentifier))) {
        String tableOrView = isDropTable ? "table" : "view";
        throw new ValidationException(
                String.format(
                        "Temporary %s with identifier '%s' exists. "
                                + "Drop it first before removing the permanent 
%s.",
                        tableOrView, objectIdentifier, tableOrView));
    }
        execute(
                (catalog, path) -> catalog.dropTable(path, ignoreIfNotExists),
                objectIdentifier,
                ignoreIfNotExists,
                "DropTable");
}
{code}

> Some scenes can't drop table by hive catalog
> --------------------------------------------
>
>                 Key: FLINK-22272
>                 URL: https://issues.apache.org/jira/browse/FLINK-22272
>             Project: Flink
>          Issue Type: Bug
>          Components: Connectors / Hive
>    Affects Versions: 1.12.1
>            Reporter: wangzeyu
>            Priority: Major
>             Fix For: 1.12.1
>
>
> There are some scenes we can't drop table by hive catalog because of we 
> execute error create table sql like "caeate table tableName". And then when 
> we execute drop table sql "drop table tableName" will throw error 
> "org.apache.flink.table.catalog.exceptions.CatalogException: Failed to get 
> table schema from properties for generic table".
> So, i think maybe we should remove the check when we drop table by 
> third-party catalog and just drop table depend on the third-party catalog.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to