greenplum-db/plcontainer

PL / Container R stored procedure cannot return data frame or array correctly

palosky opened this issue · 2 comments

Hi,all。
When I tested the PL / Container(plcontainer-1.4.0) R stored procedure, I wanted to return the contents of the data frame or array. As a result, the float data and character data could not be returned correctly. Thanks for the answer.

code show as below:

drop table if exists t_r1;
create table t_r1(id int primary key, name varchar(32), val1 numeric, val2 numeric);
insert into t_r1 values(1, 'tom', 10.52, 9.87),(2, 'lucy', 8.97, 11.24),(3, 'jack', 9.69, 8.83);

--------------Test example1--------------

drop function if exists func_r1();
create or replace function func_r1()
returns int[]
as
$$
#container: plc_r_shared
result <- pg.spi.exec("select * from t_r1 order by id")
return(result[[1]]) # return column id values
$$
language 'plcontainer';

select func_r1();
-- result {1,2,3}

--------------Test example2--------------

drop function if exists func_r2();
create or replace function func_r2()
returns text[]
as
$$
#container: plc_r_shared
result <- pg.spi.exec("select * from t_r1 order by id")
return(result[[2]]) # return column name values
$$
language 'plcontainer';

select func_r2();
-- result ERROR: plcontainer: Error receiving data from the client. Maybe retry later. (plcontainer.c:335)

--------------Test example3--------------

drop function if exists func_r3();
create or replace function func_r3()
returns float8[]
as
$$
#container: plc_r_shared
result <- pg.spi.exec("select * from t_r1 order by id")
return(result[[3]]) # return column val1 values
$$
language 'plcontainer';

select func_r3();
-- result {6.12244320859016e+257,4.27255601798251e+180,4.53795471739096e+217}
This result is obviously wrong, the correct should be: {10.52, 8.97, 9.69}

We have created an issue in Pivotal Tracker to manage this. Unfortunately, the Pivotal Tracker project is private so you may be unable to view the contents of the story.

The labels on this github issue will be updated when the story is started.

@palosky Thank you very much for using PL/Container.
Yes, this is the known issue for PL/Container R language. It has been fixed in PL/Container 3.0-beta.