gpt4 book ai didi

python - 如何从 Azure ADLS Gen 1 在 Azure 机器学习工作室中注册特定版本的增量表?

转载 作者:行者123 更新时间:2023-12-02 05:59:15 24 4
gpt4 key购买 nike

我在 Databricks 中使用以下代码在 ADLS Gen 1 中创建了一个增量表:

df.write.format("delta").mode("overwrite").saveAsTable("db.my_tbl", path ='adl://organisation.azuredatalakestore.net/folder_name/my_data')

有时,我会重新运行上面的代码来生成新版本的 my_tbl 表。与增量表一样,会构建历史记录,并且必须定期对其进行优化和清理。现在,我经常在 Azure 机器学习工作室中重新训练 ML 模型,并且想知道是否可以注册特定版本的增量表?

目前,即使在清理后,从 my_data 文件夹读取 parquet 文件时,我的所有增量文件(包括旧版本)都会在 Azure ML Studio 中注册!这是因为除了打开 spark.databricks.delta.retentionDurationCheck.enabled 之外,我无法将增量表的保留期降低到 168 小时以下。我不想将其关闭。

我通过 ML Studio 界面将数据集注册为文件数据集(不是表格数据集)。此注册如下所示:

enter image description here

现在我只看到创建 my_data 副本并读取它的选项。还有别的办法吗?您知道我是否可以在路径中指定某些内容来指向“正确的”.parquet 文件(属于特定的增量表版本)?

最佳答案

如果您使用 Databricks 并且不介意在移动文件夹时采取一些解决方法,这里有一个基于 manifest files 的解决方案。此脚本列出了最新增量表版本的所有文件。它可用于具有增量数据更新的管道。

spark.conf.set("spark.databricks.delta.symlinkFormatManifest.fileSystemCheck.enabled", False) # this type of filesystemcheck is an AWS feature currently, so it needs to be disabled on Azure or Google Cloud

from delta.tables import DeltaTable

delta_path=<'full path in data lake pointing to your table'> # note your Databricks workspace needs WRITE access for the data lake!

newpath=<'folder outside delta table'>

delta_table = DeltaTable.forPath(spark, f"{delta_path}")

#clean up existing folder to be on the safe side
dbutils.fs.rm(f"{newpath}/_symlink_format_manifest", recurse=True)

manifest = delta_table.generate("symlink_format_manifest")

# The automatically created symlink folder needs to be moved out from the delta path!
# Otherwise spark import will not recognize the format, as a usual delta table is expected under this path. The symlink_format_manifest is not a correct delta table partition!

dbutils.fs.mv(f"{delta_path}/_symlink_format_manifest", f"{newpath}/_symlink_format_manifest", recurse=True)

# create the list of parquet files from the manifest
filelist=spark.read.text(f"{newpath}/_symlink_format_manifest/*").rdd.flatMap(lambda x: x).collect()

filelist

关于python - 如何从 Azure ADLS Gen 1 在 Azure 机器学习工作室中注册特定版本的增量表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70187921/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com