简体   繁体   English

Spark Databricks 本地文件 API

[英]Spark Databricks local file API

I'm trying to build a summary/report of the processing done in spark DataBricks.我正在尝试构建在 spark DataBricks 中完成的处理的摘要/报告。 I came across below piece of code that allows the data to be written to dbfs as well as ADLS(through mount point), but the issue arises when I package the code in jar and try to execute it as a DataBricks job, I get file not found exception and now wondering how to write data into storage with out using notebooks .我遇到了下面的一段代码,它允许将数据写入 dbfs 以及 ADLS(通过挂载点),但是当我将代码打包在 jar 中并尝试将其作为 DataBricks 作业执行时,问题出现了,我得到了文件未发现异常,现在想知道如何在不使用笔记本的情况下将数据写入存储。

    import java.io.File
    import java.io.PrintWriter

    val writer = new PrintWriter(new File("/dbfs/mnt/data/out-01/test-01"))
    writer.write("Hello Developer, Welcome to Programming.")
    writer.write("Hello Developer, Welcome to Programming 2.")
    writer.close()

I came across DButils from DataBricks, but haven't seen any sample code / documentation that I can use.我遇到了来自 DataBricks 的 DButils,但没有看到任何我可以使用的示例代码/文档。 Any help on it will be appreciated.对此的任何帮助将不胜感激。

If your notebook created by the below of the figure below to mount ADLS, yes that you can directly write date to dbfs in the current session of your databricks.如果你的 notebook 是通过下图创建的来挂载 ADLS,是的,你可以在你的数据块的当前会话中直接将日期写入 dbfs。

在此处输入图片说明

So I think the necessary code of DBFS mount points is missing in your code which be packaged to jar file.所以我认为在打包到 jar 文件的代码中缺少 DBFS 挂载点的必要代码。

And please refer to the offical documents as below to see how to access directly ADLS v1 and v2 in your code.请参考以下官方文档,了解如何在代码中直接访问 ADLS v1 和 v2。

  1. Azure Data Lake Storage Gen1 Azure Data Lake Storage Gen1
  2. Azure Data Lake Storage Gen2 Azure Data Lake Storage Gen2

Meanwhile, if without databricks library, you also can change your code using ADLS SDK and REST APIs to write code without using DBFS and run it in databricks.同时,如果没有databricks 库,您也可以使用ADLS SDK 和REST API 更改您的代码,从而无需使用DBFS 编写代码并在databricks 中运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM