|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.polaris.extensions.federation.hive; |
| 20 | + |
| 21 | +import io.smallrye.common.annotation.Identifier; |
| 22 | +import jakarta.enterprise.context.ApplicationScoped; |
| 23 | +import org.apache.iceberg.catalog.Catalog; |
| 24 | +import org.apache.iceberg.hive.HiveCatalog; |
| 25 | +import org.apache.polaris.core.catalog.ExternalCatalogFactory; |
| 26 | +import org.apache.polaris.core.connection.AuthenticationParametersDpo; |
| 27 | +import org.apache.polaris.core.connection.AuthenticationType; |
| 28 | +import org.apache.polaris.core.connection.ConnectionConfigInfoDpo; |
| 29 | +import org.apache.polaris.core.connection.ConnectionType; |
| 30 | +import org.apache.polaris.core.connection.hive.HiveConnectionConfigInfoDpo; |
| 31 | +import org.apache.polaris.core.secrets.UserSecretsManager; |
| 32 | +import org.slf4j.Logger; |
| 33 | +import org.slf4j.LoggerFactory; |
| 34 | + |
| 35 | +/** Factory class for creating a Hive catalog handle based on connection configuration. */ |
| 36 | +@ApplicationScoped |
| 37 | +@Identifier(ConnectionType.HIVE_FACTORY_IDENTIFIER) |
| 38 | +public class HiveFederatedCatalogFactory implements ExternalCatalogFactory { |
| 39 | + private static final Logger LOGGER = LoggerFactory.getLogger(HiveFederatedCatalogFactory.class); |
| 40 | + |
| 41 | + @Override |
| 42 | + public Catalog createCatalog( |
| 43 | + ConnectionConfigInfoDpo connectionConfigInfoDpo, UserSecretsManager userSecretsManager) { |
| 44 | + // Currently, Polaris supports Hive federation only via IMPLICIT authentication. |
| 45 | + // Hence, prior to initializing the configuration, ensure that the catalog uses |
| 46 | + // IMPLICIT authentication. |
| 47 | + AuthenticationParametersDpo authenticationParametersDpo = |
| 48 | + connectionConfigInfoDpo.getAuthenticationParameters(); |
| 49 | + if (authenticationParametersDpo.getAuthenticationTypeCode() |
| 50 | + != AuthenticationType.IMPLICIT.getCode()) { |
| 51 | + throw new IllegalStateException("Hive federation only supports IMPLICIT authentication."); |
| 52 | + } |
| 53 | + String warehouse = ((HiveConnectionConfigInfoDpo) connectionConfigInfoDpo).getWarehouse(); |
| 54 | + // Unlike Hadoop, HiveCatalog does not require us to create a Configuration object, the iceberg |
| 55 | + // rest library find the default configuration by reading hive-site.xml in the classpath |
| 56 | + // (including HADOOP_CONF_DIR classpath). |
| 57 | + |
| 58 | + // TODO: In the future, we could support multiple HiveCatalog instances based on polaris/catalog |
| 59 | + // properties. |
| 60 | + // A brief set of setps involved (and the options): |
| 61 | + // 1. Create a configuration without default properties. |
| 62 | + // `Configuration conf = new Configuration(boolean loadDefaults=false);` |
| 63 | + // 2a. Specify the hive-site.xml file path in the configuration. |
| 64 | + // `conf.addResource(new Path(hiveSiteXmlPath));` |
| 65 | + // 2b. Specify individual properties in the configuration. |
| 66 | + // `conf.set(property, value);` |
| 67 | + // Polaris could support federating to multiple LDAP based Hive metastores. Multiple |
| 68 | + // Kerberos instances are not suitable because Kerberos ties a single identity to the server. |
| 69 | + HiveCatalog hiveCatalog = new HiveCatalog(); |
| 70 | + hiveCatalog.initialize( |
| 71 | + warehouse, connectionConfigInfoDpo.asIcebergCatalogProperties(userSecretsManager)); |
| 72 | + return hiveCatalog; |
| 73 | + } |
| 74 | +} |
0 commit comments