diff --git hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatLoader.java hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatLoader.java index 4bdb7c3..5a4d400 100644 --- hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatLoader.java +++ hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatLoader.java @@ -82,7 +82,7 @@ public class HCatLoader extends HCatBaseLoader { @Override public void setLocation(String location, Job job) throws IOException { - HCatContext.setupHCatContext(job.getConfiguration()).getConf().get() + HCatContext.INSTANCE.setConf(job.getConfiguration()).getConf().get() .setBoolean(HCatConstants.HCAT_DATA_TINY_SMALL_INT_PROMOTION, true); UDFContext udfContext = UDFContext.getUDFContext(); @@ -187,7 +187,7 @@ public class HCatLoader extends HCatBaseLoader { @Override public ResourceSchema getSchema(String location, Job job) throws IOException { - HCatContext.setupHCatContext(job.getConfiguration()).getConf().get() + HCatContext.INSTANCE.setConf(job.getConfiguration()).getConf().get() .setBoolean(HCatConstants.HCAT_DATA_TINY_SMALL_INT_PROMOTION, true); Table table = phutil.getTable(location, diff --git hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatStorer.java hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatStorer.java index 54c174b..a457a07 100644 --- hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatStorer.java +++ hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatStorer.java @@ -77,7 +77,7 @@ public class HCatStorer extends HCatBaseStorer { @Override public void setStoreLocation(String location, Job job) throws IOException { - HCatContext.setupHCatContext(job.getConfiguration()).getConf().get() + HCatContext.INSTANCE.setConf(job.getConfiguration()).getConf().get() .setBoolean(HCatConstants.HCAT_DATA_TINY_SMALL_INT_PROMOTION, false); Configuration config = job.getConfiguration(); diff --git src/java/org/apache/hcatalog/common/HCatContext.java src/java/org/apache/hcatalog/common/HCatContext.java index 1c40b5e..34e1af9 100644 --- src/java/org/apache/hcatalog/common/HCatContext.java +++ src/java/org/apache/hcatalog/common/HCatContext.java @@ -21,50 +21,65 @@ package org.apache.hcatalog.common; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.common.classification.InterfaceAudience; +import org.apache.hadoop.hive.common.classification.InterfaceStability; import java.util.Map; /** - * HCatContext provides global access to configuration data. It uses a reference to the - * job configuration so that settings are automatically passed to the backend by the - * MR framework. + * HCatContext is a singleton that provides global access to configuration data. + * + *
HCatalog provides a variety of functionality that users can configure at runtime through + * configuration properties. Available configuration properties are defined in + * {@link HCatConstants}. HCatContext allows users to enable optional functionality by + * setting properties in a provided configuration.
+ * + *HCatalog users (MR apps, processing framework adapters) should set properties + * in a configuration that has been provided to + * {@link #setConf(org.apache.hadoop.conf.Configuration)} to enable optional functionality. + * The job configuration must be used to ensure properties are passed to the backend MR tasks.
+ * + *HCatalog developers should enable optional functionality by checking properties + * from {@link #getConf()}. Since users are not obligated to set a configuration, optional + * functionality must provide a sensible default.
*/ -public class HCatContext { - - private static final HCatContext hCatContext = new HCatContext(); +@InterfaceAudience.Public +@InterfaceStability.Evolving +public enum HCatContext { + INSTANCE; private Configuration conf = null; - private HCatContext() { - } - /** - * Setup the HCatContext as a reference to the given configuration. Keys - * exclusive to an existing config are set in the new conf. + * Use the given configuration for optional behavior. Keys exclusive to an existing config + * are set in the new conf. The job conf must be used to ensure properties are passed to + * backend MR tasks. */ - public static synchronized HCatContext setupHCatContext(Configuration newConf) { - Preconditions.checkNotNull(newConf, "HCatContext must not have a null conf."); + public synchronized HCatContext setConf(Configuration newConf) { + Preconditions.checkNotNull(newConf, "Required parameter 'newConf' must not be null."); - if (hCatContext.conf == null) { - hCatContext.conf = newConf; - return hCatContext; + if (conf == null) { + conf = newConf; + return this; } - if (hCatContext.conf != newConf) { - for (Map.Entry