pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject svn commit: r1605661 - in /pig/trunk: CHANGES.txt src/org/apache/pig/Main.java test/org/apache/pig/test/TestParamSubPreproc.java
Date Thu, 26 Jun 2014 04:22:07 GMT
Author: daijy
Date: Thu Jun 26 04:22:07 2014
New Revision: 1605661

URL: http://svn.apache.org/r1605661
Log:
PIG-2122: Parameter Substitution doesn't work in the Grunt shell

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/Main.java
    pig/trunk/test/org/apache/pig/test/TestParamSubPreproc.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1605661&r1=1605660&r2=1605661&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Thu Jun 26 04:22:07 2014
@@ -24,6 +24,8 @@ INCOMPATIBLE CHANGES
  
 IMPROVEMENTS
 
+PIG-2122: Parameter Substitution doesn't work in the Grunt shell (daijy)
+
 PIG-4031: Provide Counter aggregation for Tez (daijy)
 
 PIG-4028: add a flag to control the ivy resolve/retrieve output (gkesavan via daijy)

Modified: pig/trunk/src/org/apache/pig/Main.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/Main.java?rev=1605661&r1=1605660&r2=1605661&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/Main.java (original)
+++ pig/trunk/src/org/apache/pig/Main.java Thu Jun 26 04:22:07 2014
@@ -28,6 +28,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
+import java.io.Reader;
 import java.io.StringReader;
 import java.text.ParseException;
 import java.util.AbstractList;
@@ -536,7 +537,7 @@ public class Main {
                 String historyFile = System.getProperty("user.home") + File.separator  +
HISTORYFILE;
                 reader.setHistory(new History(new File(historyFile)));
                 ConsoleReaderInputStream inputStream = new ConsoleReaderInputStream(reader);
-                grunt = new Grunt(new BufferedReader(new InputStreamReader(inputStream)),
pigContext);
+                grunt = new Grunt(new BufferedReaderWithParamSub(new InputStreamReader(inputStream),
pigContext), pigContext);
                 grunt.setConsoleReader(reader);
                 gruntCalled = true;
                 grunt.run();
@@ -1039,5 +1040,21 @@ public class Main {
                 : (failCount > 0) ? ReturnCode.PARTIAL_FAILURE
                         : ReturnCode.SUCCESS;
     }
+    
+    static class BufferedReaderWithParamSub extends BufferedReader {
+        PigContext pc;
+        BufferedReaderWithParamSub(Reader in, PigContext pigContext) {
+            super(in);
+            pc = pigContext;
+        }
+
+        @Override
+        public String readLine() throws IOException {
+            String line = super.readLine();
+            String paramSubLine = pc.doParamSubstitution(new BufferedReader(new StringReader(line)));
+            return paramSubLine;
+        }
+        
+    }
 
 }

Modified: pig/trunk/test/org/apache/pig/test/TestParamSubPreproc.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestParamSubPreproc.java?rev=1605661&r1=1605660&r2=1605661&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestParamSubPreproc.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestParamSubPreproc.java Thu Jun 26 04:22:07 2014
@@ -28,6 +28,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
+import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -1344,6 +1345,27 @@ public class TestParamSubPreproc {
         inExpected.close();
         inResult.close();
     }
+
+    @Test
+    public void testGruntWithParamSub() throws Exception{
+        log.info("Starting test testGruntWithParamSub()");
+        File inputFile = Util.createFile(new String[]{"daniel\t10","jenny\t20"});
+        File outputFile = File.createTempFile("tmp", "");
+        outputFile.delete();
+        String command = "a = load '" + Util.encodeEscape(inputFile.toString()) + "' as ($param1:chararray,
$param2:int);\n"
+                + "store a into '" + outputFile.toString() + "';\n"
+                + "quit\n";
+        System.setIn(new ByteArrayInputStream(command.getBytes()));
+        org.apache.pig.PigRunner.run(new String[] {"-x", "local", "-p", "param1=name", "-p",
"param2=age"}, null);
+        File[] partFiles = outputFile.listFiles(new FilenameFilter() {
+            public boolean accept(File dir, String name) { 
+            return name.startsWith("part");
+        }
+        });
+        String resultContent = Util.readFile(partFiles[0]);
+        assertEquals(resultContent, "daniel\t10\njenny\t20\n");
+    }
+
     @SuppressWarnings("resource")
     private BufferedReader WithConditionalReplacement(String filename, String orig, String
dest, boolean replace) throws IOException {
         BufferedReader pigOrigIStream = new BufferedReader(new FileReader(filename));



Mime
View raw message