共用方式為


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)