put_file() 函数在 Scala 中?



是否有与 R/Pythonput_file()方法等效的方法,用于从 DSX 中的 Scala 笔记本中获取对象并将其保存为项目的数据资产?如果是这样,是否有任何文档?寻找类似本文概述的内容:
https://datascience.ibm.com/blog/working-with-object-storage-in-data-science-experience-python-edition/
我已经在笔记本中编写了我想要的csv文件,只需要将其保存到项目中即可!

尝试以下步骤和代码片段 -

第 1 步:首先生成凭据。您应该能够通过单击 DSX 中"文件和添加数据"窗格的"文件"选项卡中的"插入到代码>插入 Spark 会话数据帧"来生成它。

def setHadoopConfig2db1c1ff193345c28eaffb250b92d92b(name: String) = {
val prefix = "fs.swift.service." + name
sc.hadoopConfiguration.set(prefix + ".auth.url", "https://identity.open.softlayer.com" + "/v3/auth/tokens")
sc.hadoopConfiguration.set(prefix + ".auth.endpoint.prefix","endpoints")
sc.hadoopConfiguration.set(prefix + ".tenant", "<tenant id>")
sc.hadoopConfiguration.set(prefix + ".username", "<userid>")
sc.hadoopConfiguration.set(prefix + ".password", "<password.")
sc.hadoopConfiguration.setInt(prefix + ".http.port", 8080)
sc.hadoopConfiguration.set(prefix + ".region", "dallas")
sc.hadoopConfiguration.setBoolean(prefix + ".public", false)
}
val name = "keystone"
setHadoopConfig2db1c1ff193345c28eaffb250b92d92b(name)
val data_frame1 = spark.read.option("header","true").csv("swift://'Your 
DSXProjectName'.keystone/<your file name>.csv")

第 2 步:一些代码在说一些转换后从data_frame1创建data_frame2

步骤3:使用相同的容器和项目名称,同时将data_frame2的数据保存到对象存储中的文件

data_frame2.write.option("header","true").csv("swift://'Same DSXproject name as before'.keystone/<name of the file u want to write the data>.csv")

请注意,您可以在步骤 1 中生成凭据,并可以使用它来保存当前笔记本中的任何数据帧,甚至无需从任何文件中读取数据。

最新更新