简体   繁体   English

从 R 笔记本访问 Azure blob 存储

[英]Access Azure blob storage from R notebook

in python this is how I would access a csv from Azure blobs在 python 中,这是我从 Azure blob 访问 csv 的方式

storage_account_name = "testname"
storage_account_access_key = "..."
file_location = "wasb://example@testname.blob.core.windows.net/testfile.csv"

spark.conf.set(
  "fs.azure.account.key."+storage_account_name+".blob.core.windows.net",
  storage_account_access_key)

df = spark.read.format('csv').load(file_location, header = True, inferSchema = True)

How can I do this in R?我怎样才能在 R 中做到这一点? I cannot find any documentation...我找不到任何文件...

The AzureStor package provides an R interface to Azure storage, including files, blobs and ADLSgen2. AzureStor包为 Azure 存储提供 R 接口,包括文件、blob 和 ADLSgen2。

endp <- storage_endpoint("https://acctname.blob.core.windows.net", key="access_key")
cont <- storage_container(endp, "mycontainer")
storage_download(cont, "myblob.csv", "local_filename.csv")

Note that this will download to a file in local storage.请注意,这将下载到本地存储中的文件。 From there, you can ingest into Spark using standard Sparklyr methods.从那里,您可以使用标准 Sparklyr 方法摄取到 Spark。

Disclaimer: I'm the author of AzureStor.免责声明:我是 AzureStor 的作者。

If you do not want to download it, create a tempfile and then read from it如果您不想下载它,请创建一个临时文件,然后从中读取

   endp <- storage_endpoint("https://acctname.blob.core.windows.net", key="access_key")
   cont <- storage_container(endp, "mycontainer")
   fname <- tempfile()
   storage_download(cont, "myblob.csv", fname)
   df = read.csv(fname)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM