You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by da...@apache.org on 2012/04/02 09:07:58 UTC
svn commit: r1308253 - in /pig/trunk: CHANGES.txt
src/org/apache/pig/PigServer.java test/org/apache/pig/test/TestPigServer.java
Author: daijy
Date: Mon Apr 2 07:07:57 2012
New Revision: 1308253
URL: http://svn.apache.org/viewvc?rev=1308253&view=rev
Log:
PIG-2623: Support S3 paths for registering UDFs
Modified:
pig/trunk/CHANGES.txt
pig/trunk/src/org/apache/pig/PigServer.java
pig/trunk/test/org/apache/pig/test/TestPigServer.java
Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1308253&r1=1308252&r2=1308253&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Mon Apr 2 07:07:57 2012
@@ -293,6 +293,8 @@ PIG-2228: support partial aggregation in
BUG FIXES
+PIG-2623: Support S3 paths for registering UDFs (nshkrob via daijy)
+
PIG-2505: AvroStorage won't read any file not ending in .avro (russell.jurney via daijy)
PIG-2585: Enable ignored e2e test cases (daijy)
Modified: pig/trunk/src/org/apache/pig/PigServer.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/PigServer.java?rev=1308253&r1=1308252&r2=1308253&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/PigServer.java (original)
+++ pig/trunk/src/org/apache/pig/PigServer.java Mon Apr 2 07:07:57 2012
@@ -512,8 +512,7 @@ public class PigServer {
*/
public void registerCode(String path, String scriptingLang, String namespace)
throws IOException {
- File f = new File(path);
-
+ File f = FileLocalizer.fetchFile(pigContext.getProperties(), path).file;
if (!f.canRead()) {
int errCode = 4002;
String msg = "Can't read file: " + path;
@@ -522,9 +521,9 @@ public class PigServer {
}
if(scriptingLang != null) {
ScriptEngine se = ScriptEngine.getInstance(scriptingLang);
- se.registerFunctions(path, namespace, pigContext);
+ se.registerFunctions(f.getPath(), namespace, pigContext);
}
- pigContext.addScriptFile(path);
+ pigContext.addScriptFile(f.getPath());
}
/**
Modified: pig/trunk/test/org/apache/pig/test/TestPigServer.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPigServer.java?rev=1308253&r1=1308252&r2=1308253&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPigServer.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPigServer.java Mon Apr 2 07:07:57 2012
@@ -423,6 +423,32 @@ public class TestPigServer {
Assert.assertTrue(((Long)iter.next().get(0))==2);
}
+
+ @Test
+ public void testRegisterRemoteScript() throws Throwable {
+ String scriptName = "script.py";
+ File scriptFile = File.createTempFile("tmp", "");
+ PrintWriter pw = new PrintWriter(new FileWriter(scriptFile));
+ pw.println("@outputSchema(\"word:chararray\")\ndef helloworld():\n return 'Hello, World'");
+ pw.close();
+
+ FileSystem fs = cluster.getFileSystem();
+ fs.copyFromLocalFile(new Path(scriptFile.getAbsolutePath()), new Path(scriptName));
+
+ // find the absolute path for the directory so that it does not
+ // depend on configuration
+ String absPath = fs.getFileStatus(new Path(scriptName)).getPath().toString();
+
+ Util.createInputFile(cluster, "testRegisterRemoteScript_input", new String[]{"1", "2"});
+ pig.registerCode(absPath, "jython", "pig");
+ pig.registerQuery("a = load 'testRegisterRemoteScript_input';");
+ pig.registerQuery("b = foreach a generate pig.helloworld($0);");
+ Iterator<Tuple> iter = pig.openIterator("b");
+
+ Assert.assertTrue(iter.next().get(0).equals("Hello, World"));
+ Assert.assertTrue(iter.next().get(0).equals("Hello, World"));
+ Assert.assertFalse(iter.hasNext());
+ }
@Test
public void testDescribeLoad() throws Throwable {