Author: rding
Date: Tue Jul 27 16:42:45 2010
New Revision: 979768

URL: http://svn.apache.org/viewvc?rev=979768&view=rev
Log:
PIG-348:  -j command line option doesn't work

Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/src/org/apache/pig/Main.java
    hadoop/pig/trunk/src/org/apache/pig/PigRunner.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestPigRunner.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=979768&r1=979767&r2=979768&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Tue Jul 27 16:42:45 2010
@@ -106,6 +106,8 @@ PIG-1309: Map-side Cogroup (ashutoshc)
 
 BUG FIXES
 
+PIG-348:  -j command line option doesn't work (rding)
+
 PIG-1487: Replace "bz" with ".bz" in all the LoadFunc
 
 PIG-1489: Pig MapReduceLauncher does not use jars in register statement

Modified: hadoop/pig/trunk/src/org/apache/pig/Main.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/Main.java?rev=979768&r1=979767&r2=979768&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/Main.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/Main.java Tue Jul 27 16:42:45 2010
@@ -46,12 +46,14 @@ import jline.History;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.util.GenericOptionsParser;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
 import org.apache.pig.PigRunner.ReturnCode;
+import org.apache.pig.backend.hadoop.datastorage.ConfigurationUtil;
 import org.apache.pig.classification.InterfaceAudience;
 import org.apache.pig.classification.InterfaceStability;
 import org.apache.pig.ExecType;
