a2l007 commented on code in PR #14329: URL: https://github.com/apache/druid/pull/14329#discussion_r1225897320
########## extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java: ########## @@ -0,0 +1,99 @@ +/* + * 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.druid.iceberg.input; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.apache.druid.data.input.InputFormat; +import org.apache.druid.iceberg.filter.IcebergFilter; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.RE; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.iceberg.BaseMetastoreCatalog; +import org.apache.iceberg.FileScanTask; +import org.apache.iceberg.TableScan; +import org.apache.iceberg.catalog.Catalog; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.io.CloseableIterable; + +import java.util.ArrayList; +import java.util.List; + +/* + * Druid wrapper for an iceberg catalog. + * The configured catalog is used to load the specified iceberg table and retrieve the underlying live data files upto the latest snapshot. + * This does not perform any projections on the table yet, therefore all the underlying columns will be retrieved from the data files. Review Comment: Yes, we create an iceberg table scan and feed it the set of filters before the plan files are identified. Therefore while the files are being planned, it can prune out the list based on the filters provided. ########## extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/HiveIcebergCatalog.java: ########## @@ -0,0 +1,136 @@ +/* + * 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.druid.iceberg.input; + +import com.fasterxml.jackson.annotation.JacksonInject; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import org.apache.druid.iceberg.guice.HiveConf; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.iceberg.BaseMetastoreCatalog; +import org.apache.iceberg.hive.HiveCatalog; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * Hive Metastore specific implementation of iceberg catalog. + * Kerberos authentication is performed if the credentials are provided in the catalog properties + */ +public class HiveIcebergCatalog extends IcebergCatalog +{ + public static final String TYPE_KEY = "hive"; + + @JsonProperty + private String warehousePath; + + @JsonProperty + private String catalogUri; + + @JsonProperty + private Map<String, String> catalogProperties; + + private final Configuration configuration; + + private BaseMetastoreCatalog hiveCatalog; + + private static final Logger log = new Logger(HiveIcebergCatalog.class); + + @JsonCreator + public HiveIcebergCatalog( + @JsonProperty("warehousePath") String warehousePath, + @JsonProperty("catalogUri") String catalogUri, + @JsonProperty("catalogProperties") @Nullable + Map<String, String> catalogProperties, + @JacksonInject @HiveConf Configuration configuration + ) + { + this.warehousePath = Preconditions.checkNotNull(warehousePath, "warehousePath cannot be null"); + this.catalogUri = Preconditions.checkNotNull(catalogUri, "catalogUri cannot be null"); + this.catalogProperties = catalogProperties != null ? catalogProperties : new HashMap<>(); + this.configuration = configuration; + this.catalogProperties + .forEach(this.configuration::set); + this.hiveCatalog = retrieveCatalog(); + } + + @Override + public BaseMetastoreCatalog retrieveCatalog() + { + if (hiveCatalog == null) { + hiveCatalog = setupCatalog(); + } + return hiveCatalog; + } + + private HiveCatalog setupCatalog() + { + HiveCatalog catalog = new HiveCatalog(); + authenticate(); + catalog.setConf(configuration); + catalogProperties.put("warehouse", warehousePath); + catalogProperties.put("uri", catalogUri); + catalog.initialize("hive", catalogProperties); + return catalog; + } + + private void authenticate() + { + String principal = catalogProperties.getOrDefault("principal", null); Review Comment: Added a line in the doc. -- 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]
