gpt4 book ai didi

sql - 如何将原始二进制数据从 R 写入 duckdb?

转载 作者:行者123 更新时间:2023-12-05 05:38:18 27 4
gpt4 key购买 nike

我最好的猜测是 {duckdb} 包目前不支持它,但是我不确定我是否做错了什么/没有按照预期的方式做.这是一个重现(相当不言自明)问题的代表:

con <- DBI::dbConnect(duckdb::duckdb())

# Note: this connection would work fine
# con <- DBI::dbConnect(RSQLite::SQLite())

DBI::dbCreateTable(
conn = con,
name = "raw_test",
fields = list(file = "blob")
)

DBI::dbAppendTable(
conn = con,
name = "raw_test",
value = data.frame(file = I(list(as.raw(1:3)))),
field.types = list(file = "blob")
)

#> Error: rapi_execute: Unsupported column type for scan
#> Error: rapi_register_df: Failed to register data frame: std::exception

注意 (1),我试图找到一种将任意 R 对象写入 SQL 的方法。为此,我计划将有问题的对象序列化为二进制格式,写入 SQL,读回并反序列化。我还想找到一种能够可靠地与尽可能多的 SQL 后端一起工作的方法,因为我正计划创建一个允许用户指定连接的包。

注意 (2),我已将其发布为 issue on the duckdb github因为我觉得这只是一个错误/尚不支持的功能。

编辑#1

我现在更加确信这只是 {duckdb} 的一个错误。来自 DBI::dbDataType() 的文档:

If the backend needs to override this generic, it must accept all basic R data types as its second argument, namely logical, integer, numeric, character, dates (see Dates), date-time (see DateTimeClasses), and difftime. If the database supports blobs, this method also must accept lists of raw vectors, and blob::blob objects.

duckdb 当然支持 blob 类型,据我所知,这些对象应该是可写的。请注意,此代码会产生与上述相同的问题(使用 blob::blob() 而不是 I(list()):

DBI::dbAppendTable(
conn = con,
name = "raw_test",
value = data.frame(file = blob::blob(as.raw(1:3))),
field.types = list(file = "blob")
)

#> Error: rapi_execute: Unsupported column type for scan
#> Error: rapi_register_df: Failed to register data frame: std::exception

我现在将此打开,以防任何好心的 duckdb 开发人员可以确认这是一个错误/缺少的功能,或者是否有人可以提出解决方法。

最佳答案

是的,根据 this issue 这只是一个缺失的功能

关于sql - 如何将原始二进制数据从 R 写入 duckdb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72969276/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com