difin commented on code in PR #6449: URL: https://github.com/apache/hive/pull/6449#discussion_r3350645166
########## iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/IcebergNativeLogicalViewSupport.java: ########## @@ -0,0 +1,154 @@ +/* + * 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.iceberg.hive; + +import java.io.Closeable; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.metastore.api.FieldSchema; +import org.apache.iceberg.CatalogUtil; +import org.apache.iceberg.catalog.Catalog; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.catalog.ViewCatalog; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.view.ViewBuilder; + +/** + * Commits a native Iceberg view through the configured default Iceberg catalog (HiveCatalog or REST + * catalog, etc.) when {@code Catalog} also implements {@link ViewCatalog}. + */ +public final class IcebergNativeLogicalViewSupport { + + /** Value for HMS {@code table_type} on native Iceberg logical views (uppercase, HMS convention). */ + public static final String ICEBERG_VIEW_HMS_TABLE_TYPE_VALUE = + HiveOperationsBase.ICEBERG_VIEW_TYPE_VALUE.toUpperCase(java.util.Locale.ENGLISH); + + private IcebergNativeLogicalViewSupport() { + } + + /** + * Loads the native Iceberg logical view definition and applies SQL, schema, and Iceberg params to {@code hmsTable} + */ + public static void enrichHmsTableFromIcebergView( + org.apache.hadoop.hive.metastore.api.Table hmsTable, Configuration conf) { + TableIdentifier identifier = TableIdentifier.of(hmsTable.getDbName(), hmsTable.getTableName()); + String catalogName = IcebergCatalogProperties.getCatalogName(conf); + Map<String, String> catalogProps = IcebergCatalogProperties.getCatalogProperties(conf, catalogName); + Catalog catalog = CatalogUtil.buildIcebergCatalog(catalogName, catalogProps, conf); + + try { + if (catalog instanceof Closeable closeable) { + try (Closeable ignored = closeable) { Review Comment: `buildIcebergCatalog` gives us a one-off catalog for this call. The `Catalog` interface isn’t `Closeable`, but some implementations are (`RestCatalog` is `Closable`) and they hold clients/IO that need to be closed when we’re done. `HiveCatalog` often isn’t, so we only wrap when `instanceof Closeable`. We are not ignoring it. The `try (Closeable ignored = closeable)` bit is just `try-with-resources`, we need a variable so `close()` runs at the end of the block. We don’t reference it in the body because we already use catalog for `loadView`. Naming it as `ignored` is only to signal “this exists for cleanup, not for logic.” Without it you can leak connections on every postGetTable enrich against REST. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
