csurong commented on code in PR #4351: URL: https://github.com/apache/amoro/pull/4351#discussion_r3964439438
########## amoro-common/src/main/java/org/apache/amoro/hive/HiveTableTypeUtil.java: ########## @@ -0,0 +1,112 @@ +/* + * 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.amoro.hive; + +import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.hadoop.hive.metastore.api.TableMeta; +import org.apache.thrift.TException; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Set; +import java.util.stream.Collectors; + +/** Utilities for classifying Hive Metastore table objects. */ +public final class HiveTableTypeUtil { + + private static final String VIRTUAL_VIEW_TYPE = "VIRTUAL_VIEW"; + private static final String MATERIALIZED_VIEW_TYPE = "MATERIALIZED_VIEW"; + private static final List<String> VIEW_TYPES = + Collections.unmodifiableList(Arrays.asList(VIRTUAL_VIEW_TYPE, MATERIALIZED_VIEW_TYPE)); + + private HiveTableTypeUtil() {} + + /** Returns the Hive table type names representing virtual or materialized views. */ + public static List<String> viewTypes() { + return VIEW_TYPES; + } + + /** Returns whether the Hive table is a virtual or materialized view. */ + public static boolean isView(Table table) { + return table != null && isViewType(table.getTableType()); + } + + /** Returns whether the lightweight Hive table metadata describes a view. */ + public static boolean isView(TableMeta table) { + return table != null && isViewType(table.getTableType()); + } + + /** + * Returns the normalized names of Hive views among the candidate tables. + * + * <p>The lightweight table metadata API is preferred. Clients that do not implement that API fall + * back to loading the candidate table objects. + * + * @param client Hive Metastore client + * @param database database containing the candidate tables + * @param candidateTableNames table names to inspect + * @return lowercase names of virtual and materialized views + */ + public static Set<String> listViewNames( + HMSClient client, String database, List<String> candidateTableNames) throws TException { + if (candidateTableNames == null || candidateTableNames.isEmpty()) { + return Collections.emptySet(); + } + + List<TableMeta> views; + try { + views = client.getTableMeta(database, "*", viewTypes()); + } catch (UnsupportedOperationException e) { Review Comment: Done, thanks for the suggestion ########## amoro-format-iceberg/src/main/java/org/apache/amoro/formats/iceberg/IcebergCatalog.java: ########## @@ -89,11 +118,32 @@ public void dropDatabase(String database) { @Override public List<String> listTables(String database) { - return metaStore.doAs( - () -> - icebergCatalog.listTables(Namespace.of(database)).stream() - .map(TableIdentifier::name) - .collect(Collectors.toList())); + List<String> tableNames = + metaStore.doAs( + () -> + icebergCatalog.listTables(Namespace.of(database)).stream() + .map(TableIdentifier::name) + .collect(Collectors.toList())); + if (hiveClientPool == null || tableNames.isEmpty()) { Review Comment: Done, thanks for the suggestion -- 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]
