Transform Function Error

Moderator: NorbertKrupa

Post Reply
stwp86
Newbie
Newbie
Posts: 11
Joined: Mon Nov 12, 2012 7:06 pm

Transform Function Error

Post by stwp86 » Fri Mar 28, 2014 8:50 pm

Hi Everyone . . .

I am new to the world of UDF w/R and Vertica. I have the following R code:

Code: Select all

betaFunction <- function(client, domain, user_name, ptSeen, avgATPP, avgOTPP, avgDTPP, percentCPOE, percentEDOC)
{
        sub <- subset((percentEDOC > .2) & (percentCPOE > .2) & (avgATPP < .06), select=c(client, domain, user_name, ptSeen, avgATPP, avgOTPP, avgDTPP, percentCPOE, percentEDOC))
        cooksreg <- lm(sub$avgATPP~sub$ptSeen)
        cook <- cooks.distance(cooksreg)
        df <- data.frame(sub,cook)
        sub1 <- subset(df, select=c(client,domain,user_name,ptSeen,avgATPP,avgOTPP,avgDTPP,percentCPOE,percentEDOC),cook<.05)
        cpoereg <- lm(sub1$avgOTPP~sub1$percentCPOE)
        edocreg <- lm(sub1$avgDTPP~sub1$percentEDOC)
        betacpoe <- coef(cpoereg)[2]
        betaedoc <- coef(edocreg)[2]
        print(c(betacpoe,betaedoc),digits=5)
}
betaFactory <- function()
{
        list(name=betaFunction,udxtype=c("transform"),intype=c("varchar","varchar","varchar","int","float","float","float","float","float"),outtype=c("float","float"),outnames=c("cpoeBeta","edocBeta"))
}
And successfully ran the following:

Code: Select all

CREATE LIBRARY betaFunctionLib AS '/home/vertica/betaFunction.R' LANGUAGE 'R';

CREATE TRANSFORM FUNCTION betaFunction AS NAME 'betaFactory' LIBRARY betaFunctionLib;
However, I get the following error when I run my query (query is pasted below):
Error: [Vertica][VJDBC](3399) ERROR: Failure in UDx RPC call InvokeProcessPartition(): Error calling processPartition() in User Defined Object [betaFunction] at [/scratch_a/release/vbuild/vertica/OSS/UDxFence/RInterface.cpp:1244], error code: 0, message: Exception in processPartitionForR: ['percentEDOC' is missing]
SQLState: VP001
ErrorCode: 3399



Changed the betaFunction (client, domain ...) to betaFunction(x) and then referenced it the R code like such x[,1] . . . this seemed to help, but now I must make a few more adjustments to get it working.

thanks!

Post Reply

Return to “R Language Integration”