如何将远大前程保存到 Azure Data Lake 或 Blob Store

How to Save an Great Expectation to Azure Data Lake or Blob Store

我正在尝试使用以下代码行将 great_expectations 'expectation_suite 保存到 Azue ADLS Gen 2 或 Blob 存储。

ge_df.save_expectation_suite('abfss://polybase@mipolybasestagingsbox.dfs.core.windows.net/test/newdata/loggingtableupdate.json')

但是,我收到以下错误:

FileNotFoundError: [Errno 2] No such file or directory: 'abfss://polybase@mipolybasestagingsbox.dfs.core.windows.net/test/newdata/loggingtableupdate.json'

下面成功了,但是不知道期望套件保存到哪里:

ge_df.save_expectation_suite('gregs_expectations.json')

如果有人可以让我知道如何保存到 adls gen2 或者让我知道期望保存到哪里,那就太好了

Great expectations 不能直接保存到 ADLS - 它只是使用标准 Python 文件 API,只能用于本地文件。最后一个命令会将数据存储到驱动程序的当前目录中,但您可以显式设置路径,例如 /tmp/gregs_expectations.json.

保存后,第二步就是上传到ADLS。在 Databricks 上,您可以使用 dbutils.fs.cp 将文件放入 DBFS 或 ADLS。如果你不是 运行 在 Databricks 上,那么你可以使用 azure-storage-file-datalake Python package to upload file to ADLS (see its docs for details),像这样:

from azure.storage.filedatalake import DataLakeFileClient

with open('/tmp/gregs_expectations.json', 'r') as file:
    data = file.read()

file = DataLakeFileClient.from_connection_string("my_connection_string", 
                                                 file_system_name="myfilesystem", 
                                                 file_path="gregs_expectations.json")
file.create_file ()
file.append_data(data, offset=0, length=len(data))
file.flush_data(len(data))