@@ -83,7 +85,6 @@ public class Main {
     private static final String LOG4J_CONF = "log4jconf";
     private static final String BRIEF = "brief";
     private static final String DEBUG = "debug";
-    private static final String JAR = "jar";
     private static final String VERBOSE = "verbose";
     
     private enum ExecMode {STRING, FILE, SHELL, UNKNOWN}    
@@ -99,16 +100,20 @@ public class Main {
  * @throws IOException
  */
 public static void main(String args[]) {
-    GenericOptionsParser parser = new GenericOptionsParser(args);
-    String[] pigArgs = parser.getRemainingArgs();
-    System.exit(run(pigArgs, null));
+    System.exit(run(args, null));
 }
 
 static int run(String args[], PigProgressNotificationListener listener) {
     int rc = 1;
-    Properties properties = new Properties();
+    
+    GenericOptionsParser parser = new GenericOptionsParser(args);
+    Configuration conf = parser.getConfiguration();
+    Properties properties = ConfigurationUtil.toProperties(conf);
+    
     PropertiesUtil.loadDefaultProperties(properties);
     
+    String[] pigArgs = parser.getRemainingArgs();
+    
     boolean verbose = false;
     boolean gruntCalled = false;
     String logFileName = null;
@@ -124,7 +129,7 @@ static int run(String args[], PigProgres
         ArrayList<String> paramFiles = new ArrayList<String>();
         HashSet<String> optimizerRules = new HashSet<String>();
 
-        CmdLineParser opts = new CmdLineParser(args);
+        CmdLineParser opts = new CmdLineParser(pigArgs);
         opts.registerOpt('4', "log4jconf", 
CmdLineParser.ValueExpected.REQUIRED);
         opts.registerOpt('b', "brief", 
CmdLineParser.ValueExpected.NOT_ACCEPTED);
         opts.registerOpt('c', "check", 
CmdLineParser.ValueExpected.NOT_ACCEPTED);
@@ -132,8 +137,7 @@ static int run(String args[], PigProgres
         opts.registerOpt('e', "execute", 
CmdLineParser.ValueExpected.NOT_ACCEPTED);
         opts.registerOpt('f', "file", CmdLineParser.ValueExpected.REQUIRED);
         opts.registerOpt('h', "help", 
CmdLineParser.ValueExpected.NOT_ACCEPTED);
-        opts.registerOpt('i', "version", CmdLineParser.ValueExpected.OPTIONAL);
-        opts.registerOpt('j', "jar", CmdLineParser.ValueExpected.REQUIRED);
+        opts.registerOpt('i', "version", 
CmdLineParser.ValueExpected.OPTIONAL);        
         opts.registerOpt('l', "logfile", CmdLineParser.ValueExpected.REQUIRED);
         opts.registerOpt('m', "param_file", 
CmdLineParser.ValueExpected.OPTIONAL);
         opts.registerOpt('p', "param", CmdLineParser.ValueExpected.OPTIONAL);
@@ -213,13 +217,6 @@ static int run(String args[], PigProgres
                System.out.println(getVersionString());
                return ReturnCode.SUCCESS;
 
-            case 'j': 
-                String jarsString = opts.getValStr();
-                if(jarsString != null){
-                    properties.setProperty(JAR, jarsString);
-                }
-                break;
-
             case 'l':
                 //call to method that validates the path to the log file 
                 //and sets up the file to store the client side log file       
         
@@ -624,7 +621,6 @@ public static void usage()
         System.out.println("    -f, -file path to the script to execute");
         System.out.println("    -h, -help display this message");
         System.out.println("    -i, -version display version information");
-        System.out.println("    -j, -jar jarfile load jarfile"); 
         System.out.println("    -l, -logfile path to client side log file; 
current working directory is default");
         System.out.println("    -m, -param_file path to the parameter file");
         System.out.println("    -p, -param key value pair of the form 
param=val");

Modified: hadoop/pig/trunk/src/org/apache/pig/PigRunner.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/PigRunner.java?rev=979768&r1=979767&r2=979768&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/PigRunner.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/PigRunner.java Tue Jul 27 16:42:45 2010
@@ -17,7 +17,6 @@
  */
 package org.apache.pig;
 
-import org.apache.hadoop.util.GenericOptionsParser;
 import org.apache.pig.classification.InterfaceAudience;
 import org.apache.pig.classification.InterfaceStability;
 import org.apache.pig.tools.pigstats.PigProgressNotificationListener;
@@ -47,9 +46,7 @@ public abstract class PigRunner {
     }
     
     public static PigStats run(String[] args, PigProgressNotificationListener 
listener) {
-        GenericOptionsParser parser = new GenericOptionsParser(args);
-        String[] pigArgs = parser.getRemainingArgs();
-        return PigStatsUtil.getPigStats(Main.run(pigArgs, listener));
+        return PigStatsUtil.getPigStats(Main.run(args, listener));
     }
     
 }

Modified: hadoop/pig/trunk/test/org/apache/pig/test/TestPigRunner.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/TestPigRunner.java?rev=979768&r1=979767&r2=979768&view=diff
==============================================================================
--- hadoop/pig/trunk/test/org/apache/pig/test/TestPigRunner.java (original)
+++ hadoop/pig/trunk/test/org/apache/pig/test/TestPigRunner.java Tue Jul 27 
16:42:45 2010
@@ -28,6 +28,8 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
 
+import junit.framework.Assert;
+
 import org.apache.pig.ExecType;
 import org.apache.pig.PigRunner;
 import org.apache.pig.PigRunner.ReturnCode;
@@ -328,6 +330,29 @@ public class TestPigRunner {
     }
     
     @Test
+    public void testRegisterExternalJar() throws Exception {
+        String[] args = { "-Dpig.additional.jars=pig-withouthadoop.jar",
+                "-Dmapred.job.queue.name=default",
+                "-e", "A = load '" + INPUT_FILE + "';store A into '" + 
OUTPUT_FILE + "';\n" };
+        PigStats stats = PigRunner.run(args, new TestNotificationListener());  
      
+
+        Util.deleteFile(cluster, OUTPUT_FILE);
+        
+        java.lang.reflect.Method getPigContext = stats.getClass()
+                .getDeclaredMethod("getPigContext");
+
+        getPigContext.setAccessible(true);
+
+        PigContext ctx = (PigContext) getPigContext.invoke(stats);
+
+        Assert.assertNotNull(ctx);
+
+        
assertTrue(ctx.extraJars.contains(ClassLoader.getSystemResource("pig-withouthadoop.jar")));
+        assertEquals("default", 
ctx.getProperties().getProperty("mapred.job.queue.name"));
+       
+    }
+
+    @Test
     public void classLoaderTest() throws Exception {
         PrintWriter w = new PrintWriter(new FileWriter(PIG_FILE));
         w.println("register test/org/apache/pig/test/data/pigtestloader.jar");


Reply via email to