分享方式:


InputData:SQL 預存程式的輸入資料:類別產生器

InputData:產生 InputData 物件,以擷取輸入參數 (其為資料框架) 的資訊。 在執行指定的查詢時,必須填入資料框架。 此物件是建立預存程序的必要項目,而預存程序中的內嵌 R 函數會採用資料框架輸入參數。

使用方式

  InputData(name, defaultQuery = NULL, query = NULL)

引數

name

字元字串,R 函數中會提供給 StoredProcedure 的資料輸入參數名稱。

defaultQuery

指定預設查詢的字元字串,如果在預存程序執行時未提供不同的查詢,預設查詢將會擷取資料。 必須是簡單的 SELECT 查詢。

query

字元字串,指定將用來擷取下一次預存程式中數據的查詢。

InputData 物件

範例


 ## Not run:

 # See ?StoredProcedure for creating the "cleandata" table.

 # train 1 takes a data frame with clean data and outputs a model
 train1 <- function(in_df) {
   in_df[,"DayOfWeek"] <- factor(in_df[,"DayOfWeek"], levels=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))
   # The model formula
   formula <- ArrDelay ~ CRSDepTime + DayOfWeek + CRSDepHour:DayOfWeek
   # Train the model
   rxSetComputeContext("local")
   mm <- rxLinMod(formula, data=in_df)
   mm <- rxSerializeModel(mm)

   return(list("mm" = mm))
 }
 # create InpuData Object for an input parameter that is a data frame
 # note: if the input parameter is not a data frame use InputParameter object
 id <- InputData(name = "in_df",
                defaultQuery = paste0("select top 10000 ArrDelay,CRSDepTime,",
                                      "DayOfWeek,CRSDepHour from cleanData"))
 # create an OutputParameter object for the variable inside the return list
 # note: if that variable is a data frame use OutputData object
 out <- OutputParameter("mm", "raw")

 # connections string
 conStr <- paste0("Driver={ODBC Driver 13 for SQL Server};Server=.;Database=RevoTestDB;",
                  "Trusted_Connection=Yes;")
 # create the stored procedure object
 sp_df_op <- StoredProcedure("train1", "spTest1", id, out,
                        filePath = ".")
 # register the stored procedure with the database
 registerStoredProcedure(sp_df_op, conStr)

 # execute the stored procedure, note: non-data frame variables inside the
 # return list are not returned to R. However, if the execution is not successful
 # the error will be displayed
 model <- executeStoredProcedure(sp_df_op, connectionString = conStr)
 # get the linear model
 mm <- rxUnserializeModel(model$params$op1)
## End(Not run)