使用RevoScaleR的R中的T-SQL临时表和存储过程

时间:2016-12-11 07:00:09

标签: sql-server r stored-procedures microsoft-r

在下面的示例中,我能够使查询处理一个例外。当我在q步骤中使用source.query代替RxSqlServerData时,我收到错误rxCompleteClusterJob Execution halted

第一个目标是使用存储过程代替较长的查询。这可能吗?

第二个目标是在存储过程中创建并调用#TEMPORARY表。我想知道这是否可行?

library (RODBC)
library (RevoScaleR)
sqlConnString <- "Driver=SQL Server;Server=SAMPLE_SERVER; Database=SAMPLE_DATABASE;Trusted_Connection=True"
sqlWait <- TRUE   
sqlConsoleOutput <- FALSE  
sql_share_directory <- paste("D:\\RWork\\AllShare\\", Sys.getenv("USERNAME"), sep = "")
sqlCompute <- RxInSqlServer(connectionString = sqlConnString, wait = sqlWait, consoleOutput = sqlConsoleOutput)  
rxSetComputeContext(sqlCompute) 


#This Sample Query Works
source.query <- paste("SELECT CASE WHEN [Order Date Key] = [Picked Date Key]",
                              "THEN 1 ELSE 0 END AS SameDayFulfillment,",
                              "[City Key] AS city, [STOCK ITEM KEY] AS item,",
                              "[PICKER KEY] AS picker, [QUANTITY] AS quantity",
                              "FROM [WideWorldImportersDW].[FACT].[ORDER]",
                              "WHERE [WWI ORDER ID] >= 63968")
#This Query Does Not
q <- paste("EXEC [dbo].[SAMPLE_STORED_PROCEDURE]")
inDataSource <- RxSqlServerData(sqlQuery=q, connectionString=sqlConnString, rowsPerRead=500)
order.logit.rx <- rxLogit(SameDayFulfillment ~ city + item + picker  + quantity, data = inDataSource)
order.logit.rx

1 个答案:

答案 0 :(得分:0)

目前,只允许T-SQL SELECT语句作为输入数据集,而不是存储过程。