[ https://issues.apache.org/jira/browse/PIG-1354?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12853421#action_12853421 ]
Dmitriy V. Ryaboy commented on PIG-1354: ---------------------------------------- The attached patch provides generic UDFs for invoking functions that return one of the following Java classes: String, Integer, Long, Double, Float, or their primitive equivalents. The same set of classes can serve as arguments to said functions. Static or non-static methods can be invoked (a non-static method is assumed to be invoked on the first element in the argument list). The method signature is supplied using Pig Latin's DEFINE statement. Usage looks like this: {code} -- invoking a static method DEFINE StringToLong InvokeForLong('java.lang.Long.valueOf', 'String') longs = FOREACH strings GENERATE StringToLong(some_chararray); -- invoking a method on an object DEFINE StringConcat InvokeForString('java.lang.String.concat', 'String String', 'false') concatenations = FOREACH strings GENERATE StringConcat(str1, str2); {code} There is some overhead to using this technique vs writing a method-specific UDF wrapper. In my tests, the dynamic version runs about 1.3x-1.8x slower than a non-dynamic version for simple methods. > UDFs for dynamic invocation of simple Java methods > -------------------------------------------------- > > Key: PIG-1354 > URL: https://issues.apache.org/jira/browse/PIG-1354 > Project: Pig > Issue Type: New Feature > Affects Versions: 0.8.0 > Reporter: Dmitriy V. Ryaboy > Assignee: Dmitriy V. Ryaboy > Fix For: 0.8.0 > > Attachments: PIG-1354.patch > > > The need to create wrapper UDFs for simple Java functions creates unnecessary > work for Pig users, slows down the development process, and produces a lot of > trivial classes. We can use Java's reflection to allow invoking a number of > methods on the fly, dynamically, by creating a generic UDF to accomplish this. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.