Author: daijy
Date: Sat Feb 20 00:37:14 2016
New Revision: 1731318
URL: http://svn.apache.org/viewvc?rev=1731318&view=rev
Log:
PIG-4812: Register Groovy UDF with relative path does not work
Added:
pig/branches/branch-0.15/test/e2e/pig/udfs/groovy/
pig/branches/branch-0.15/test/e2e/pig/udfs/groovy/scriptingudf.groovy
pig/branches/branch-0.15/test/e2e/pig/udfs/js/
pig/branches/branch-0.15/test/e2e/pig/udfs/js/scriptingudf.js
Modified:
pig/branches/branch-0.15/CHANGES.txt
pig/branches/branch-0.15/src/org/apache/pig/scripting/groovy/GroovyEvalFunc.java
pig/branches/branch-0.15/test/e2e/pig/build.xml
pig/branches/branch-0.15/test/e2e/pig/tests/nightly.conf
Modified: pig/branches/branch-0.15/CHANGES.txt
URL:
http://svn.apache.org/viewvc/pig/branches/branch-0.15/CHANGES.txt?rev=1731318&r1=1731317&r2=1731318&view=diff
==============================================================================
--- pig/branches/branch-0.15/CHANGES.txt (original)
+++ pig/branches/branch-0.15/CHANGES.txt Sat Feb 20 00:37:14 2016
@@ -28,6 +28,8 @@ OPTIMIZATIONS
BUG FIXES
+PIG-4812: Register Groovy UDF with relative path does not work (daijy)
+
PIG-4808: PluckTuple overwrites regex if used more than once in the same
script (eval via daijy)
PIG-4587: Applying isFirstReduceOfKey for Skewed left outer join skips records
(rohini)
Modified:
pig/branches/branch-0.15/src/org/apache/pig/scripting/groovy/GroovyEvalFunc.java
URL:
http://svn.apache.org/viewvc/pig/branches/branch-0.15/src/org/apache/pig/scripting/groovy/GroovyEvalFunc.java?rev=1731318&r1=1731317&r2=1731318&view=diff
==============================================================================
---
pig/branches/branch-0.15/src/org/apache/pig/scripting/groovy/GroovyEvalFunc.java
(original)
+++
pig/branches/branch-0.15/src/org/apache/pig/scripting/groovy/GroovyEvalFunc.java
Sat Feb 20 00:37:14 2016
@@ -28,6 +28,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.net.URL;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -65,8 +66,21 @@ public class GroovyEvalFunc<T> extends E
Class c = scriptClasses.get(path);
if (null == c) {
+ File file = new File(path);
+ URL resource = null;
+ if (!file.exists()) {
+ resource = ScriptEngine.class.getResource(path);
+ if (resource == null) {
+ resource = ScriptEngine.class.getResource(File.separator + path);
+ }
+ if (resource == null) {
+ throw new IOException("Cannot find " + path);
+ }
+ } else {
+ resource = file.toURL();
+ }
try {
- c = GroovyScriptEngine.getEngine().loadScriptByName(new
File(path).toURI().toString());
+ c =
GroovyScriptEngine.getEngine().loadScriptByName(resource.toString());
} catch (ScriptException se) {
throw new IOException(se);
} catch (ResourceException re) {
Modified: pig/branches/branch-0.15/test/e2e/pig/build.xml
URL:
http://svn.apache.org/viewvc/pig/branches/branch-0.15/test/e2e/pig/build.xml?rev=1731318&r1=1731317&r2=1731318&view=diff
==============================================================================
--- pig/branches/branch-0.15/test/e2e/pig/build.xml (original)
+++ pig/branches/branch-0.15/test/e2e/pig/build.xml Sat Feb 20 00:37:14 2016
@@ -38,7 +38,9 @@
<property name="udf.java.dir" value="${udf.dir}/java"/>
<property name="udf.jar" value="${udf.java.dir}/testudf.jar"/>
<property name="python.udf.dir" value="${udf.dir}/python"/>
+ <property name="js.udf.dir" value="${udf.dir}/js" />
<property name="ruby.udf.dir" value="${udf.dir}/ruby" />
+ <property name="groovy.udf.dir" value="${udf.dir}/groovy" />
<property name="cpython.udf.dir" value="${udf.dir}/cpython" />
<property name="params.dir" value="${basedir}/paramfiles"/>
<property name="e2e.lib.dir" value="${basedir}/lib"/>
@@ -168,7 +170,9 @@
<mkdir dir="${tar.dir}/libexec/PigTest/test"/>
<mkdir dir="${tar.dir}/libexec/PigTest/generate"/>
<mkdir dir="${tar.dir}/libexec/python"/>
+ <mkdir dir="${tar.dir}/libexec/js"/>
<mkdir dir="${tar.dir}/libexec/ruby"/>
+ <mkdir dir="${tar.dir}/libexec/groovy"/>
<mkdir dir="${tar.dir}/libexec/cpython"/>
<mkdir dir="${tar.dir}/lib"/>
<mkdir dir="${tar.dir}/lib/java"/>
@@ -217,10 +221,18 @@
<fileset dir="${python.udf.dir}"/>
</copy>
+ <copy todir="${tar.dir}/libexec/js">
+ <fileset dir="${js.udf.dir}"/>
+ </copy>
+
<copy todir="${tar.dir}/libexec/ruby">
<fileset dir="${ruby.udf.dir}"/>
</copy>
+ <copy todir="${tar.dir}/libexec/groovy">
+ <fileset dir="${groovy.udf.dir}"/>
+ </copy>
+
<copy todir="${tar.dir}/libexec/cpython">
<fileset dir="${cpython.udf.dir}"/>
</copy>
Modified: pig/branches/branch-0.15/test/e2e/pig/tests/nightly.conf
URL:
http://svn.apache.org/viewvc/pig/branches/branch-0.15/test/e2e/pig/tests/nightly.conf?rev=1731318&r1=1731317&r2=1731318&view=diff
==============================================================================
--- pig/branches/branch-0.15/test/e2e/pig/tests/nightly.conf (original)
+++ pig/branches/branch-0.15/test/e2e/pig/tests/nightly.conf Sat Feb 20
00:37:14 2016
@@ -3963,6 +3963,42 @@ store b into ':OUTPATH:';\,
]
},
{
+ 'name' => 'JavaScriptUDFs',
+ 'tests' => [
+ {
+ # test double square
+ 'num' => 1,
+ 'pig' => q\
+register ':SCRIPTHOMEPATH:/js/scriptingudf.js' using javascript as myfuncs;
+a = load ':INPATH:/singlefile/studenttab10k' using PigStorage() as (name,
age:int, gpa:double);
+b = foreach a generate myfuncs.square(gpa);
+store b into ':OUTPATH:';\,
+ 'verify_pig_script' => q\
+a = load ':INPATH:/singlefile/studenttab10k' using PigStorage() as (name,
age:int, gpa:double);
+b = foreach a generate gpa * gpa;
+store b into ':OUTPATH:';\,
+ },
+ ]
+ },
+ {
+ 'name' => 'GroovyUDFs',
+ 'tests' => [
+ {
+ # test integer square
+ 'num' => 1,
+ 'pig' => q\
+register ':SCRIPTHOMEPATH:/groovy/scriptingudf.groovy' using groovy as myfuncs;
+a = load ':INPATH:/singlefile/studenttab10k' using PigStorage() as (name,
age:int, gpa:double);
+b = foreach a generate myfuncs.square(age);
+store b into ':OUTPATH:';\,
+ 'verify_pig_script' => q\
+a = load ':INPATH:/singlefile/studenttab10k' using PigStorage() as (name,
age:int, gpa:double);
+b = foreach a generate age * age;
+store b into ':OUTPATH:';\,
+ },
+ ]
+ },
+ {
'name' => 'StreamingPythonUDFs',
'tests' => [
{
Added: pig/branches/branch-0.15/test/e2e/pig/udfs/groovy/scriptingudf.groovy
URL:
http://svn.apache.org/viewvc/pig/branches/branch-0.15/test/e2e/pig/udfs/groovy/scriptingudf.groovy?rev=1731318&view=auto
==============================================================================
--- pig/branches/branch-0.15/test/e2e/pig/udfs/groovy/scriptingudf.groovy
(added)
+++ pig/branches/branch-0.15/test/e2e/pig/udfs/groovy/scriptingudf.groovy Sat
Feb 20 00:37:14 2016
@@ -0,0 +1,10 @@
+import org.apache.pig.scripting.groovy.OutputSchemaFunction;
+class GroovyUDFs {
+ @OutputSchemaFunction('squareSchema')
+ public static square(x) {
+ return x * x;
+ }
+ public static squareSchema(input) {
+ return input;
+ }
+}
Added: pig/branches/branch-0.15/test/e2e/pig/udfs/js/scriptingudf.js
URL:
http://svn.apache.org/viewvc/pig/branches/branch-0.15/test/e2e/pig/udfs/js/scriptingudf.js?rev=1731318&view=auto
==============================================================================
--- pig/branches/branch-0.15/test/e2e/pig/udfs/js/scriptingudf.js (added)
+++ pig/branches/branch-0.15/test/e2e/pig/udfs/js/scriptingudf.js Sat Feb 20
00:37:14 2016
@@ -0,0 +1,4 @@
+square.outputSchema = "square:double";
+function square(x) {
+ return x * x
+}