Hey Joseph, You can return an empty result set by returning a list of empty lists, e.g.: CREATE FUNCTION empty_table() RETURNS TABLE(i INTEGER, j INTEGER) LANGUAGE PYTHON { return [[],[]] }; It seems the dictionary result doesn’t work correctly when returning an empty array. I will create a testcase and fix it. Another tip for prototyping functions, you can enter a file path instead of a function body. This way you don’t need to constantly recreate the function, e.g.: CREATE FUNCTION test() RETURNS TABLE(i INTEGER) LANGUAGE PYTHON ‘/home/user/file.py’; Everytime the function is executed the function body will be loaded from the file. Hope that helps, Mark
On 16 Dec 2016, at 18:31, Joseph D'silva
wrote: Hi All,
I am trying to return an "empty" result set from an embedded python function (as in some situations I will not have valid rows to produce in the output). However the very many attempts of trying to return an "empty" result from the function have failed (as is documented in the example below).
How do you get it done ?
Thanks.
DROP FUNCTION p_results_exp01; CREATE FUNCTION p_results_exp01() RETURNS TABLE(val1 STRING, val2 INTEGER) LANGUAGE PYTHON { #Unsupported result object. Expected either a list, dictionary, a numpy array, a numpy masked array or a pandas data frame, but received an object of type "
" #return None; #Errors #Expected a return value with name "val1", but this key was not present in the dictionary. #return {}; #Errors
#Error converting dict return value "val1": MALException:pyapi.eval:Unsupported result object. Expected either a list, dictionary, a numpy array, a numpy masked array or a pandas data frame, but received an object of type "
". #return {'val1':None, 'val2':None}; #Errors #Error converting dict return value "val1": MALException:pyapi.eval:An array of size 0 was returned, yet we expect a list of 1 columns. The result is invalid.. #return {'val1':[], 'val2':[]};
#return {'val1':['value_1'], 'val2':[1]}; #Works, as it has value. }; SELECT * FROM p_results_exp01();
Joseph _______________________________________________ users-list mailing list users-list@monetdb.org https://www.monetdb.org/mailman/listinfo/users-list