-
Notifications
You must be signed in to change notification settings - Fork 293
Support HMS Federation #2355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Support HMS Federation #2355
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!-- | ||
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. | ||
--> | ||
### Using the `HiveFederatedCatalogFactory` | ||
|
||
This `HiveFederatedCatalogFactory` module is an independent compilation unit and will be built into the Polaris binary only when the following flag is set in the gradle.properties file: | ||
``` | ||
NonRESTCatalogs=HIVE,<alternates> | ||
``` | ||
|
||
The other option is to pass it as an argument to the gradle JVM as follows: | ||
``` | ||
./gradlew build -DNonRESTCatalogs=HIVE | ||
``` | ||
|
||
Without this flag, the Hive factory won't be compiled into Polaris and therefore Polaris will not load the class at runtime, throwing an unsupported exception for federated catalog calls. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
plugins { | ||
id("polaris-client") | ||
alias(libs.plugins.jandex) | ||
} | ||
|
||
dependencies { | ||
// Polaris dependencies | ||
implementation(project(":polaris-core")) | ||
|
||
implementation(platform(libs.iceberg.bom)) | ||
implementation("org.apache.iceberg:iceberg-api") | ||
implementation("org.apache.iceberg:iceberg-core") | ||
implementation("org.apache.iceberg:iceberg-common") | ||
// Use iceberg-hive-metastore but exclude conflicting hive dependencies | ||
implementation("org.apache.iceberg:iceberg-hive-metastore") { exclude(group = "org.apache.hive") } | ||
// Add our own Hive 4.1.0 dependencies | ||
implementation(libs.hive.metastore) { | ||
exclude("org.slf4j", "slf4j-reload4j") | ||
exclude("org.slf4j", "slf4j-log4j12") | ||
exclude("ch.qos.reload4j", "reload4j") | ||
exclude("log4j", "log4j") | ||
exclude("org.apache.zookeeper", "zookeeper") | ||
} | ||
|
||
// Hadoop dependencies | ||
implementation(libs.hadoop.common) { | ||
exclude("org.slf4j", "slf4j-reload4j") | ||
exclude("org.slf4j", "slf4j-log4j12") | ||
exclude("ch.qos.reload4j", "reload4j") | ||
exclude("log4j", "log4j") | ||
exclude("org.apache.zookeeper", "zookeeper") | ||
exclude("org.apache.hadoop.thirdparty", "hadoop-shaded-protobuf_3_25") | ||
exclude("com.github.pjfanning", "jersey-json") | ||
exclude("com.sun.jersey", "jersey-core") | ||
exclude("com.sun.jersey", "jersey-server") | ||
exclude("com.sun.jersey", "jersey-servlet") | ||
exclude("io.dropwizard.metrics", "metrics-core") | ||
} | ||
|
||
// CDI dependencies for runtime discovery | ||
implementation(libs.jakarta.enterprise.cdi.api) | ||
implementation(libs.smallrye.common.annotation) | ||
|
||
// Logging | ||
implementation(libs.slf4j.api) | ||
} |
74 changes: 74 additions & 0 deletions
74
.../main/java/org/apache/polaris/extensions/federation/hive/HiveFederatedCatalogFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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). | ||
|
||
// TODO: In the future, we could support multiple HiveCatalog instances based on polaris/catalog | ||
// properties. | ||
// A brief set of setps involved (and the options): | ||
// 1. Create a configuration without default properties. | ||
// `Configuration conf = new Configuration(boolean loadDefaults=false);` | ||
// 2a. Specify the hive-site.xml file path in the configuration. | ||
// `conf.addResource(new Path(hiveSiteXmlPath));` | ||
// 2b. Specify individual properties in the configuration. | ||
// `conf.set(property, value);` | ||
// Polaris could support federating to multiple LDAP based Hive metastores. Multiple | ||
// Kerberos instances are not suitable because Kerberos ties a single identity to the server. | ||
HiveCatalog hiveCatalog = new HiveCatalog(); | ||
hiveCatalog.initialize( | ||
warehouse, connectionConfigInfoDpo.asIcebergCatalogProperties(userSecretsManager)); | ||
return hiveCatalog; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...re/src/main/java/org/apache/polaris/core/connection/hive/HiveConnectionConfigInfoDpo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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.core.connection.hive; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.MoreObjects; | ||
import jakarta.annotation.Nonnull; | ||
import jakarta.annotation.Nullable; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.iceberg.CatalogProperties; | ||
import org.apache.polaris.core.admin.model.ConnectionConfigInfo; | ||
import org.apache.polaris.core.admin.model.HiveConnectionConfigInfo; | ||
import org.apache.polaris.core.connection.AuthenticationParametersDpo; | ||
import org.apache.polaris.core.connection.ConnectionConfigInfoDpo; | ||
import org.apache.polaris.core.connection.ConnectionType; | ||
import org.apache.polaris.core.secrets.UserSecretsManager; | ||
|
||
/** | ||
* The internal persistence-object counterpart to {@link | ||
* org.apache.polaris.core.admin.model.HiveConnectionConfigInfo} defined in the API model. | ||
*/ | ||
public class HiveConnectionConfigInfoDpo extends ConnectionConfigInfoDpo { | ||
|
||
private final String warehouse; | ||
|
||
public HiveConnectionConfigInfoDpo( | ||
@JsonProperty(value = "uri", required = true) @Nonnull String uri, | ||
@JsonProperty(value = "authenticationParameters", required = false) @Nullable | ||
AuthenticationParametersDpo authenticationParameters, | ||
@JsonProperty(value = "warehouse", required = false) @Nullable String warehouse) { | ||
super(ConnectionType.HIVE.getCode(), uri, authenticationParameters); | ||
this.warehouse = warehouse; | ||
} | ||
|
||
public String getWarehouse() { | ||
return warehouse; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("connectionTypeCode", getConnectionTypeCode()) | ||
.add("uri", getUri()) | ||
.add("warehouse", getWarehouse()) | ||
.add("authenticationParameters", getAuthenticationParameters().toString()) | ||
.toString(); | ||
} | ||
|
||
@Override | ||
public @Nonnull Map<String, String> asIcebergCatalogProperties( | ||
UserSecretsManager secretsManager) { | ||
HashMap<String, String> properties = new HashMap<>(); | ||
properties.put(CatalogProperties.URI, getUri()); | ||
if (getWarehouse() != null) { | ||
properties.put(CatalogProperties.WAREHOUSE_LOCATION, getWarehouse()); | ||
} | ||
if (getAuthenticationParameters() != null) { | ||
properties.putAll(getAuthenticationParameters().asIcebergCatalogProperties(secretsManager)); | ||
} | ||
return properties; | ||
} | ||
|
||
@Override | ||
public ConnectionConfigInfo asConnectionConfigInfoModel() { | ||
return HiveConnectionConfigInfo.builder() | ||
.setConnectionType(ConnectionConfigInfo.ConnectionTypeEnum.HIVE) | ||
.setUri(getUri()) | ||
.setWarehouse(getWarehouse()) | ||
.setAuthenticationParameters( | ||
getAuthenticationParameters().asAuthenticationParametersModel()) | ||
.build(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 tohiveCatalog.initialize
and our constructedConfiguration
should begin withnew 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.