【问题标题】:to find duplicate file name in the adls gen 2 location using pyspark databricks使用 pyspark databricks 在 adls gen 2 位置查找重复的文件名
【发布时间】:2020-12-02 16:47:18
【问题描述】:

我正在尝试查找 adls gen 2 位置中是否已经存在同名文件,即 如果同名文件已经存在,我需要检查 adls gen2 位置 例如

abc.csv
def.csv
xyz.csv
abc.csv

因为我们可以看到 abc.csv 存在 2 次,所以它需要通过异常或存在重复文件的消息

【问题讨论】:

  • 在 adls gen2 的给定文件夹中不能有 2 个同名文件。让你的问题非常具体。

标签: pyspark databricks azure-databricks pyspark-dataframes


【解决方案1】:

很遗憾,ADLS Gen2 位置中不能有重复的文件名。

原因: ADLS Gen2 不允许创建已存在的同名文件。

如果要检查文件系统中是否存在文件,请参考以下代码:

from azure.storage.filedatalake import DataLakeFileClient

account_name = 'ADLS_Name'
account_key = 'ADLS_Access_Key'
file_system_name='FileSystem_Name'
file_client = DataLakeFileClient(account_url="{}://{}.dfs.core.windows.net".format(
        "https",
        account_name
    ),
    file_system_name=file_system_name,
    file_path='test.txt',
    credential=account_key 
)

try:
     file_client.get_file_properties()
except Exception as error:
    print(error)    
    if type(error).__name__ =='ResourceNotFoundError':
        print("the path does not exist")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 1970-01-01
    • 2020-07-25
    • 2021-11-25
    • 2021-03-04
    • 2020-06-09
    相关资源
    最近更新 更多