【发布时间】:2020-06-18 14:16:12
【问题描述】:
我与 Athena 建立了 odbc 连接,并且已经能够读取和检索数据。例如,我在 hive 中创建了一个新的空表,它使用与 Athena 的 s3 相同的元存储:
CREATE EXTERNAL TABLE IF NOT EXISTS adhoc.mtcars
(
mpg integer,
cyl integer,
disp integer,
hp integer,
drat integer,
wt integer,
qsec integer,
vs integer,
am integer,
gear integer,
carb integer)
partitioned by (year string, month string, day string)
stored as orc
location 's3://ourco-emr/tables/adhoc.db/mtcars';
我可以使用 DBI::dbReadTable 读取这个新的空表:
con <- dbConnect(odbc(), "Athena")
dbReadTable(con, DBI::Id(schema = "adhoc", table = "mtcars"))
返回:
[1] mpg cyl disp hp drat wt qsec vs am gear carb year month day
<0 rows> (or 0-length row.names)
所以,空表清晰可见。
在 hive create table 中注意以上内容:
location 's3://ourco-emr/tables/adhoc.db/mtcars'
此表的数据应存储在该位置的 s3 中。
我尝试使用 dbWriteTable 将 mtcars 写入此位置:
dbWriteTable(conn = con,
name = "tables/adhoc.db/mtcars",
value = mtcars,
overwrite = FALSE,
append = TRUE,
file.type = "orc",
partition = c(year = "2020", month = "02", day = "01"),
s3.location = "s3://ourco-emr/tables/adhoc.db/mtcars/mtcars")
这似乎在返回此错误消息之前运行了几秒钟:
错误:nanodbc/nanodbc.cpp:1617: 00000: [Simba][Athena] (1040) AWS Athena 客户端引发错误。 Athena 错误编号:130,HTTP 响应代码:400,异常名称:InvalidRequestException,错误消息:第 1:14 行:输入“CREATE TABLE“tables/adhoc.db/mtcars”'[执行 ID:] 处没有可行的替代方案 '创建表“表/adhoc.db/mtcars”( "row_names" VARCHAR(255), “mpg”双精度, “圆柱”双精度, “disp”双精度, “马力”双精度, “drat”双精度, “wt”双精度, “qsec”双精度, “vs”双精度, “我”双精度, “齿轮”双精度, “碳水化合物”双精度 )
看起来 dbi 正在尝试创建一个新表,我只想在其中追加到现有表,尽管我之前创建的表是空的。
如何使用 DBI 向 s3 发送数据帧?
【问题讨论】: