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 >> return dict from Python UDF?


Copy link to this message
-
return dict from Python UDF?
Hi all - I'm having some difficulty returning a dict/map from a Python UDF.
The following code returns "java.lang.String cannot be cast to
org.python.core.PyObject".  What am I missing?

Thanks,
Norbert

Here's my test Pig script:

REGISTER 'pigfuncs.py' USING jython AS pigfuncs;
cvps = LOAD 'test.txt' USING PigStorage();

A = FOREACH cvps GENERATE pigfuncs.createmap() as dict;
B = FOREACH A GENERATE dict#'asdf';
dump B;

And the Python UDF:

@outputSchema("m:map[]")
def createmap():
        d = {}
        d['asdf'] = '1234'
        d['qwer'] = '5678'
        return d
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