czy006 commented on code in PR #4351: URL: https://github.com/apache/amoro/pull/4351#discussion_r3959087600
########## 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: **[Optional] The `UnsupportedOperationException` fallback is unreachable — the real failure mode is uncaught** The fallback in `HiveTableTypeUtil.listViewNames` only triggers via the interface's default method, but `HMSClientImpl` (the only production implementation) always overrides `getTableMeta` — so it's dead code outside Mockito tests. The scenario that can actually happen is an old metastore server without the `get_table_meta` endpoint (it only entered the HMS thrift IDL in Hive 2.0.0): the client then throws `TApplicationException`, which is a `TException`, isn't caught here, and fails the whole listing call — a new hard dependency this PR introduces. Non-blocking since Amoro supports HMS 2.x/3.x, but consider either dropping the fallback and letting `TException` propagate, or catching `TApplicationException` and falling back to `getTableObjectsByName` (which exists on Hive 1.x servers). ########## 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: **[Optional] Skip the extra `get_table_meta` RPC when iceberg already excludes views** For hive-type iceberg catalogs, `IcebergCatalog.listTables` now always adds one `get_table_meta` call. With `list-all-tables=false` (the default; nothing in Amoro overrides it), iceberg's `HiveCatalog` already filters by `table_type=iceberg`, so views are absent and the new filter is a guaranteed no-op — pure overhead in the default config. Consider gating on the property: ```java boolean listAllTables = Boolean.parseBoolean(properties.getOrDefault("list-all-tables", "false")); if (hiveClientPool == null || tableNames.isEmpty() || !listAllTables) { return tableNames; } ``` -- 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]
