Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 12-21-2015 01:43 PM
I have seen URLDecoder as an example for Pig Dynamic Invokers. Can i have more examples like String related functions or may be other that pig use as dynamic invokers?
Created 12-24-2015 04:01 AM
awesome question, didn't even know this exists but digging through Pig source code, here are some examples https://github.com/apache/pig/blob/a44b85a0ab941cd...
-- 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);
and here are test cases that you can probably look for examples https://github.com/apache/pig/blob/a44b85a0ab941cd...
Created 12-24-2015 04:01 AM
awesome question, didn't even know this exists but digging through Pig source code, here are some examples https://github.com/apache/pig/blob/a44b85a0ab941cd...
-- 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);
and here are test cases that you can probably look for examples https://github.com/apache/pig/blob/a44b85a0ab941cd...
Created 12-24-2015 04:54 AM
pig is awesome...
Created 12-24-2015 05:11 AM
Is StringConcat function that you defined working for you??? I am encountering following error.
Caused by: java.lang.NoSuchMethodException: java.lang.String.concat() at java.lang.Class.getMethod(Class.java:1665) at org.apache.pig.builtin.Invoker.<init>(Invoker.java:88) at org.apache.pig.builtin.GenericInvoker.<init>(GenericInvoker.java:90) at org.apache.pig.builtin.InvokeForString.<init>(InvokeForString.java:40) ... 39 more
I am not sure whether Pig Dynamic Invokes work for functions other than "Static".
Created 12-24-2015 01:58 PM
@Suresh Bonam The string concat example is from the tests of dynamic invokers, I didn't create it. Here are some comments from the source code
/** need more tests -- non-String funcs and especially the full path through the pig interpreter. * I tested manually, seems to work, but * should really add more here.It's passing their tests so I assume it does work. I will test it at some point. If you want a speedier answer, perhaps you can ping the Pig mailing list? I'm so glad you brought this up, I see how this feature can be really handy and it's been available since Pig 0.8! Here's some more info on it https://squarecog.wordpress.com/?s=dynamic+invoker.
Created 12-24-2015 05:50 PM
@Suresh Bonam I tried the StringConcat and it didn't work, even though GenericInvoker does accept functions that are not Static. InvokeForString('java.lang.String.concat', 'String String', 'false') with false being isStatic didn't work for me. I ping the Pig mailing list, will see. It is pretty limiting with only primitives and only static methods, that's a shame!
Created 12-24-2015 05:52 PM
Here's the original post https://pig.apache.org/docs/r0.15.0/api/org/apache/pig/builtin/GenericInvoker.html