You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Dan Young <da...@gmail.com> on 2012/04/28 00:00:28 UTC
Javascript UDF woes...
I'm trying to output two values from a javascript udf, which takes a JSON
document as input.....but for the life of me I can't seem to get it to
return where I can reference the device_id or user_device......
I've tried this, which when I dump the data I just get noting => ()
get_device_id_and_type.outputSchema = "t:tuple(device_id:chararray,
user_device:chararray)";
function get_device_id_and_type(doc){
var obj = eval('(' + doc + ')');
return {device_id:obj.device_id , user_device:obj.user_device};
}
grunt> describe c;
c: {t: (device_id: chararray,user_device: chararray)}
this returns data, buy it's only one column.....
get_device_id_and_type.outputSchema = "device_id:chararray,
user_device:chararray";
function get_device_id_and_type(doc){
var obj = eval('(' + doc + ')');
return {device_id:obj.device_id , user_device:obj.user_device};
}
grunt> describe c;
c: {(device_id: chararray,user_device: chararray)}
Am I doing something wrong with my function decorators or with the return?
or should I bag javascript and go to jython or jruby :)
Dan
Javascript UDF woes...
Posted by Dan Young <da...@gmail.com>.
Are there any users out there using JavaScript udfs? I'm trying to figure
out how to return a tuple, with two elements in it, from a basic
JavaScript . I'm forwarding a previous email I sent to the list a few days
ago...since then I've upgraded Rhino so that I can use JSON.parse vs the
eval.... but I still can't get then tuple definition /outputSchema working.
Any insight /pointers would be greatly appreciated.
Regards,
Dano
---------- Forwarded message ----------
From: "Dan Young" <da...@gmail.com>
Date: Apr 27, 2012 4:00 PM
Subject: Javascript UDF woes...
To: <us...@pig.apache.org>
I'm trying to output two values from a javascript udf, which takes a JSON
document as input.....but for the life of me I can't seem to get it to
return where I can reference the device_id or user_device......
I've tried this, which when I dump the data I just get noting => ()
get_device_id_and_type.outputSchema = "t:tuple(device_id:chararray,
user_device:chararray)";
function get_device_id_and_type(doc){
var obj = eval('(' + doc + ')');
return {device_id:obj.device_id , user_device:obj.user_device};
}
grunt> describe c;
c: {t: (device_id: chararray,user_device: chararray)}
this returns data, buy it's only one column.....
get_device_id_and_type.outputSchema = "device_id:chararray,
user_device:chararray";
function get_device_id_and_type(doc){
var obj = eval('(' + doc + ')');
return {device_id:obj.device_id , user_device:obj.user_device};
}
grunt> describe c;
c: {(device_id: chararray,user_device: chararray)}
Am I doing something wrong with my function decorators or with the return?
or should I bag javascript and go to jython or jruby :)
Dan