首页 > 解决方案 > Databrick 连接到 ADLS Gen2 文本文件

问题描述

我正在使用数据块来访问我的 ADLS Gen2 容器。

dbutils.fs.mount(
  source = "wasbs://<container-name>@<storage-account-name>.blob.core.windows.net",
  mount_point = "/mnt/<mount-name>",
  extra_configs = {"<conf-key>":dbutils.secrets.get(scope = "<scope-name>", key = "<key-name>")})

我正在使用以下代码并更改我需要更改的内容。

当我运行脚本时,出现以下错误

df = spark.read.text("/mnt/<mount-name>/...")
shaded.databricks.org.apache.hadoop.fs.azure.AzureException: shaded.databricks.org.apache.hadoop.fs.azure.AzureException: Container <container name> in account <storage account name>.blob.core.windows.net not found, and we can&#39;t create it using anoynomous credentials, and no credentials found for them in the configuration.

我在我的应用程序注册中注册了数据块,并将名称添加到我的 ADLS 角色中作为存储 Blob 数据贡献者。

我不确定为什么我的凭据不允许我提取我的 ADLS 帐户中的文本文件。

任何帮助表示赞赏!

标签: databricksazure-databricksazure-data-lakeazure-data-lake-gen2databricks-connect

解决方案


我试图重现这个问题,它对我来说工作正常。我跟着这个教程

请在下面找到 databrick 笔记本片段:

在此处输入图像描述

您可以考虑相同的代码示例。如下请见:

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": "<appId>",
       "fs.azure.account.oauth2.client.secret": "<clientSecret>",
       "fs.azure.account.oauth2.client.endpoint": "https://login.microsoftonline.com/<tenant>/oauth2/token",
       "fs.azure.createRemoteFileSystemDuringInitialization": "true"}

dbutils.fs.mount(
source = "abfss://<container-name>@<storage-account-name>.dfs.core.windows.net/folder1",
mount_point = "/mnt/flightdata",
extra_configs = configs)

在此代码块中,将此代码块中的appIdclientSecrettenantstorage-account-name占位符值替换为您在完成先决条件时收集的值。将container-name占位符值替换为容器的名称。

请考虑以下几点:

  1. 确保您的容器和存储帐户名称正确。
  2. 必须完成教程页面中提到的所有先决条件。用户拥有所有必需的权限。

推荐阅读