我正在尝试通过JDBC和pool
连接到Amazon Athena:
到目前为止有效:
library(RJDBC)
library(DBI)
library(pool)
library(dplyr)
library(dbplyr)
drv <- RJDBC::JDBC('com.amazonaws.athena.jdbc.AthenaDriver', '/opt/jdbc/AthenaJDBC41-1.1.0.jar')
pool_instance <- dbPool(
drv = drv,
url = "jdbc:awsathena://athena.us-west-2.amazonaws.com:443/",
user = "me",
s3_staging_dir = "s3://somedir",
password = "pwd"
)
mydata <- DBI::dbGetQuery(pool_instance, "SELECT *
FROM myDB.myTable
LIMIT 10")
mydata
---&GT;工作良好。正确的数据正在归还。
这不起作用:
pool_instance %>% tbl("myDB.myTable") %>% head(10)
# Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", :
# Unable to retrieve JDBC result set for SELECT *
# FROM "myDB.myTable" AS "zzz2"
# WHERE (0 = 1) ( Table myDB.myTable not found. Please check your query.)
这里的问题是Athena期望以下语法为SQL:
或者:
SELECT *
FROM "myDB"."myTable"
或者:
SELECT *
FROM myDB.myTable
所以基本上,通过传递字符串"myDB.myTable"
:
pool_instance %>% tbl("myDB.myTable") %>% head(10)
正在使用以下语法:
SELECT *
FROM "myDB.myTable"
导致以下错误,因为此表不存在:
# Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", :
# Unable to retrieve JDBC result set for SELECT *
# FROM "myDB.myTable" AS "zzz6"
# WHERE (0 = 1) ( Table myDB.myTable not found. Please check your query.)
我尝试过:
因此,我试图将"myDB"."myTable"
或myDB.myTable
传递给tbl()
失败:
我尝试使用capture.output(cat('\"myDB\".\"myTable\"'))
:
pool_instance %>% tbl(capture.output(cat('\"myDB\".\"myTable\"'))) %>% head(10)
# Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", :
# Unable to retrieve JDBC result set for SELECT *
# FROM """myDB"".""myTable""" AS "zzz4"
# WHERE (0 = 1) ( Table ""myDB"".""myTable"" not found. Please check your query.)
pool_instance %>% tbl(noquote("myDB"."myTable") %>% head(10)
# Error in UseMethod("as.sql") :
# no applicable method for 'as.sql' applied to an object of class "noquote"
答案 0 :(得分:4)
您可以使用dbplyr::in_schema
:
pool_instance %>% tbl(in_schema("myDB", "myTable")) %>% head(10)