Skip to main content

UDX_R - "incompatible factory type"

  • July 20, 2017
  • 1 reply
  • 6 views

MaciejPaliwoda
Forum|alt.badge.img+2

Hi
I have created UDX, and when I am trying to CREATE function, i am getting the error:

_SQL Error [4746] [42V13]: [Vertica]VJDBC ROLLBACK: Setting up function "xgb_createmodel" failed
[Vertica][VJDBC]Detail: [Incompatible factory type]
[Vertica]VJDBC ROLLBACK: Setting up function "xgb_createmodel" failed
[Vertica][VJDBC]Detail: [Incompatible factory type]
com.vertica.support.exceptions.SyntaxErrorException: [Vertica]VJDBC ROLLBACK: Setting up function "xgb_createmodel" failed
[Vertica][VJDBC]Detail: [Incompatible factory type]
_

any ideas?

And there is the SQL code:
DROP LIBRARY rXGBOOST_lib CASCADE;
CREATE LIBRARY rXGBOOST_lib AS '/home/dbadmin/R/rudx_xgboost.R' LANGUAGE 'R';
CREATE OR REPLACE FUNCTION xgb_createmodel AS LANGUAGE 'R' NAME 'xgb_createmodel_UserFactory' LIBRARY rXGBOOST_lib FENCED;

And the R Code:

library(xgboost)

xgb_createmodel <- function(inputcols, params){

  ### Set parameters for XBoost objective , num_class , nrounds ,


  if ( is.null(params[['modelfmt_str']]) ) {
    stop("NULL value for modelfmt_str! objective cannot be NULL.")
  } else {
    modelfmt_str.value <- params[['modelfmt_str']]
  }

  if ( is.null(params[['objective']]) ) {
    stop("NULL value for objective! objective cannot be NULL. (set to : multi:softmax or ...)")
  } else {
    objective.value <- params[['objective']]
  }
  if ( is.null(params[['num_class']]) ) {
    stop("NULL value for num_class! num_class cannot be NULL.")
  } else {
    num_class.value <- params[['num_class']]
  }
  if ( is.null(params[['nrounds']]) ) {
    stop("NULL value for nrounds! nrounds cannot be NULL.")
  } else {
    nrounds.value <- params[['nrounds']]
  }


  mlabel <- as.numeric(inputcols[,length(inputcols)])-1

  dTRAIN <- xgb.DMatrix(data = model.matrix( modelfmt_str.value, data = inputcols), label = mlabel)  

  XGB_MODEL <- xgboost(params = list(objective = objective.value,
                                      num_class = num_class.value),
                        data = dTRAIN,
                        nrounds = nrounds.value ,
                        verbose = FALSE
                      )

  SM <- serialize(XGB_MODEL, NULL)
  SM
}





xgb_createmodel_RReturnType <- function(arg.data.frame, parm.data.frame) {
  output.return.type <- data.frame(datatype = rep(NA,1),
                                   length   = rep(NA,1),
                                   scale    = rep(NA,1),
                                   name     = rep(NA,1))
  output.return.type$datatype <- c("long varbinary")
  output.return.type$name <- c("model")
  output.return.type$length <- c(2000)
  return(output.return.type)
}


xgb_createmodel_Parameters <- function() {
  input.parameters <- data.frame(datatype = c("varchar", "varchar", "int","int"),
                     length   = c("NA", "NA","NA","NA"),
                     scale    = c("NA", "NA", "NA", "NA"),
                     name     = c("modelfmt_str", "objective","num_class","nrounds")
                    )
  return(input.parameters)


}

xgb_createmodel_UserFactory <- function() {
  list(name    = xgb_createmodel,
       udxtype = c("transform"),
       # Since this is a polymorphic function the intype must be any
       intype  = c("any"),
       outtype = c("long varbinary"),
       parametertypecallback=xgb_createmodel_Parameters,
       outtypecallback = xgb_createmodel_RReturnType
       )
}

1 reply

MaciejPaliwoda
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • July 20, 2017

SOLVED::

the reason was lack of TRANSFORM statmement in function def:

CREATE LIBRARY rXGBOOST_lib AS '/home/dbadmin/R/rudx_xgboost.R' LANGUAGE 'R';
CREATE OR REPLACE >>>TRANSFORM<<< FUNCTION xgb_createmodel AS LANGUAGE 'R' NAME 'xgb_createmodel_UserFactory' LIBRARY rXGBOOST_lib FENCED;