如何使用Azure Blob存储装载数据?

时间:2019-06-26 13:48:03

标签: python azure azure-storage-blobs azure-blob-storage azure-databricks

我是Azure Databricks的新手,我的导师建议我通过

完成机器学习训练营

https://aischool.microsoft.com/en-us/machine-learning/learning-paths/ai-platform-engineering-bootcamps/custom-machine-learning-bootcamp

不幸的是,成功设置Azure Databricks之后,在步骤2中遇到了一些问题。我成功地将1_01_introduction文件作为笔记本添加到了我的工作区中。但是,尽管本教程讨论了如何在Azure Blob存储中装载数据,但似乎跳过了这一步,这将导致所有后续教程编码步骤均引发错误。下面包括第一个代码位(本教程告诉我运行),以及随后出现的错误。

%run“ ../ presenter / includes / mnt_blob”

找不到笔记本:presenter / includes / mnt_blob。可以通过相对路径(./Notebook或../folder/Notebook)或绝对路径(/ Abs / Path / to / Notebook)指定笔记本。确保您正确指定了路径。

Stacktrace:   / 1_01_简介:python

据我所知,Azure Blob存储尚未设置,因此我运行的代码(以及以下所有步骤中的代码)找不到相应的教程项目。应该存储在blob中。非常感谢您提供的任何帮助。

1 个答案:

答案 0 :(得分:0)

在Azure Databricks中设置和安装Blob存储确实需要执行几个步骤。

首先,在其中create a storage account,然后在create a container

下一步,记下以下各项:

  • 存储帐户名称:创建存储帐户时的名称
  • 存储帐户密钥:可以在资源页面上的Azure门户中找到。
  • 容器名称:容器的名称

在Azure Databricks笔记本中,为上述项目创建变量。

storage_account_name = "Storage account name"
storage_account_key = "Storage account key"
container = "Container name"

然后,使用以下代码将Spark配置设置为指向您的Azure Blob存储实例。

spark.conf.set("fs.azure.account.key.{0}.blob.core.windows.net".format(storage_account_name), storage_account_key)

要将其安装到Azure Databricks,请使用dbutils.fs.mount方法。源是您的Azure Blob存储实例和特定容器的地址。安装点是将其安装在Azure Databricks上的Databricks文件存储中的位置。额外的配置是您在Spark配置中传递的位置,因此不必始终进行设置。

dbutils.fs.mount(
 source = "wasbs://{0}@{1}.blob.core.windows.net".format(container, storage_account_name),
 mount_point = "/mnt/<Mount name>",
 extra_configs = {"fs.azure.account.key.{0}.blob.core.windows.net".format(storage_account_name): storage_account_key}
)

设置好这些后,现在就可以开始使用安装架了。要检查它是否可以查看存储帐户中的文件,请使用dbutils.fs.ls命令。

dbutils.fs.ls("dbfs:/mnt/<Mount name>")

希望有帮助!

相关问题