R 中的数据表包是否支持超过 2^31 行的数据表?

wol*_*oor 8 merge r cross-join data.table apache-arrow

我正在尝试进行交叉连接(来自此处的原始问题),并且我有 500GB 的内存。问题是最后的data.table行数超过 2^31 行,所以我收到此错误:

Error in vecseq(f__, len__, if (allow.cartesian || notjoin || !anyDuplicated(f__,  : 
  Join results in more than 2^31 rows (internal vecseq reached physical limit). Very likely misspecified join. Check for duplicate key values in i each of which join to the same group in x over and over again. If that's ok, try by=.EACHI to run j for each group to avoid the large allocation. Otherwise, please search for this error message in the FAQ, Wiki, Stack Overflow and data.table issue tracker for advice.
Run Code Online (Sandbox Code Playgroud)

有没有办法覆盖这个?当我添加时by=.EACHI,我收到错误:

  'by' or 'keyby' is supplied but not j
Run Code Online (Sandbox Code Playgroud)

我知道这个问题不是理想的可重现格式(我很抱歉!),但我不确定这对于答案来说是绝对必要的。也许我只是错过了一些东西或者受到这种方式的限制?

我只知道2013年的这个问题,这似乎表明data.table当时无法做到这一点。

这是导致错误的以下代码:

  pfill=q[, k:=t+1][q2[, k:=tprm], on=.(k), nomatch=0L,allow.cartesian=TRUE][,k:=NULL]
Run Code Online (Sandbox Code Playgroud)

Wal*_*ldi 9

由于data.table似乎仍然仅限于2^31行,您可以作为解决方法使用arrow 与 dplyr 结合来克服此限制:

library(arrow)
library(dplyr)

# Create 3 * 2^30 rows feathers
dt <-data.frame(val=rep(1.0,2^30))
write_feather(dt, "test/data1.feather")
write_feather(dt, "test/data2.feather")
write_feather(dt, "test/data3.feather")

# Read the 3 files in a common dataset
dset <- open_dataset('test',format = 'feather')

# Get number of rows
(nrows <- dset %>% summarize(n=n()) %>% collect() %>% pull)
#integer64
#[1] 3221225472

# Check that we're above 2^31 rows
nrows / 2^31
#[1] 1.5
Run Code Online (Sandbox Code Playgroud)

  • 答案是创建一个超过 2^31 行的对象,但该对象不是“data.frame”或“data.table”。因此,它似乎或多或少地错过了这个问题。 (3认同)
  • @DirkEddelbuettel,这是对OP要求解决方法的回答,允许对大量行进行数据操作。它可能会填补“data.table”行限制和大数据操作之间的空白,例如 [sparklyr](https://spark.rstudio.com/) (3认同)