[ 
https://issues.apache.org/jira/browse/PIG-928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12888232#action_12888232
 ] 

Aniket Mokashi commented on PIG-928:
------------------------------------

Thanks for your comments. I will make the required changes.

bq. Do you want to allow: register myJavaUDFs.jar using 'java' as 
'javaNameSpace' ? Use-case could be that if we are allowing namespaces for 
non-java, why not allow for Java udfs as well. But then define is exactly for 
this purpose. So, it may make sense to throw exception for such a case.
myJavaUDFs.jar can itself have package structure that can define its own 
namespace, for example- maths.jar has function math.sin etc, I will throw 
parseexception for such a case
bq. ScriptEngine.getInstance() should be a singleton, no?
getInstance is a factory method that returns an instance of scriptEngine based 
on its type. We create a newInstance of the scriptEngine so that if 
registerCode is called simultaneously, we can create a different interpreter 
for both the invocations to register these scripts to pig.
bq. In JythonScriptEngine.getFunction() I think you should check if 
interpreter.get(functionName) != null and then return it and call 
Interpreter.init(path) only if its null.
This behavior is consistent with interpreter.get method that returns null if 
some resource is not found inside the script. Callers of this function handle 
runtimeexceptions. Also, we will fail much earlier if we try to access 
functions that are not already present/registered so it should be safe.
Also, interpreter is never null because its a static member of the 
JythonScriptEngine, instantiated statically.
bq. I didn't get why the changes are required in POUserFunc. Can you explain 
and also add it as comments in the code.
POUserFunc has possible bug to check res.result != null when it is always null 
at this point. If the returntype expected is bytearray, we cast return object 
to byte[] with toString().getBytes() (which was never hit due to the bug 
mentioned above), but when return type is byte[] we need special handling (this 
is not case for other evalfuncs as they generally return pigtypes).
bq. Instead of adding query through pigServer.registerCode() api, add it 
through pigServer.registerQuery(register myscript.py using "jython"). This will 
make sure we are testing changes in QueryParser.jjt as well.
register is Grunt command parsed by gruntparser hence doesnt go through 
queryparser. We directly call registerCode from GruntParser. Also, parsing 
logic is trivial.



> UDFs in scripting languages
> ---------------------------
>
>                 Key: PIG-928
>                 URL: https://issues.apache.org/jira/browse/PIG-928
>             Project: Pig
>          Issue Type: New Feature
>            Reporter: Alan Gates
>            Assignee: Aniket Mokashi
>             Fix For: 0.8.0
>
>         Attachments: calltrace.png, package.zip, PIG-928.patch, 
> pig-greek.tgz, pig.scripting.patch.arnab, pyg.tgz, RegisterPythonUDF3.patch, 
> RegisterPythonUDF4.patch, RegisterPythonUDF_Final.patch, 
> RegisterPythonUDFFinale.patch, RegisterPythonUDFFinale3.patch, 
> RegisterPythonUDFFinale4.patch, RegisterPythonUDFFinale5.patch, 
> RegisterScriptUDFDefineParse.patch, scripting.tgz, scripting.tgz, test.zip
>
>
> It should be possible to write UDFs in scripting languages such as python, 
> ruby, etc.  This frees users from needing to compile Java, generate a jar, 
> etc.  It also opens Pig to programmers who prefer scripting languages over 
> Java.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to