@Jon Keane 是正确的。使用col_select
应该可以让你实现这一点。
(conbench2) pace@pace-desktop:~/dev/arrow/r$ /usr/bin/time -v Rscript -e "print(arrow::read_feather('/home/pace/dev/data/feather/big/data.feather', col_select=c('f0', 'f7000', 'f32000'), as_data_frame = FALSE))"
Table
500000 rows x 3 columns
$f0 <int32>
$f7000 <int32>
$f32000 <int32>
Command being timed: "Rscript -e print(arrow::read_feather('/home/pace/dev/data/feather/big/data.feather', col_select=c('f0', 'f7000', 'f32000'), as_data_frame = FALSE))"
User time (seconds): 1.16
System time (seconds): 0.51
Percent of CPU this job got: 150%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.11
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 262660
Average resident set size (kbytes): 0
...
话虽如此,当您的整个文件不适合内存时,羽毛可能不是最好的格式。在这种情况下,即使您指定了内存映射,您仍然必须执行 I/O。如果您一次又一次地重复访问相同的一小组列,那么您应该没问题。它们将很快被加载到页面缓存中,并且 I/O 成本将消失。
另一方面,如果您每次都访问随机列,或者您希望在运行之间有很大的时间间隔(在这种情况下,页面不会在页面缓存中),您可以考虑 parquet。Parquet 将需要更多的 CPU 时间来压缩/解压缩,但应该会减少您需要加载的数据量。当然,对于相对少量的数据(例如该数据集的 0.2%),性能差异可能非常小。即使这样,它也可以节省您的硬盘,因为您描述的表占用了大约 100GB 的空间,并且由于“大多数列是 {NA,1,2}”,我希望数据是高度可压缩的。