InputData:SQL 存储过程的输入数据:类生成器

InputData:生成一个 InputData 对象,该对象捕获有关作为数据帧的输入参数的信息。 在执行给定查询时需要填充数据帧。 创建嵌入 R 函数采用数据帧输入参数存储过程时,此对象是必需的。

用法

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

参数

name

一个字符串,即提供给 StoredProcedure 的 R 函数中数据输入参数的名称。

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)