首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将Azure Data Lake Store gen 2文件共享与Azure Databricks连接?

如何将Azure Data Lake Store gen 2文件共享与Azure Databricks连接?
EN

Stack Overflow用户
提问于 2019-08-26 22:21:48
回答 1查看 1.1K关注 0票数 1

我有一个Azure数据湖存储第二代帐户,启用了分层命名空间。我为帐户生成了SAS令牌,并将数据接收到文件共享(文件服务)中的文件夹。现在我想通过Azure Databricks和python访问这些文件。然而,似乎Azure Databricks只能访问文件系统(在gen1中称为Blob Container ),而不能访问文件共享。我也无法为文件系统生成SAS-token。

我希望有一个存储实例,可以生成SAS令牌并提供给我的客户端,并使用python从azure databricks访问相同的令牌。无论是文件系统、文件共享、ADLS gen2还是gen1都不重要,只要它能以某种方式工作即可。

我使用以下内容从databricks访问文件系统:

代码语言:javascript
复制
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": "my_client_id",
           "fs.azure.account.oauth2.client.secret": "my_client_secret",
           "fs.azure.account.oauth2.client.endpoint": "https://login.microsoftonline.com/"+"My_tenant_id" +"/oauth2/token",
           "fs.azure.createRemoteFileSystemDuringInitialization": "true"}

dbutils.fs.mount(source = "abfss://"+"my_file_system"+"@"+"my_storage_account"+".dfs.core.windows.net/MyFolder",
                 mount_point = "/mnt/my_mount",
                 extra_configs = configs) 

工作正常,但我不能让它访问文件共享。我有一个带有如下连接字符串的SAS-token:

代码语言:javascript
复制
connection_string = (
    'BlobEndpoint=https://<my_storage>.blob.core.windows.net/;'+
    'QueueEndpoint=https://<my_storage>.queue.core.windows.net/;'+
    'FileEndpoint=https://<my_storage>.file.core.windows.net/;'+
    'TableEndpoint=https://<my_storage>.table.core.windows.net/;'+
    'SharedAccessSignature=sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-09-26T17:12:38Z&st=2019-08-26T09:12:38Z&spr=https&sig=<my_sig>'
)

我设法使用它将内容上传到文件共享,但不是上传到文件系统。是否有任何类型的Azure存储可以由SAS-token和azure数据库访问?

EN

回答 1

Stack Overflow用户

发布于 2021-02-27 00:57:34

从databricks连接到azure文件共享的步骤

首先在Databricks中使用pip install安装Microsoft Azure Storage File Share client library for Python。https://pypi.org/project/azure-storage-file-share/

安装后,创建存储帐户。然后,您可以从databricks创建文件共享

代码语言:javascript
复制
from azure.storage.fileshare import ShareClient

share = ShareClient.from_connection_string(conn_str="<connection_string consists of FileEndpoint=myFileEndpoint(https://storageaccountname.file.core.windows.net/);SharedAccessSignature=sasToken>", share_name="<file share name that you want to create>")

share.create_share()

将其用于进一步的参考https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string

通过databricks将文件上传到fileshare的代码

代码语言:javascript
复制
from azure.storage.fileshare import ShareFileClient
 
file_client = ShareFileClient.from_connection_string(conn_str="<connection_string consists of FileEndpoint=myFileEndpoint(https://storageaccountname.file.core.windows.net/);SharedAccessSignature=sasToken>", share_name="<your_fileshare_name>", file_path="my_file")
 
with open("./SampleSource.txt", "rb") as source_file:
    file_client.upload_file(source_file)

有关详细信息,请参阅此链接https://pypi.org/project/azure-storage-file-share/

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57659774

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档