【问题标题】:Spark dataframe(in Azure Databricks) save in single file on data lake(gen2) and rename the fileSpark 数据框(在 Azure Databricks 中)保存在数据湖(gen2)上的单个文件中并重命名文件
【发布时间】:2020-01-24 15:24:09
【问题描述】:

我正在尝试实现与此 SO 帖子 Spark dataframe save in single file on hdfs location 相同的功能,但我的文件位于 Azure Data Lake Gen2 中,并且我在 Databricks 笔记本中使用 pyspark。

下面是我用来重命名文件的代码sn-p

from py4j.java_gateway import java_import
java_import(spark._jvm, 'org.apache.hadoop.fs.Path')

destpath = "abfss://" + contianer + "@" + storageacct + ".dfs.core.windows.net/"
fs = spark._jvm.org.apache.hadoop.fs.FileSystem.get(spark._jsc.hadoopConfiguration())
file = fs.globStatus(sc._jvm.Path(destpath+'part*'))[0].getPath().getName()
#Rename the file

我在这条线上收到IndexError: list index out of range

file = fs.globStatus(sc._jvm.Path(destpath+'part*'))[0].getPath().getName()

part* 文件确实存在于文件夹中。

1) 这是重命名 databricks(pyspark) 写入 Azure DataLakeGen2 的文件的正确方法,如果不是,我还能如何完成此操作?

【问题讨论】:

    标签: apache-spark pyspark databricks azure-data-lake-gen2


    【解决方案1】:

    我可以通过在我的 databricks 笔记本中安装 azure.storage.filedatalake client 库来解决此问题。通过使用 FileSystemClient 类和 DataLakeFileClient 类,我能够重命名数据湖 gen2 中的文件。

    【讨论】:

      猜你喜欢
      • 2019-06-03
      • 2022-08-21
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 2021-03-26
      相关资源
      最近更新 更多