Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Plain View
Pig >> mail # user >> calling python udfs with varargs


Copy link to this message
-
calling python udfs with varargs
Hi,

I have a simple python udf which takes a variable number of (string)
arguments and returns the first non-empty one.
I can see that the udf is invoked from pig but no arguments are being passed.

Here is the script:
========================================================
#!/usr/bin/python

from org.apache.pig.scripting import *

@outputSchema("s:chararray")
def firstNonempty(*args):
    print args
    for v in args:
     if len(v) != 0:
           return v
    return ''

if __name__ == "__main__":
   Pig.compile("""
   data = load 'input.txt' AS (string1:chararray, string2:chararray);
   data = foreach data generate firstNonempty(string1, string2) as id,
string1, string2;
   dump data;
   """).bind().runSingle()

==========================================================
Thanks!

stan
+
Julien Le Dem 2011-10-17, 18:26
+
Stan Rosenberg 2011-10-17, 19:38
+
Julien Le Dem 2011-10-17, 20:01
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB