在Vertica中调用R函数:UDx RPC调用失败... processPartitionForR中的异常:[0(非NA)情况]

时间:2016-09-01 12:07:15

标签: r vertica

我在R中创建了一个转换UDF,它在由某个实体的Id划分的表上运行线性回归。我在控制台测试它,它完美无缺,结果很有意义,一切都很好。但是,在实际设置(由服务器运行的代码,而不是我手动运行)中使用相同的数据我总是看到相同的错误:

错误3399:UDx RPC调用失败InvokeProcessPartition():在[/scratch_a/release/24506/vbuild/vertica/OSS/UDxFence/RInterface.cpp:1387]中调用用户定义对象[remove_temperature_correlation]中的processPartition()时出错,错误代码:0,消息:processPartitionForR中的异常:[0(非NA)情况]

这是实际功能:

require('splines')

timefy <- function(time) {
  time = as.POSIXct(time, tz='utc', origin='1970-01-01T00:00:00Z')
  return(time)
}

remove_temperature_correlation <- function(data, params=list()) {
  names(data) = c('Time', 'Value', 'Temperature')

  # Check params
  df = params[['df']]
  if (is.null(df))
    df = 4

  degree = params[['degree']]
  if (is.null(degree))
    degree = 1

  # Convert Vertica timestamps to R's POSIXct format
  data$ct = timefy(data$Time)

  # Fit model
  formula = Value ~ bs(Temperature, df = df, degree = degree)
  fitmodel = lm(formula, data=data)

  data$NormalizedValue = residuals(fitmodel)

  return(data[c('Time', 'Value', 'Temperature', 'NormalizedValue')])
}

remove_temperature_correlation_parameters <- function()
{
  num_params = 2
  param = data.frame(datatype=rep(NA, num_params),
                     length=rep(NA, num_params),
                     scale=rep(NA, num_params),
                     name=rep(NA, num_params))

  param[1,1] = 'int'
  param[1,4] = 'df'

  param[2,1] = 'int'
  param[2,4] = 'degree'

  return(param)
}

remove_temperature_correlation_return_type <- function(x, param)
{
  num_params = 4
  param = data.frame(datatype=rep(NA, num_params),
                     length=rep(NA, num_params),
                     scale=rep(NA, num_params),
                     name=rep(NA, num_params))

  param[1,1] = 'timestamptz'
  param[1,4] = 'Time'

  param[2,1] = 'float'
  param[2,4] = 'Value'

  param[3,1] = 'float'
  param[3,4] = 'Temperature'

  param[4,1] = 'float'
  param[4,4] = 'NormalizedValue'

  return(param)
}

remove_temperature_correlation_factory <- function()
{
  list(name=remove_temperature_correlation,
       udxtype=c('transform'),
       # time, value, temperature
       intype=c('timestamptz', 'float', 'float'),
       outtype=c('any'),
       outtypecallback=remove_temperature_correlation_return_type,
       parametertypecallback=remove_temperature_correlation_parameters,
       volatility=c('stable'),
       strict=c('called_on_null_input'))
}

我试图模拟在测试环境中导致类似错误的情况,并发现仅为一行提供该函数会引发相同的错误。我对Vertica及其UDF非常陌生,所以如果我能够获得有关如何进一步调试它的想法以及可能是什么原因的想法,它将会非常有用。一些谷歌搜索和对话让我相信原因是数据被分区的方式(可能是一些空分区到达UDF?)

以下是我如何调用UDF:

create local temporary table TEMP_table
on commit preserve rows
as
SELECT 
    Id,
    remove_temperature_correlation(Time, Value, Temperature USING PARAMETERS df = 4, degree=1)
    OVER(partition by Id order by Time)
FROM temp_input;

temp_input表只是将相应的数据存储在多行中。

解决问题的方法是什么,关于如何确定错误发生在哪里以及如何处理它的任何想法?

0 个答案:

没有答案
相关问题