incubator-hcatalog-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tra...@apache.org
Subject svn commit: r1412314 - in /incubator/hcatalog/trunk: ./ core/src/main/java/org/apache/hcatalog/common/ core/src/main/java/org/apache/hcatalog/data/ core/src/main/java/org/apache/hcatalog/data/schema/ hcatalog-pig-adapter/src/main/java/org/apache/hcatal...
Date Wed, 21 Nov 2012 21:41:32 GMT
Author: travis
Date: Wed Nov 21 21:41:31 2012
New Revision: 1412314

URL: http://svn.apache.org/viewvc?rev=1412314&view=rev
Log:
HCATALOG-531 HCatContext should be an enum

Modified:
    incubator/hcatalog/trunk/CHANGES.txt
    incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/common/HCatContext.java
    incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/data/HCatRecordSerDe.java
    incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/data/schema/HCatSchemaUtils.java
    incubator/hcatalog/trunk/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatLoader.java
    incubator/hcatalog/trunk/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatStorer.java

Modified: incubator/hcatalog/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/CHANGES.txt?rev=1412314&r1=1412313&r2=1412314&view=diff
==============================================================================
--- incubator/hcatalog/trunk/CHANGES.txt (original)
+++ incubator/hcatalog/trunk/CHANGES.txt Wed Nov 21 21:41:31 2012
@@ -44,6 +44,8 @@ Trunk (unreleased changes)
   HCAT-427 Document storage-based authorization (lefty via gates)
 
   IMPROVEMENTS
+  HCAT-531 HCatContext should be an enum (traviscrawford)
+
   HCAT-530 HCatBaseLoader.getSizeInBytes NPE when partition path is missing (traviscrawford)
 
   HCAT-518 Refactor hcatalog-core as subproject (traviscrawford and toffer)

Modified: incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/common/HCatContext.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/common/HCatContext.java?rev=1412314&r1=1412313&r2=1412314&view=diff
==============================================================================
--- incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/common/HCatContext.java
(original)
+++ incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/common/HCatContext.java
Wed Nov 21 21:41:31 2012
@@ -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.
+ *
+ * <p>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.</p>
+ *
+ * <p>HCatalog <em>users</em> (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.</p>
+ *
+ * <p>HCatalog <em>developers</em> 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.</p>
  */
-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<String, String> entry : hCatContext.conf) {
+        if (conf != newConf) {
+            for (Map.Entry<String, String> entry : conf) {
                 if (newConf.get(entry.getKey()) == null) {
                     newConf.set(entry.getKey(), entry.getValue());
                 }
             }
-            hCatContext.conf = newConf;
+            conf = newConf;
         }
-        return hCatContext;
-    }
-
-    public static HCatContext getInstance() {
-        return hCatContext;
+        return this;
     }
 
+    /**
+     * Get the configuration, if there is one. Users are not required to setup HCatContext
+     * unless they wish to override default behavior, so the configuration may not be present.
+     *
+     * @return an Optional that might contain a Configuration
+     */
     public Optional<Configuration> getConf() {
         return Optional.fromNullable(conf);
     }

Modified: incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/data/HCatRecordSerDe.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/data/HCatRecordSerDe.java?rev=1412314&r1=1412313&r2=1412314&view=diff
==============================================================================
--- incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/data/HCatRecordSerDe.java
(original)
+++ incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/data/HCatRecordSerDe.java
Wed Nov 21 21:41:31 2012
@@ -265,8 +265,8 @@ public class HCatRecordSerDe implements 
     private static Object serializePrimitiveField(Object field,
             ObjectInspector fieldObjectInspector) {
 
-        if (field != null && HCatContext.getInstance().getConf().isPresent()) {
-            Configuration conf = HCatContext.getInstance().getConf().get();
+        if (field != null && HCatContext.INSTANCE.getConf().isPresent()) {
+            Configuration conf = HCatContext.INSTANCE.getConf().get();
 
             if (field instanceof Boolean &&
                 conf.getBoolean(

Modified: incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/data/schema/HCatSchemaUtils.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/data/schema/HCatSchemaUtils.java?rev=1412314&r1=1412313&r2=1412314&view=diff
==============================================================================
--- incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/data/schema/HCatSchemaUtils.java
(original)
+++ incubator/hcatalog/trunk/core/src/main/java/org/apache/hcatalog/data/schema/HCatSchemaUtils.java
Wed Nov 21 21:41:31 2012
@@ -139,14 +139,14 @@ public class HCatSchemaUtils {
     private static Type getPrimitiveHType(TypeInfo basePrimitiveTypeInfo) {
         switch (((PrimitiveTypeInfo) basePrimitiveTypeInfo).getPrimitiveCategory()) {
         case BOOLEAN:
-            return (HCatContext.getInstance().getConf().isPresent() &&
-                HCatContext.getInstance().getConf().get().getBoolean(
+            return (HCatContext.INSTANCE.getConf().isPresent() &&
+                HCatContext.INSTANCE.getConf().get().getBoolean(
                     HCatConstants.HCAT_DATA_CONVERT_BOOLEAN_TO_INTEGER,
                     HCatConstants.HCAT_DATA_CONVERT_BOOLEAN_TO_INTEGER_DEFAULT)) ?
                 Type.INT : Type.BOOLEAN;
         case BYTE:
-            return (HCatContext.getInstance().getConf().isPresent() &&
-                HCatContext.getInstance().getConf().get().getBoolean(
+            return (HCatContext.INSTANCE.getConf().isPresent() &&
+                HCatContext.INSTANCE.getConf().get().getBoolean(
                     HCatConstants.HCAT_DATA_TINY_SMALL_INT_PROMOTION,
                     HCatConstants.HCAT_DATA_TINY_SMALL_INT_PROMOTION_DEFAULT)) ?
                 Type.INT : Type.TINYINT;
@@ -159,8 +159,8 @@ public class HCatSchemaUtils {
         case LONG:
             return Type.BIGINT;
         case SHORT:
-            return (HCatContext.getInstance().getConf().isPresent() &&
-                HCatContext.getInstance().getConf().get().getBoolean(
+            return (HCatContext.INSTANCE.getConf().isPresent() &&
+                HCatContext.INSTANCE.getConf().get().getBoolean(
                     HCatConstants.HCAT_DATA_TINY_SMALL_INT_PROMOTION,
                     HCatConstants.HCAT_DATA_TINY_SMALL_INT_PROMOTION_DEFAULT)) ?
                 Type.INT : Type.SMALLINT;

Modified: incubator/hcatalog/trunk/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatLoader.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatLoader.java?rev=1412314&r1=1412313&r2=1412314&view=diff
==============================================================================
--- incubator/hcatalog/trunk/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatLoader.java
(original)
+++ incubator/hcatalog/trunk/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatLoader.java
Wed Nov 21 21:41:31 2012
@@ -82,7 +82,7 @@ public class HCatLoader extends HCatBase
 
     @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 HCatBase
 
     @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,

Modified: incubator/hcatalog/trunk/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatStorer.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatStorer.java?rev=1412314&r1=1412313&r2=1412314&view=diff
==============================================================================
--- incubator/hcatalog/trunk/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatStorer.java
(original)
+++ incubator/hcatalog/trunk/hcatalog-pig-adapter/src/main/java/org/apache/hcatalog/pig/HCatStorer.java
Wed Nov 21 21:41:31 2012
@@ -77,7 +77,7 @@ public class HCatStorer extends HCatBase
 
     @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();



Mime
View raw message