I'm working on a Monetdb Database with embedded R. Now, I want to process the data from a column, which basically reduces the amount of values.
The question now is if it is possible to create a R function that takes an input column with n
values and returns a columns with m
(m <> n)
columns.
I tried it but the output of the function is somehow irritating:
-- create data
CREATE FUNCTION generate(n INTEGER) RETURNS TABLE(data DOUBLE) LANGUAGE R{
data.frame(rnorm(n))
};
-- reduce data
CREATE FUNCTION reduce(data REAL) returns DOUBLE LANGUAGE R{
data[1:(length(data)-1)]
};
-- actually reduce generated data
select reduce(data) from generate(3);
This outputs the following:
sql>select reduce(data) from generate(3);
+--------------------------+
| L4 |
+==========================+
| -0.6561001539230347 |
| 1.0922646522521973 |
+--------------------------+
2 tuples (47.601ms)
The interesting think happens, when I add another column to the output:
sql>select 1,reduce(data) from generate(3);
+------+--------------------------+
| L4 | L6 |
+======+==========================+
| 1 | -1.2222824096679688 |
| 1 | 2.696558952331543 |
+------+--------------------------+
3 tuples (5.455ms)
The number of tuples which monetdb thinks to deliver changes. Is anything wrong with the Code or is it simply wrong to reduce the length of the output column?
This is only a simplified example of the real problem. The actual problem occurs when I insert the result into another table.
CREATE TABLE test(i INTEGER, r real);
insert into test select 1,reduce(data) from generate(3);
2 affected rows (4.404ms)
gives
select * from test;
GDK reported error.
BATproject: does not match always
What is the reason for the problem? I assume that it is somehow related to the above described problem.