This is an automated email from the ASF dual-hosted git repository. difin pushed a commit to branch iceberg_native_views1 in repository https://gitbox.apache.org/repos/asf/hive.git
commit 5b98a6014cc44059120a73cad2ac89c566064103 Author: Dmitriy Fingerman <[email protected]> AuthorDate: Tue Jun 2 23:57:22 2026 -0400 fixes 3 --- .../org/apache/iceberg/hive/MetastoreUtil.java | 38 ++++++++++++---------- .../iceberg/hive/client/HiveRESTCatalogClient.java | 9 ++--- .../iceberg/mr/hive/BaseHiveIcebergMetaHook.java | 13 ++++---- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/MetastoreUtil.java b/iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/MetastoreUtil.java index 6b029c5326f..58b72cdd36d 100644 --- a/iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/MetastoreUtil.java +++ b/iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/MetastoreUtil.java @@ -36,7 +36,9 @@ import org.apache.hadoop.hive.metastore.api.SkewedInfo; import org.apache.hadoop.hive.metastore.api.StorageDescriptor; import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants; import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils; +import org.apache.iceberg.BaseMetastoreTableOperations; import org.apache.hadoop.hive.serde.serdeConstants; import org.apache.iceberg.BaseTable; import org.apache.iceberg.CatalogUtil; @@ -46,7 +48,6 @@ import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; import org.apache.iceberg.relocated.com.google.common.collect.Lists; import org.apache.iceberg.relocated.com.google.common.collect.Maps; -import org.apache.iceberg.util.PropertyUtil; import org.apache.iceberg.view.BaseView; import org.apache.iceberg.view.SQLViewRepresentation; import org.apache.iceberg.view.View; @@ -158,31 +159,32 @@ public static Table toHiveTable(org.apache.iceberg.Table table, Configuration co } /** - * Builds a Hive metastore {@link Table} representation for an Iceberg {@link View}, for clients - * (e.g. {@code HiveRESTCatalogClient}) that bridge Iceberg catalog metadata into the HMS API. + * Builds a minimal HMS {@link Table} shell for a native Iceberg logical view (identity, view type, + * and Iceberg storage-handler markers only). The storage handler {@code postGetTable} hook enriches + * this object via {@link IcebergNativeLogicalViewSupport#enrichHmsTableFromIcebergView} (view SQL, + * schema, and Iceberg parameters). */ - public static Table toHiveView(View view, Configuration conf) { + public static Table buildMinimalHMSView(String catName, String dbName, String tableName, Configuration conf) { Table result = new Table(); - TableName tableName = - TableName.fromString( - view.name(), MetaStoreUtils.getDefaultCatalog(conf), Warehouse.DEFAULT_DATABASE_NAME); - result.setCatName(tableName.getCat()); - result.setDbName(tableName.getDb()); - result.setTableName(tableName.getTable()); + result.setCatName( + catName != null ? catName : MetaStoreUtils.getDefaultCatalog(conf)); + result.setDbName(dbName); + result.setTableName(tableName); result.setTableType(TableType.VIRTUAL_VIEW.toString()); - long nowMillis = System.currentTimeMillis(); - int nowSec = (int) (nowMillis / 1000); - ViewMetadata metadata = ((BaseView) view).operations().current(); - String owner = - PropertyUtil.propertyAsString( - metadata.properties(), HiveCatalog.HMS_TABLE_OWNER, System.getProperty("user.name")); - result.setOwner(owner); + int nowSec = (int) (System.currentTimeMillis() / 1000); + result.setOwner(System.getProperty("user.name")); result.setCreateTime(nowSec); result.setLastAccessTime(nowSec); result.setRetention(Integer.MAX_VALUE); - applyIcebergViewToHmsTable(result, view, conf); + Map<String, String> parameters = Maps.newHashMap(); + parameters.put( + BaseMetastoreTableOperations.TABLE_TYPE_PROP, + IcebergNativeLogicalViewSupport.ICEBERG_VIEW_HMS_TABLE_TYPE_VALUE); + parameters.put( + hive_metastoreConstants.META_TABLE_STORAGE, HMSTablePropertyHelper.HIVE_ICEBERG_STORAGE_HANDLER); + result.setParameters(parameters); return result; } diff --git a/iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/client/HiveRESTCatalogClient.java b/iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/client/HiveRESTCatalogClient.java index 76f5ae7568b..1798b6811c7 100644 --- a/iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/client/HiveRESTCatalogClient.java +++ b/iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/client/HiveRESTCatalogClient.java @@ -49,7 +49,6 @@ import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.catalog.ViewCatalog; import org.apache.iceberg.exceptions.NoSuchTableException; -import org.apache.iceberg.exceptions.NoSuchViewException; import org.apache.iceberg.hive.HMSTablePropertyHelper; import org.apache.iceberg.hive.HiveSchemaUtil; import org.apache.iceberg.hive.IcebergCatalogProperties; @@ -61,7 +60,6 @@ import org.apache.iceberg.relocated.com.google.common.collect.Lists; import org.apache.iceberg.relocated.com.google.common.collect.Maps; import org.apache.iceberg.rest.RESTCatalog; -import org.apache.iceberg.view.View; import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -212,12 +210,11 @@ public Table getTable(GetTableRequest tableRequest) throws TException { return MetastoreUtil.toHiveTable(icebergTable, conf); } catch (NoSuchTableException tableMissing) { if (restCatalog instanceof ViewCatalog viewCatalog) { - try { - View icebergView = viewCatalog.loadView(id); - return MetastoreUtil.toHiveView(icebergView, conf); - } catch (NoSuchViewException viewMissing) { + if (!viewCatalog.viewExists(id)) { throw new NoSuchObjectException(); } + return MetastoreUtil.buildMinimalHMSView( + tableRequest.getCatName(), tableRequest.getDbName(), tableRequest.getTblName(), conf); } throw new NoSuchObjectException(); } diff --git a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/BaseHiveIcebergMetaHook.java b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/BaseHiveIcebergMetaHook.java index 8b25c625d71..ae05e709625 100644 --- a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/BaseHiveIcebergMetaHook.java +++ b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/BaseHiveIcebergMetaHook.java @@ -41,7 +41,6 @@ import org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint; import org.apache.hadoop.hive.metastore.api.SQLPrimaryKey; import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants; -import org.apache.hadoop.hive.metastore.conf.MetastoreConf; import org.apache.hadoop.hive.ql.ddl.misc.sortoder.SortFieldDesc; import org.apache.hadoop.hive.ql.ddl.misc.sortoder.SortFields; import org.apache.hadoop.hive.ql.ddl.misc.sortoder.ZOrderFieldDesc; @@ -60,13 +59,13 @@ import org.apache.iceberg.TableUtil; import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.exceptions.NoSuchTableException; +import org.apache.iceberg.exceptions.NoSuchViewException; import org.apache.iceberg.exceptions.NotFoundException; import org.apache.iceberg.hive.HMSTablePropertyHelper; import org.apache.iceberg.hive.HiveSchemaUtil; import org.apache.iceberg.hive.IcebergCatalogProperties; import org.apache.iceberg.hive.IcebergNativeLogicalViewSupport; import org.apache.iceberg.hive.IcebergTableProperties; -import org.apache.iceberg.hive.client.HiveRESTCatalogClient; import org.apache.iceberg.mr.Catalogs; import org.apache.iceberg.mr.InputFormatConfig; import org.apache.iceberg.relocated.com.google.common.base.Preconditions; @@ -535,8 +534,12 @@ public void postGetTable(org.apache.hadoop.hive.metastore.api.Table hmsTable) { if (hmsTable != null) { try { if (isNativeIcebergLogicalView(hmsTable)) { - if (!usesRestMetastoreClient(conf)) { + try { IcebergNativeLogicalViewSupport.enrichHmsTableFromIcebergView(hmsTable, conf); + } catch (NoSuchViewException ex) { + // Iceberg metadata not committed yet; keep HMS view text for compile. + LOG.debug("Iceberg view metadata missing for {}.{}, using HMS view text", + hmsTable.getDbName(), hmsTable.getTableName()); } return; } @@ -568,8 +571,4 @@ private static boolean isHiveIcebergStorageHandler(String storageHandler) { } } - private static boolean usesRestMetastoreClient(Configuration conf) { - String clientImpl = MetastoreConf.getVar(conf, MetastoreConf.ConfVars.METASTORE_CLIENT_IMPL); - return HiveRESTCatalogClient.class.getName().equals(clientImpl); - } }
