我可以使用DBI写入s3上的Athena表吗?

问题描述 投票:0回答:1

我与Athena建立了odbc连接,并且已经能够读取和检索数据。例如,我在Hive中创建了一个新的空表,该表使用与雅典娜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)

因此,空表清晰可见并可见。

注意上面的配置单元创建表中的内容:

location 's3://ourco-emr/tables/adhoc.db/mtcars'

此表的数据应存储在该位置的s3中。

我尝试使用dbWriteTable将mtcar写入此位置:

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] [雅典娜](1040)从AWS Athena客户端引发了一个错误。雅典娜错误编号:130,HTTP响应代码:400,异常名称:InvalidRequestException,错误消息:第1:14行:输入“ CREATE TABLE“ tables / adhoc.db / mtcars””处没有可行的替代方法[执行ID:]'创建表“ tables / adhoc.db / mtcars”(“ row_names” VARCHAR(255),“ mpg”双精度,“圆柱”双精度,“显示”双精度,“ hp”双精度,“双精度”,“ wt”双精度,“ qsec”双精度,“ vs”双精度,“是”双重精度,“齿轮”双精度,“碳水化合物”的双精度)

看起来dbi试图创建一个新表,我只想在其中添加到现有表,尽管之前创建的表是空的。

如何使用DBI将数据帧发送到s3?

r amazon-s3 dbi rodbc
1个回答
0
投票

我无法对odbc进行评论,但是有两个软件包RAthenaRAthena具有noctua方法用于将数据上传到AWS Athena。

noctua利用Python SDK DBI创建与AWS的连接。 RAthena利用R SDK boto3创建与AWS的连接。

noctua

当前,这些软件包在上传到AWS Athena时仅支持paws [“ tsv”,“ csv”,“ parquet”]。要扩展当前软件包的功能,请在library(DBI) # connect to AWS Athena using RAthena con = dbConnect(RAthena::athena()) # OR connect to AWS Athena using noctua con = dbConnect(noctua::athena()) # Uploading to existing AWS Athena table dbWriteTable(conn = con, name = "adhoc.mtcars", value = mtcars, append = TRUE, file.type = "parquet", partition = c(year = "2020", month = "02", day = "01"), s3.location = "s3://ourco-emr/tables/") dbGetQuery(con, "select * from adhoc.iris") file.types处提出功能请求。

注意:请勿在相同的环境中加载两个软件包,因为连接类会发生冲突。

© www.soinside.com 2019 - 2024. All rights reserved.