You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ch...@apache.org on 2013/11/12 01:55:04 UTC

svn commit: r1540908 - in /pig/trunk: CHANGES.txt src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java test/org/apache/pig/test/TestJobControlCompiler.java

Author: cheolsoo
Date: Tue Nov 12 00:55:03 2013
New Revision: 1540908

URL: http://svn.apache.org/r1540908
Log:
PIG-3563: support adding archives to the distributed cache (jdonofrio via cheolsoo)

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java
    pig/trunk/test/org/apache/pig/test/TestJobControlCompiler.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1540908&r1=1540907&r2=1540908&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Tue Nov 12 00:55:03 2013
@@ -28,6 +28,8 @@ PIG-3419: Pluggable Execution Engine (ac
 
 IMPROVEMENTS
 
+PIG-3563: support adding archives to the distributed cache (jdonofrio via cheolsoo)
+
 PIG-3388: No support for Regex for row filter in org.apache.pig.backend.hadoop.hbase.HBaseStorage (lbendig via cheolsoo)
 
 PIG-3522: Remove shock from pig (daijy)

Modified: pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java?rev=1540908&r1=1540907&r2=1540908&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java (original)
+++ pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java Tue Nov 12 00:55:03 2013
@@ -33,6 +33,8 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -137,6 +139,9 @@ public class JobControlCompiler{
     Configuration conf;
     PigContext pigContext;
 
+    private static final Matcher DISTRIBUTED_CACHE_ARCHIVE_MATCHER = Pattern
+            .compile("\\.(zip|tgz|tar\\.gz|tar)$").matcher("");
+
     private static final Log log = LogFactory.getLog(JobControlCompiler.class);
 
     public static final String LOG_DIR = "_logs";
@@ -954,12 +959,11 @@ public class JobControlCompiler{
 
     public static class PigSecondaryKeyGroupComparator extends WritableComparator {
         public PigSecondaryKeyGroupComparator() {
-//            super(TupleFactory.getInstance().tupleClass(), true);
             super(NullableTuple.class, true);
         }
 
         @SuppressWarnings("unchecked")
-		@Override
+        @Override
         public int compare(WritableComparable a, WritableComparable b)
         {
             PigNullableWritable wa = (PigNullableWritable)a;
@@ -1362,6 +1366,14 @@ public class JobControlCompiler{
         }
     }
 
+    private static void addToDistributedCache(URI uri, Configuration conf) {
+        if (DISTRIBUTED_CACHE_ARCHIVE_MATCHER.reset(uri.toString()).find()) {
+            DistributedCache.addCacheArchive(uri, conf);
+        } else {
+            DistributedCache.addCacheFile(uri, conf);
+        }
+    }
+
     private static void setupDistributedCache(PigContext pigContext,
             Configuration conf, String[] paths, boolean shipToCluster) throws IOException {
         // Turn on the symlink feature
@@ -1405,9 +1417,9 @@ public class JobControlCompiler{
                         "File doesn't exist: " + dst;
                         throw new ExecException(msg, errCode, errSrc);
                     }
-                    DistributedCache.addCacheFile(dstURI, conf);
+                    addToDistributedCache(dstURI, conf);
                 } else {
-                    DistributedCache.addCacheFile(srcURI, conf);
+                    addToDistributedCache(srcURI, conf);
                 }
             }
         }

Modified: pig/trunk/test/org/apache/pig/test/TestJobControlCompiler.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestJobControlCompiler.java?rev=1540908&r1=1540907&r2=1540908&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestJobControlCompiler.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestJobControlCompiler.java Tue Nov 12 00:55:03 2013
@@ -25,11 +25,14 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.RandomAccessFile;
+import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Properties;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
@@ -42,6 +45,7 @@ import javax.tools.JavaFileObject;
 import javax.tools.StandardJavaFileManager;
 import javax.tools.ToolProvider;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.filecache.DistributedCache;
 import org.apache.hadoop.fs.Path;
@@ -131,12 +135,61 @@ public class TestJobControlCompiler {
         jarContainsFileNamed(new File(fileClassPaths[0].toUri().getPath()), testUDFFileName));
 
     // verifying the job jar does not contain the UDF
-//    jobConf.writeXml(System.out);
     File submitJarFile = new File(jobConf.get("mapred.jar"));
     Assert.assertFalse("the mapred.jar should *not* contain the testUDF", jarContainsFileNamed(submitJarFile, testUDFFileName));
 
   }
 
+    private static List<File> createFiles(String... extensions)
+            throws IOException {
+        List<File> files = new ArrayList<File>();
+        for (String extension : extensions) {
+            File file = File.createTempFile("file", extension);
+            file.deleteOnExit();
+            files.add(file);
+        }
+        return files;
+    }
+
+    private static void assertFilesInDistributedCache(URI[] uris, int size,
+            String... extensions) {
+        Assert.assertEquals(size, uris.length);
+        for (int i = 0; i < uris.length; i++) {
+            Assert.assertTrue(uris[i].toString().endsWith(extensions[i]));
+        }
+    }
+
+    @Test
+    public void testAddArchiveToDistributedCache() throws IOException {
+        final File textFile = File.createTempFile("file", ".txt");
+        textFile.deleteOnExit();
+
+        final List<File> zipArchives = createFiles(".zip");
+        zipArchives.add(textFile);
+        final List<File> tarArchives = createFiles(".tgz", ".tar.gz", ".tar");
+
+        final PigContext pigContext = new PigContext();
+        pigContext.connect();
+        pigContext.getProperties().put("pig.streaming.ship.files",
+                StringUtils.join(zipArchives, ","));
+        pigContext.getProperties().put("pig.streaming.cache.files",
+                StringUtils.join(tarArchives, ","));
+        final JobControlCompiler jobControlCompiler = new JobControlCompiler(
+                pigContext, CONF);
+
+        final MROperPlan plan = new MROperPlan();
+        plan.add(new MapReduceOper(new OperatorKey()));
+
+        final JobControl jobControl = jobControlCompiler.compile(plan, "test");
+        final JobConf jobConf = jobControl.getWaitingJobs().get(0).getJobConf();
+        
+        assertFilesInDistributedCache(DistributedCache.getCacheFiles(jobConf),
+                1, ".txt");
+        assertFilesInDistributedCache(
+                DistributedCache.getCacheArchives(jobConf), 4, ".zip", ".tgz",
+                ".tar.gz", ".tar");
+    }
+
     @Test
     public void testEstimateNumberOfReducers() throws Exception {
         Assert.assertEquals(2, JobControlCompiler.estimateNumberOfReducers(
@@ -160,6 +213,7 @@ public class TestJobControlCompiler {
         file.deleteOnExit();
         RandomAccessFile f = new RandomAccessFile(file, "rw");
         f.setLength(size);
+        f.close();
 
         loadFunc.setLocation(file.getAbsolutePath(), new org.apache.hadoop.mapreduce.Job(CONF));
         FuncSpec funcSpec = new FuncSpec(loadFunc.getClass().getCanonicalName());