Skip to main content

How to create outtype call back function?

  • February 21, 2014
  • 5 replies
  • 17 views

Haifeng_Ren
Forum|alt.badge.img+1
i just define "outtype=c("any")" , and when i create library, it prompt me to define a outtype call back function.

5 replies

Daniel_Leybovic
Forum|alt.badge.img+1
  • Participating Frequently
  • February 21, 2014
Hi!

Can you explain what you can't understand in this example?
https://my.vertica.com/docs/7.0.x/HTML/index.htm#Authoring/ProgrammersGuide/UserDefinedFunctions/UDx...
It will help to support to improve a documentation.


Haifeng_Ren
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • February 24, 2014
Error happened in getReturnType : unused argument (list(datatype = c(1, 1), length = c(0, 0), scale = c(0, 0), name = 1:2)).  I just define the outtype callback function like the example , i don't know why show this error message , could you give me an example for the outtype = "any"?

Daniel_Leybovic
Forum|alt.badge.img+1
  • Participating Frequently
  • February 24, 2014
Hi!


- Think about an example that will be a representative example for you
- If you can't - provide an original problem


>> could you give me an example for the outtype = "any"
No, you must to concretize.
1. Because an example of documentation also fit your definition:  "an example for the outtype = "any"", but you do not understands, so you MUST to be more concrete.
2. I can explain what you does understand and do not explain what actually you don't

Bheemesh
  • New Participant
  • August 6, 2014
I have same issue. When outputtype= "any" how to define outtypecallback? 
I might have any number of rows with any datatype in the output. I would not be able to name them or tell their datatypes to create outtypecallback function

PRana
Forum|alt.badge.img
  • Participating Frequently
  • August 6, 2014
Here is an example of how to define an outtypecallback

In this example the return type doesn't depend on the input types and hence the function stringreturntype doesn't need to look at the intypes.

stringConcat <- function(x,y)
{
    fullname <- paste(x[,1] ," ",x[,2])
    fullname

}

polyTransformfac <- function()
{
    list(name=stringConcat,
             udxtype=c("transform"),
             intype=c("any"),
             outtype=c("any"),
             outtypecallback = stringreturntype)
}

stringreturntype <- function(x,y)
{
    
     ret <- data.frame(datatype=rep(NA, 1), length=rep(NA, 1), scale=rep(NA,1))
     ret[1,1] = "varchar"
     ret[1,2] = 20
     ret[1,3] = 0
     ret
}




In this function the return type depends on intypes, it returns all the intypes except the first one as returntypes

polyTopK<- function(x,y)
{
    k = x[1,1]
    if(!check.integer(k))
    {
       stop("First argument must be an integer (the 'k' value)")
    } 
   
    j = ncol(x)
    ret = NULL
 
    df = convert.factors.to.strings.in.dataframe(x)
    for(i in 1:nrow(x))
    {
        if( i > k)
    {
       break
    }
        rbind(ret,df[i,2:j])->ret
    }

    if(k<=0)
    {
     ret<-as.data.frame(matrix(0,nrow=0,ncol=j-1))
    }
    ret
 
}

polyTopKReturnType <- function(x,y)
{
     ret <- NULL
     for( i in 2:nrow(x))
     {
         rbind(ret,x[i,]) -> ret
     }
     ret   
}

polyTopKFactory <- function()
{
     list(
         name=polyTopK,
         udxtype=c("transform"),
         intype=c("any"),
         outtype=c("any") ,
       outtypecallback=polyTopKReturnType
     )
}




HTH
Pratibha