Author: daijy
Date: Fri May 14 01:13:14 2010
New Revision: 944073

URL: http://svn.apache.org/viewvc?rev=944073&view=rev
Log:
PIG-1381: Need a way for Pig to take an alternative property file

Added:
    hadoop/pig/trunk/conf/pig-default.properties   (contents, props changed)
      - copied, changed from r944068, hadoop/pig/trunk/conf/pig.properties
Removed:
    hadoop/pig/trunk/conf/pig.properties
Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/build.xml
    hadoop/pig/trunk/src/org/apache/pig/impl/util/PropertiesUtil.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestPigServer.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=944073&r1=944072&r2=944073&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Fri May 14 01:13:14 2010
@@ -116,7 +116,7 @@ in the path and does not consider JAVA_H
 
 PIG-1352: piggybank UPPER udf throws exception if argument is null
 
-Release 0.7.0 - Unreleased
+Release 0.7.0
 
 INCOMPATIBLE CHANGES
 
@@ -166,6 +166,8 @@ manner (rding via pradeepkth)
 
 IMPROVEMENTS
 
+PIG-1381: Need a way for Pig to take an alternative property file (daijy)
+
 PIG-1330: Move pruned schema tracking logic from LoadFunc to core code (daijy)
 
 PIG-1320: more documentation updates for Pig 0.7.0 (chandec via olgan)

Modified: hadoop/pig/trunk/build.xml
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/build.xml?rev=944073&r1=944072&r2=944073&view=diff
==============================================================================
--- hadoop/pig/trunk/build.xml (original)
+++ hadoop/pig/trunk/build.xml Fri May 14 01:13:14 2010
@@ -643,6 +643,7 @@
             <fileset dir="${build.docs}" />
         </copy>
 
+               <copy todir="${dist.dir}/conf" 
file="conf/pig-default.properties"/>
                <copy todir="${dist.dir}/conf" file="conf/pig.properties"/>
 
         <copy todir="${dist.dir}/src" includeEmptyDirs="true">

Copied: hadoop/pig/trunk/conf/pig-default.properties (from r944068, 
hadoop/pig/trunk/conf/pig.properties)
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/conf/pig-default.properties?p2=hadoop/pig/trunk/conf/pig-default.properties&p1=hadoop/pig/trunk/conf/pig.properties&r1=944068&r2=944073&rev=944073&view=diff
==============================================================================
--- hadoop/pig/trunk/conf/pig.properties (original)
+++ hadoop/pig/trunk/conf/pig-default.properties Fri May 14 01:13:14 2010
@@ -1,39 +1,17 @@
-# Pig configuration file. All values can be overwritten by command line 
arguments.
+# Pig default configuration file. All values can be overwritten by 
pig.properties and command line arguments.
 # see bin/pig -help
 
-# log4jconf log4j configuration file
-# log4jconf=./conf/log4j.properties
-
 # brief logging (no timestamps)
 brief=false
 
-# clustername, name of the hadoop jobtracker. If no port is defined port 50020 
will be used. 
-#cluster
-
 #debug level, INFO is default
 debug=INFO
 
-# a file that contains pig script
-#file=
-
-# load jarfile, colon separated
-#jar=
-
 #verbose print all log messages to screen (default to print only INFO and 
above to screen)
 verbose=false
 
 #exectype local|mapreduce, mapreduce is default
 exectype=mapreduce
-# hod realted properties
-#ssh.gateway
-#hod.expect.root
-#hod.expect.uselatest
-#hod.command
-#hod.config.dir
-#hod.param
-
-#pig.logfile=
-
 
 #Do not spill temp files smaller than this size (bytes)
 pig.spill.size.threshold=5000000

Propchange: hadoop/pig/trunk/conf/pig-default.properties
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Fri May 14 01:13:14 2010
@@ -0,0 +1 @@
+/hadoop/pig/branches/multiquery/conf/pig.properties:741727-770826

Modified: hadoop/pig/trunk/src/org/apache/pig/impl/util/PropertiesUtil.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/impl/util/PropertiesUtil.java?rev=944073&r1=944072&r2=944073&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/impl/util/PropertiesUtil.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/impl/util/PropertiesUtil.java Fri May 
14 01:13:14 2010
@@ -31,16 +31,33 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 public class PropertiesUtil {
+    private static final String DEFAULT_PROPERTIES_FILE = 
"/pig-default.properties";
     private static final String PROPERTIES_FILE = "/pig.properties";
     private final static Log log = LogFactory.getLog(PropertiesUtil.class);
 
     public static void loadPropertiesFromFile(Properties properties) {
         InputStream inputStream = null;
         BufferedInputStream bis = null;
+        Class<PropertiesUtil> clazz = PropertiesUtil.class;
         try {
-            Class<PropertiesUtil> clazz = PropertiesUtil.class;
             inputStream = clazz
-                    .getResourceAsStream(PROPERTIES_FILE);
+                    .getResourceAsStream(DEFAULT_PROPERTIES_FILE);
+            if (inputStream == null) {
+                String msg = "no pig-default.properties configuration file 
available in the classpath";
+                log.debug(msg);
+            } else {
+                properties.load(inputStream);
+            }
+        } catch (Exception e) {
+            log.error("unable to parse pig-default.properties :", e);
+        } finally {
+            if (inputStream != null) try {inputStream.close();} catch 
(Exception e) {}
+        }
+        
+        try {
+            inputStream = null;
+            inputStream = clazz
+                .getResourceAsStream(PROPERTIES_FILE);
             if (inputStream == null) {
                 String msg = "no pig.properties configuration file available 
in the classpath";
                 log.debug(msg);

Modified: hadoop/pig/trunk/test/org/apache/pig/test/TestPigServer.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/TestPigServer.java?rev=944073&r1=944072&r2=944073&view=diff
==============================================================================
--- hadoop/pig/trunk/test/org/apache/pig/test/TestPigServer.java (original)
+++ hadoop/pig/trunk/test/org/apache/pig/test/TestPigServer.java Fri May 14 
01:13:14 2010
@@ -25,11 +25,13 @@ import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintStream;
+import java.io.PrintWriter;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -38,6 +40,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 import junit.framework.TestCase;
 
@@ -45,6 +48,7 @@ import org.apache.pig.ExecType;
 import org.apache.pig.PigServer;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.impl.util.PropertiesUtil;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -617,4 +621,30 @@ public class TestPigServer extends TestC
             index++;
         }
     }
+    
+    @Test
+    public void testPigProperties() throws Throwable {
+        File defaultPropertyFile = new File("pig-default.properties");
+        File propertyFile = new File("pig.properties");
+        
+        Properties properties = PropertiesUtil.loadPropertiesFromFile();
+        assertTrue(properties.getProperty("test123")==null);
+
+        PrintWriter out = new PrintWriter(new FileWriter(defaultPropertyFile));
+        out.println("test123=defaultproperties");
+        out.close();
+        
+        properties = PropertiesUtil.loadPropertiesFromFile();
+        
assertTrue(properties.getProperty("test123").equals("defaultproperties"));
+
+        out = new PrintWriter(new FileWriter(propertyFile));
+        out.println("test123=properties");
+        out.close();
+
+        properties = PropertiesUtil.loadPropertiesFromFile();
+        assertTrue(properties.getProperty("test123").equals("properties"));
+        
+        defaultPropertyFile.delete();
+        propertyFile.delete();
+    }
 }


Reply via email to