繁体   English   中英

访问来自 Azure Data Lake 敏感存储的数据块文件

[英]Acces file from Azure Data Lake sensitive storage by databricks

我通过以下方法访问普通存储中的文件:

input_path = "my_path"
file= "file.mp3"
path = os.path.join(path_data, file)
full_path = '/dbfs/' + path

with open(full_path, mode='rb') as file: # b is important -> binary
    fileContent = file.read()

我无法在敏感存储中使用相同的方法

我知道敏感存储有另一种访问数据的方式

path_sensitive_storage = 'mypath_sensitive'

如果我使用火花它可以完美地工作,但我有兴趣不使用火花读取而是打开文件

input_df = (spark.read
            .format("binaryFile")
            .option("header", "true")
            .option("encoding", "UTF-8")
            .csv(full_path)
            )

有办法做到这一点吗?

由于您使用 Azure Data Lake 作为源,您需要使用 OAuth 方法将容器挂载到 Databricks DBFS 中。 安装容器后,您可以使用它。

使用下面的代码安装容器。

configs = {"fs.azure.account.auth.type": "OAuth",
       "fs.azure.account.oauth.provider.type": "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider",
       "fs.azure.account.oauth2.client.id": "ba219eb4-0250-4780-8bd3-d7f3420dab6d",
       "fs.azure.account.oauth2.client.secret": "0wP8Q~qWUwGSFrjyByvwK-.HjrHx2EEvG06X9cmy",
       "fs.azure.account.oauth2.client.endpoint": "https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47/oauth2/token",
       "fs.azure.createRemoteFileSystemDuringInitialization": "true"}

dbutils.fs.mount(
source = "abfss://sample11@utrolicstorage11.dfs.core.windows.net/",
mount_point = "/mnt/sampledata11",
extra_configs = configs)

挂载后,您可以使用以下代码列出挂载位置的文件。

dbutils.fs.ls("/mnt/sampledata11/")

最后使用with open语句读取文件

with open("/dbfs/mnt/sampledata11/movies.csv", mode='rb') as file: # b is important -> binary
    fileContent = file.read()
    print(fileContent)

检查下面的图像以获取完整的实现和下面的输出。

在此处输入图像描述

暂无
暂无

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

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