Skip to main content

R udx returns different integer

  • July 30, 2015
  • 2 replies
  • 17 views

timolin

I'm passing integers as input to an R UDX function.  However, when I just ask the function to return the same integer, I get different numbers!  On the limited cases that I've looked at, it looks like it just increments for decrements by 1.

 

Here is an example:

 

R code:

 

longIntegerTest <- function (dt) {

names(dt) <- c('inInt')

result <- data.frame(input=dt$inInt);

}

longIntegerTest_factory <- function () {

list(name=longIntegerTest, udxtype=c("transform"), intype=c("int"), outtype=c("int"), outnames=c("res"))

}

 

SQL output:

 

timolin=> select longIntegerTest(12509528612683526) over();
res
-------------------
12509528612683526

 

timolin=> select longIntegerTest(12509528612683527) over();
res
-------------------
12509528612683528
(1 row)

 

 You can see the error in the second function call.

 

 

2 replies

SruthiA
Forum|alt.badge.img+1
  • Participating Frequently
  • July 30, 2015

Hi,

 

   I have noticed couple of things in your R program. Firstly, udx type should be scalar since you have 1:1 mapping between input and output. Second thing, 12509528612683527 is  not in integer range. Based on the machine architecture, integer range varies. To know the maximum acceptable integer for your machine, execute the following command at the R prompt

 

> .Machine$integer.max
[1] 2147483647

 

In my system, the above is the max integer value. If you give any value less than that your program will produce correct results. If given anything above, it may or may not produce correct results. You cannot use over() clause with longIntegerTest(), since it is not an analytic function. This is just from my investigation.

 

test1=> select longIntegerTest(2147483647);
longIntegerTest
-----------------
2147483647
(1 row)

 

 

test1=> select longIntegerTest(2140);
longIntegerTest
-----------------
2140
(1 row)

 

 

test1=> select longIntegerTest(21401);
longIntegerTest
-----------------
21401
(1 row)

 

 

test1=> select longIntegerTest(21402);
longIntegerTest
-----------------
21402
(1 row)

 

I hope this helps

 

-Regards,

 Sruthi


timolin
  • Author
  • Participating Frequently
  • July 30, 2015

Thanks - This explains it for me.

 

The test case is a stripped down version of a function that required it to be a transform function - I did not want to change it for this test.