dennishuo commented on code in PR #2355: URL: https://github.com/apache/polaris/pull/2355#discussion_r2280008794
########## extensions/federation/hive/src/main/java/org/apache/polaris/extensions/federation/hive/HiveFederatedCatalogFactory.java: ########## @@ -0,0 +1,62 @@ +/* + * 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.polaris.extensions.federation.hive; + +import io.smallrye.common.annotation.Identifier; +import jakarta.enterprise.context.ApplicationScoped; +import org.apache.iceberg.catalog.Catalog; +import org.apache.iceberg.hive.HiveCatalog; +import org.apache.polaris.core.catalog.ExternalCatalogFactory; +import org.apache.polaris.core.connection.AuthenticationParametersDpo; +import org.apache.polaris.core.connection.AuthenticationType; +import org.apache.polaris.core.connection.ConnectionConfigInfoDpo; +import org.apache.polaris.core.connection.ConnectionType; +import org.apache.polaris.core.connection.hive.HiveConnectionConfigInfoDpo; +import org.apache.polaris.core.secrets.UserSecretsManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Factory class for creating a Hive catalog handle based on connection configuration. */ +@ApplicationScoped +@Identifier(ConnectionType.HIVE_FACTORY_IDENTIFIER) +public class HiveFederatedCatalogFactory implements ExternalCatalogFactory { + private static final Logger LOGGER = LoggerFactory.getLogger(HiveFederatedCatalogFactory.class); + + @Override + public Catalog createCatalog( + ConnectionConfigInfoDpo connectionConfigInfoDpo, UserSecretsManager userSecretsManager) { + // Currently, Polaris supports Hive federation only via IMPLICIT authentication. + // Hence, prior to initializing the configuration, ensure that the catalog uses + // IMPLICIT authentication. + AuthenticationParametersDpo authenticationParametersDpo = + connectionConfigInfoDpo.getAuthenticationParameters(); + if (authenticationParametersDpo.getAuthenticationTypeCode() + != AuthenticationType.IMPLICIT.getCode()) { + throw new IllegalStateException("Hive federation only supports IMPLICIT authentication."); + } + String warehouse = ((HiveConnectionConfigInfoDpo) connectionConfigInfoDpo).getWarehouse(); + // Unlike Hadoop, HiveCatalog does not require us to create a Configuration object, the iceberg + // rest library find the default configuration by reading hive-site.xml in the classpath + // (including HADOOP_CONF_DIR classpath). Review Comment: Could be worth adding a TODO here to better qualify the assertion about not requiring Configuration and requiring hive-site.xml (and so we don't forget), that if we *do* want Hadoop Configuration to come from runtime Polaris properties instead, that we need to call `hiveCatalog.setConf` *before* the call to `hiveCatalog.initialize` and our constructed `Configuration` should begin with `new Configuration(false)` to avoid loading the default hive-site.xml? AFAICT doing those two actions *should* be sufficient in potential multi-catalog environments to at least prevent basic conf-leakage between HiveCatalog instances. -- 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: issues-unsubscr...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org