xuefuz commented on a change in pull request #8458: [FLINK-12452][table][hive] alterTable() should ensure existing base table and the new one are of the same type URL: https://github.com/apache/flink/pull/8458#discussion_r284477579
########## File path: flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/HiveCatalogBase.java ########## @@ -318,13 +320,44 @@ public void alterTable(ObjectPath tablePath, CatalogBaseTable newCatalogTable, b throw new TableNotExistException(catalogName, tablePath); } } else { - // TODO: [FLINK-12452] alterTable() in all catalogs should ensure existing base table and the new one are of the same type + Table oldTable = getHiveTable(tablePath); + TableType oldTableType = TableType.valueOf(oldTable.getTableType()); + + // Flink cannot alter existing Hive tables in types that Flink cannot create for now, + // including EXTERNAL_TABLE, INDEX_TABLE and MATERIALZED_VIEW. + // Note that though Flink cannot create them, it's able to read most parts of their metadata, + // like schema and properties, thru existing mechanism, but not their unique metadata. + // Also note that add capability of creating EXTERNAL_TABLE should be fairly easy to do, e.g. with a table property + // "table_type=external", we just haven't done it yet. + // INDEX_TABLE and MATERIALZED_VIEW need more research. + + if (oldTableType == TableType.EXTERNAL_TABLE + || oldTableType == TableType.INDEX_TABLE + || oldTableType == TableType.MATERIALIZED_VIEW) { + throw new CatalogException( + String.format("The existing Hive table is of type '%s', and HiveCatalogBase cannot handle it", oldTableType.name())); + } else if (oldTableType == TableType.VIRTUAL_VIEW) { + if (!(newCatalogTable instanceof CatalogView)) { + throw new CatalogException( + String.format("The existing table is a view, but the new catalog base table is not.")); + } + // Else, do nothing + } else if ((oldTableType == TableType.MANAGED_TABLE)) { + if (!(newCatalogTable instanceof CatalogTable)) { + throw new CatalogException( + String.format("The existing table is a table, but the new catalog base table is not.")); Review comment: Nit: maybe start the message with "Table type doesn't match. ...." ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services