【问题标题】:Is there any method in dbutils to check existence of a file, something like dbutils.fs.exits?dbutils 中是否有任何方法可以检查文件是否存在,例如 dbutils.fs.exits?
【发布时间】:2019-07-23 06:34:43
【问题描述】:

我想检查某个位置是否存在,比如 /dbfs/FileStore/tables/xyz.json 是否存在。如果是,则该方法应返回 true。我检查了 dbutils 中的方法,但似乎没有找到任何方法。另外,我无法在 ADLS 中安装任何位置。有哪些方法以及如何解决它?

【问题讨论】:

    标签: scala apache-spark databricks azure-databricks


    【解决方案1】:

    一种检查方法是使用 dbutils.fs.ls。

    举个例子吧。

    check_path = 'FileStore/tables/'
    check_name = 'xyz.json'
    
    files_list = dbutils.fs.ls(check_path)
    files_sdf = spark.createDataFrame(files_list)
    result = files_sdf.filter(col('name') == check_name)
    

    然后你可以使用 .count() 或 .show() 来得到你想要的。

    对于第二个问题,您能否详细说明无法安装的含义?

    【讨论】:

    • 用户想知道只使用 DButils 的解决方案,这是 DBFS 特有的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-18
    • 1970-01-01
    • 2018-04-02
    • 2013-06-16
    • 2011-01-17
    相关资源
    最近更新 更多