2

如何使用 SparklyR 将 SQL 表连接到 R?备忘单显示可以使用DBI::dbWriteTable,但没有提及DBI::dbReadTable。假设我的桌子在这里:

driver = "SQL Server Native Client 11.0"
server = "corsql10.corwin.local"
database = "Project_DB"
table = "Participants"

带有示例代码的响应是首选。谢谢!!

4

1 回答 1

3

Dan,

You can try something like this:

install.packages('devtools')
devtools::install_github('imanuelcostigan/RSQLServer')
require(RSQLServer)
require(dplyr)

src <- RSQLServer::src_sqlserver("corsql10.corwin.local", database = "Project_DB")
data <- tbl(src, "Participants")

DBI::dbWriteTable(sc, "spark_Participants", data)

First, define the data source from SQL Server. Second, write it to Spark. tbl should create a reference to the SQL Server table without loading it into memory. It looks like the RSQLServer package is not well maintained and CRAN took it down because the author didn't fix its bugs... So you will have to trouble shoot it. Here is a good resource: Accessing MSSQL Server with R

于 2017-05-05T02:01:44.323 回答