|
| 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.core.connection.hive; |
| 20 | + |
| 21 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 22 | +import com.google.common.base.MoreObjects; |
| 23 | +import jakarta.annotation.Nonnull; |
| 24 | +import jakarta.annotation.Nullable; |
| 25 | +import java.util.HashMap; |
| 26 | +import java.util.Map; |
| 27 | +import org.apache.iceberg.CatalogProperties; |
| 28 | +import org.apache.polaris.core.admin.model.ConnectionConfigInfo; |
| 29 | +import org.apache.polaris.core.admin.model.HiveConnectionConfigInfo; |
| 30 | +import org.apache.polaris.core.connection.AuthenticationParametersDpo; |
| 31 | +import org.apache.polaris.core.connection.ConnectionConfigInfoDpo; |
| 32 | +import org.apache.polaris.core.connection.ConnectionType; |
| 33 | +import org.apache.polaris.core.secrets.UserSecretsManager; |
| 34 | + |
| 35 | +/** |
| 36 | + * The internal persistence-object counterpart to {@link |
| 37 | + * org.apache.polaris.core.admin.model.HiveConnectionConfigInfo} defined in the API model. |
| 38 | + */ |
| 39 | +public class HiveConnectionConfigInfoDpo extends ConnectionConfigInfoDpo { |
| 40 | + |
| 41 | + private final String warehouse; |
| 42 | + |
| 43 | + public HiveConnectionConfigInfoDpo( |
| 44 | + @JsonProperty(value = "uri", required = true) @Nonnull String uri, |
| 45 | + @JsonProperty(value = "authenticationParameters", required = false) @Nullable |
| 46 | + AuthenticationParametersDpo authenticationParameters, |
| 47 | + @JsonProperty(value = "warehouse", required = false) @Nullable String warehouse) { |
| 48 | + super(ConnectionType.HIVE.getCode(), uri, authenticationParameters); |
| 49 | + this.warehouse = warehouse; |
| 50 | + } |
| 51 | + |
| 52 | + public String getWarehouse() { |
| 53 | + return warehouse; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public String toString() { |
| 58 | + return MoreObjects.toStringHelper(this) |
| 59 | + .add("connectionTypeCode", getConnectionTypeCode()) |
| 60 | + .add("uri", getUri()) |
| 61 | + .add("warehouse", getWarehouse()) |
| 62 | + .add("authenticationParameters", getAuthenticationParameters().toString()) |
| 63 | + .toString(); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public @Nonnull Map<String, String> asIcebergCatalogProperties( |
| 68 | + UserSecretsManager secretsManager) { |
| 69 | + HashMap<String, String> properties = new HashMap<>(); |
| 70 | + properties.put(CatalogProperties.URI, getUri()); |
| 71 | + if (getWarehouse() != null) { |
| 72 | + properties.put(CatalogProperties.WAREHOUSE_LOCATION, getWarehouse()); |
| 73 | + } |
| 74 | + if (getAuthenticationParameters() != null) { |
| 75 | + properties.putAll(getAuthenticationParameters().asIcebergCatalogProperties(secretsManager)); |
| 76 | + } |
| 77 | + return properties; |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public ConnectionConfigInfo asConnectionConfigInfoModel() { |
| 82 | + return HiveConnectionConfigInfo.builder() |
| 83 | + .setConnectionType(ConnectionConfigInfo.ConnectionTypeEnum.HIVE) |
| 84 | + .setUri(getUri()) |
| 85 | + .setWarehouse(getWarehouse()) |
| 86 | + .setAuthenticationParameters( |
| 87 | + getAuthenticationParameters().asAuthenticationParametersModel()) |
| 88 | + .build(); |
| 89 | + } |
| 90 | +} |
0 commit comments