Skip to content

Commit

Permalink
Core: Refactor HadoopCatalog constructors (apache#2323)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Murray authored Mar 12, 2021
1 parent c8b74c1 commit 28621f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 38 deletions.
50 changes: 13 additions & 37 deletions core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.apache.iceberg.relocated.com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -94,40 +93,6 @@ public class HadoopCatalog extends BaseMetastoreCatalog implements Closeable, Su
public HadoopCatalog(){
}

/**
* The constructor of the HadoopCatalog. It uses the passed location as its warehouse directory.
*
* @deprecated please use the no-arg constructor, setConf and initialize to construct the catalog. Will be removed in
* v0.12.0
* @param name The catalog name
* @param conf The Hadoop configuration
* @param warehouseLocation The location used as warehouse directory
*/
@Deprecated
public HadoopCatalog(String name, Configuration conf, String warehouseLocation) {
this(name, conf, warehouseLocation, Maps.newHashMap());
}

/**
* The all-arg constructor of the HadoopCatalog.
*
* @deprecated please use the no-arg constructor, setConf and initialize to construct the catalog. Will be removed in
* v0.12.0
* @param name The catalog name
* @param conf The Hadoop configuration
* @param warehouseLocation The location used as warehouse directory
* @param properties catalog properties
*/
@Deprecated
public HadoopCatalog(String name, Configuration conf, String warehouseLocation, Map<String, String> properties) {
Preconditions.checkArgument(warehouseLocation != null && !warehouseLocation.equals(""),
"Cannot instantiate hadoop catalog. No location provided for warehouse");
setConf(conf);
Map<String, String> props = Maps.newHashMap(properties);
props.put(CatalogProperties.WAREHOUSE_LOCATION, warehouseLocation);
initialize(name, props);
}

@Override
public void initialize(String name, Map<String, String> properties) {
String inputWarehouseLocation = properties.get(CatalogProperties.WAREHOUSE_LOCATION);
Expand All @@ -146,22 +111,33 @@ public void initialize(String name, Map<String, String> properties) {
/**
* The constructor of the HadoopCatalog. It uses the passed location as its warehouse directory.
*
* @deprecated please use the no-arg constructor, setConf and initialize to construct the catalog. Will be removed in
* v0.13.0
*
* @param conf The Hadoop configuration
* @param warehouseLocation The location used as warehouse directory
*/
@Deprecated
public HadoopCatalog(Configuration conf, String warehouseLocation) {
this("hadoop", conf, warehouseLocation);
setConf(conf);
initialize("hadoop", ImmutableMap.of(CatalogProperties.WAREHOUSE_LOCATION, warehouseLocation));
}

/**
* The constructor of the HadoopCatalog. It gets the value of <code>fs.defaultFS</code> property
* from the passed Hadoop configuration as its default file system, and use the default directory
* <code>iceberg/warehouse</code> as the warehouse directory.
*
* @deprecated please use the no-arg constructor, setConf and initialize to construct the catalog. Will be removed in
* v0.13.0
*
* @param conf The Hadoop configuration
*/
@Deprecated
public HadoopCatalog(Configuration conf) {
this("hadoop", conf, conf.get("fs.defaultFS") + "/" + ICEBERG_HADOOP_WAREHOUSE_BASE);
setConf(conf);
String hadoopWarehouseLocation = conf.get("fs.defaultFS") + "/" + ICEBERG_HADOOP_WAREHOUSE_BASE;
initialize("hadoop", ImmutableMap.of(CatalogProperties.WAREHOUSE_LOCATION, hadoopWarehouseLocation));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private HadoopCatalogLoader(

@Override
public Catalog loadCatalog() {
return new HadoopCatalog(catalogName, hadoopConf.get(), warehouseLocation, properties);
return CatalogUtil.loadCatalog(HadoopCatalog.class.getName(), catalogName, properties, hadoopConf.get());
}

@Override
Expand Down

0 comments on commit 28621f9

Please sign in to comment.