fst – Fast STorage 파일

Published by onesixx on

Serialization of dataFrames (in a fast, easy and flexible way)

https://cran.r-project.org/web/packages/fst/index.html   0.8.4
https://cran.r-project.org/web/packages/fst/fst.pdf
http://www.fstpackage.org/
nOfrows <- 1e6
DT <- data.table( Logical=sample(c(T,F,NA),              nOfrows, replace = TRUE, prob=c(0.7,0.1,0.2)),
                  Integer=sample(1L:100L,                nOfrows, replace = TRUE),
                  Real   =sample(sample(1:10000,20)/100, nOfrows, replace = TRUE),
                  Factor =sample(labels(UScitiesD),      nOfrows, replace = TRUE) %>% as.factor())

fst파일로 저장 (to disk)

BASE_PATH <- "~/data/"
write.fst(DT, str_c(BASE_PATH,"dataset.fst"))
write.fst(DT, str_c(BASE_PATH,"dataset1.fst"), compress=100, uniform_encoding=T)

Compression

압축은 type에 따라 필터를 통해 LZ4 와 ZSTD 알고리즘을 사용하고 이를 통해 fst는 높은 압축율과 속도를 얻을 수 있다. compress 옵션을 통해 0 (minimum) 부터 100 (maximum)까지의 압축률을 설정할수 있으며,
압축/압축해제시 Background threads를 사용하기 때문에 총 read/write 속도 또한 증가될수 있다

Retrieve the data frame 

DT0 <- read.fst(str_c(BASE_PATH,"dataset.fst")) %>% data.table
identical(DT, DT0)    #TRUE

DT_subset <- read.fst(str_c(BASE_PATH,"dataset.fst"), c("Logical","Factor"), from=2000, to=5000) %>% data.table

Random access

fst file 포멧은 full random access를 제공하여 저장된 data를 읽어드리기 때문에 속도가 빠르다.
또한 column과 row를 선택하여 읽을수 있다. 즉 RDS와 다르게 선택적으로 subset을 만들수 있따.

Categories: Reshaping

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x