hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1525126 - /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java
Date Fri, 20 Sep 2013 20:20:03 GMT
Author: brock
Date: Fri Sep 20 20:20:02 2013
New Revision: 1525126

URL: http://svn.apache.org/r1525126
Log:
HIVE-5327 - Potential leak and cleanup in utilities.java (Edward Capriolo via Brock Noland)

Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java?rev=1525126&r1=1525125&r2=1525126&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java Fri Sep 20 20:20:02
2013
@@ -195,6 +195,8 @@ public final class Utilities {
   public static String HADOOP_LOCAL_FS = "file:///";
   public static String MAP_PLAN_NAME = "map.xml";
   public static String REDUCE_PLAN_NAME = "reduce.xml";
+  public static final String MAPRED_MAPPER_CLASS = "mapred.mapper.class";
+  public static final String MAPRED_REDUCER_CLASS = "mapred.reducer.class";
 
   /**
    * ReduceField:
@@ -269,9 +271,18 @@ public final class Utilities {
     return (ReduceWork) getBaseWork(conf, REDUCE_PLAN_NAME);
   }
 
+  /**
+   * Returns the Map or Reduce plan
+   * Side effect: the BaseWork returned is also placed in the gWorkMap
+   * @param conf
+   * @param name
+   * @return BaseWork based on the name supplied will return null if name is null
+   * @throws RuntimeException if the configuration files are not proper or if plan can not
be loaded
+   */
   private static BaseWork getBaseWork(Configuration conf, String name) {
     BaseWork gWork = null;
     Path path = null;
+    InputStream in = null;
     try {
       path = getPlanPath(conf, name);
       assert path != null;
@@ -283,24 +294,26 @@ public final class Utilities {
         } else {
           localPath = new Path(name);
         }
-        InputStream in = new FileInputStream(localPath.toUri().getPath());
+        in = new FileInputStream(localPath.toUri().getPath());
         if(MAP_PLAN_NAME.equals(name)){
-          if (ExecMapper.class.getName().equals(conf.get("mapred.mapper.class"))){
+          if (ExecMapper.class.getName().equals(conf.get(MAPRED_MAPPER_CLASS))){
             gWork = deserializePlan(in, MapWork.class, conf);
-          } else if(RCFileMergeMapper.class.getName().equals(conf.get("mapred.mapper.class")))
{
+          } else if(RCFileMergeMapper.class.getName().equals(conf.get(MAPRED_MAPPER_CLASS)))
{
             gWork = deserializePlan(in, MergeWork.class, conf);
-          } else if(ColumnTruncateMapper.class.getName().equals(conf.get("mapred.mapper.class")))
{
+          } else if(ColumnTruncateMapper.class.getName().equals(conf.get(MAPRED_MAPPER_CLASS)))
{
             gWork = deserializePlan(in, ColumnTruncateWork.class, conf);
-          } else if(PartialScanMapper.class.getName().equals(conf.get("mapred.mapper.class")))
{
+          } else if(PartialScanMapper.class.getName().equals(conf.get(MAPRED_MAPPER_CLASS)))
{
             gWork = deserializePlan(in, PartialScanWork.class,conf);
           } else {
-            assert false;
+            throw new RuntimeException("unable to determine work from configuration ."
+                + MAPRED_MAPPER_CLASS + " was "+ conf.get(MAPRED_MAPPER_CLASS)) ;
           }
-        } else {
-          if(ExecReducer.class.getName().equals(conf.get("mapred.reducer.class"))) {
+        } else if (REDUCE_PLAN_NAME.equals(name)) {
+          if(ExecReducer.class.getName().equals(conf.get(MAPRED_REDUCER_CLASS))) {
             gWork = deserializePlan(in, ReduceWork.class, conf);
           } else {
-            assert false;
+            throw new RuntimeException("unable to determine work from configuration ."
+                + MAPRED_REDUCER_CLASS +" was "+ conf.get(MAPRED_REDUCER_CLASS)) ;
           }
         }
         gWorkMap.put(path, gWork);
@@ -311,9 +324,14 @@ public final class Utilities {
       LOG.debug("No plan file found: "+path);
       return null;
     } catch (Exception e) {
-      e.printStackTrace();
       LOG.error("Failed to load plan: "+path, e);
       throw new RuntimeException(e);
+    } finally {
+      if (in != null) {
+        try {
+          in.close();
+        } catch (IOException cantBlameMeForTrying) { }
+      }
     }
   }
 



Mime
View raw message