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

InputParameter:生成一个 InputParameter 对象,该对象捕获要嵌入 SQL Server 存储过程的 R 函数的输入参数的相关信息。 这些参数将成为存储过程的输入参数。 支持的输入参数的 R 类型为 POSIXct、数字、字符、整数、逻辑和原始。

用法

  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 InputData 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)