【发布时间】:2016-11-03 14:25:12
【问题描述】:
概述
我想使用 SQL R Services 调用 API 并将数据直接拉入 SQL Server。我一直在尝试在 R 中使用 jsonlite 和 curl,它在 R GUI 中是成功的,但是在通过 SQL Server T-SQL 进行调用时失败。
R 脚本
library(jsonlite,curl);
citibike <- fromJSON('http://citibikenyc.com/stations/json');
stations <- citibike$stationBeanList;
stations[,c(2,10)];
SQL 脚本
DECLARE @Rscript NVARCHAR(MAX);
SET @Rscript = N'library(jsonlite, curl);
citibike <- fromJSON('+''''+'http://citibikenyc.com/stations/json'+''''+');
stations <- citibike$stationBeanList;
OutputDataSet <- subset(stations, select=c("stationName", "stAddress1"))';
EXEC sp_execute_external_script
@language = N'R',
@script = @Rscript
WITH RESULT SETS(([stationName] VARCHAR(500), [stAddress1] VARCHAR(500)));
SQL 错误
Msg 39004, Level 16, State 20, Line 0
A 'R' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 1, Line 0
An external script error occurred:
Error in open.connection(con, "rb") : Couldn't connect to server
Calls: source ... fromJSON_string -> parseJSON -> parse_con -> open -> open.connection
In addition: Warning message:
package 'jsonlite' was built under R version 3.3.2
Error in ScaleR. Check the output for more information.
Error in eval(expr, envir, enclos) :
Error in ScaleR. Check the output for more information.
Calls: source -> withVisible -> eval -> eval -> .Call
Execution halted
Msg 11536, Level 16, State 1, Line 8
EXECUTE statement failed because its WITH RESULT SETS clause specified 1 result set(s), but the statement only sent 0 result set(s) at run time.
问题
我是否应该考虑另一种方法,或者是否有一些简单的错误阻止了它在 SQL R Services 中的工作?
【问题讨论】:
-
请注意,
library(jsonlite,curl)仅加载jsonlite。 -
是的,我并不是在暗示这是您的问题的根源,而是值得修复的额外问题。
标签: sql-server json r curl jsonlite