首页 > 解决方案 > 从 r 中的 Azure blob 解压缩 .gz 文件

问题描述

我想从 Azure blob 容器中读取 .csv.gz,但我正在为 .gz 格式而苦苦挣扎。当我在本地下载文件然后用 R 在 R 中读取它时,它工作正常。但是当我尝试从 Azure 中读取它时,该文件没有正确读取。文件似乎没有解压缩。这是我用来读取本地文件的代码(read_csv2 也可以正常工作):

df<-read_delim("filename.csv.gz", delim=";",col_names=c('epoch','SegmentID','TT','Speed','LoS','Coverage'),
                    col_types=cols(epoch = col_integer(),SegmentID = col_integer(),TT = col_integer(),Speed = col_integer(),LoS = col_integer(),Coverage = col_integer()))

这就是我尝试从 Azure 获取文件的方法:

blob_urls_with_sas<-paste("https://name.blob.core.windows.net","/container/filename.csv.gz",
                          sas_token, sep="")
dfAzure<-read_delim(blob_urls_with_sas,delim=";",
col_names=c('epoch','SegmentID','TT','Speed','LoS','Coverage'),
                col_types=cols(epoch = col_integer(),SegmentID = col_integer(),TT = col_integer(),
                               Speed = col_integer(),LoS = col_integer(),Coverage =col_integer()))

或来自 AzureStor 包

test <- storage_read_delim(cont, "filename.csv.gz",delim=";",
col_names=c('epoch','SegmentID','TT','Speed','LoS','Coverage'),                           col_types=cols(epoch = col_integer(),SegmentID = col_integer(),TT = col_integer(),
                       Speed = col_integer(),LoS = col_integer(),Coverage = col_integer()))

标签: razure-storagegzip

解决方案


一种选择是使用自然处理文件fread()的 data.table 。.gz确保您R.utils先安装。


推荐阅读