InputParameter:SQL 存储过程的输入参数:类生成器

InputParameter:生成一个 InputParameter 对象,该对象捕获有关要嵌入到 SQL Server 存储过程中的 R 函数的输入参数的信息。 这些值将成为存储过程的输入参数。 受支持的输入参数的 R 类型为 POSIXct、numeric、character、integer、logical 和 raw。

用法

  InputParameter(name, type, defaultValue = NULL, defaultQuery = NULL,
  value = NULL, enableOutput = FALSE)

参数

name

一个字符串,输入参数对象的名称。

type

一个字符串,表示输入参数对象的 R 类型。

defaultValue

参数的默认值。 “raw”不支持。

defaultQuery

一个字符串,指定在执行存储过程中未提供其他查询时将检索数据的默认查询。

value

将在下一次运行存储过程时用于参数的值。

enableOutput

将此值设为输入/输出参数

InputParameter 对象

示例


 ## Not run:

 # See ?StoredProcedure for creating the `cleandata` table.
 # and ?executeStoredProcedure for creating the `rdata` table. 

 # score1 makes a batch prediction given clean data(indata),
 # model object(model_param), and the new name of the variable
 # that is being predicted
 score1 <- function(indata, model_param, predVarName) {
 indata[,"DayOfWeek"] <- factor(indata[,"DayOfWeek"], levels=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))
 # The connection string
 conStr <- paste("Driver={ODBC Driver 13 for SQL Server};Server=.;Database=RevoTestDB;",
                 "Trusted_Connection=Yes;", sep = "")
 # The compute context
 computeContext <- RxInSqlServer(numTasks=4, connectionString=conStr)
 mm <- rxReadObject(as.raw(model_param))
 # Predict
 result <- rxPredict(modelObject = mm,
                     data = indata,
                     outData = NULL,
                     predVarNames = predVarName,
                     extraVarsToWrite = c("ArrDelay"),
                     writeModelVars = TRUE,
                     overwrite = TRUE)
}
# connections string
conStr <- paste0("Driver={ODBC Driver 13 for SQL Server};Server=.;Database=RevoTestDB;",
                "Trusted_Connection=Yes;")
# create InpuData Object for an input parameter that is a data frame
id <- InputData(name = "indata", defaultQuery = "SELECT * from cleanData")
# InputParameter for the model_param input variable
model <- InputParameter("model_param", "raw",
                       defaultQuery =
                         "select top 1 value from rdata where [key] = 'linmod.v1'")
# InputParameter for the predVarName variable
name <- InputParameter("predVarName", "character", value = "ArrDelayEstimate")
sp_df_df <- StoredProcedure(score1, "sTest", id, model, name,
                       filePath = ".")
## End(Not run)