2017-07-18 45 views
0

在DSX中從Scala筆記本中獲取對象並將其保存爲項目的數據資產時,是否有與R/Python put_file()方法等價的方法?如果是的話是否有任何文件?尋找類似於這篇文章中概述的內容:
https://datascience.ibm.com/blog/working-with-object-storage-in-data-science-experience-python-edition/
我已經在筆記本中編寫了我想要的csv文件,只需將其保存到項目中即可!put_file()函數在Scala中?

+0

您是否試圖將DSX中的spark數據框保存爲scala中的對象存儲? 如果是,則爲spark 2.0語法 spark.write.csv() –

回答

0

嘗試下面的步驟和代碼片段 -

步驟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中生成憑證,並且可以使用它來保存當前筆記本中的任何數據框,而無需從任何文件讀取數據。