Home | About | Sematext search-lucene.com search-hadoop.com
 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?
Norbert Burger 2011-07-26, 14:21
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