Spark學習 檔案讀取路徑)

2021-07-23 10:07:08 字數 652 閱讀 1937

在不同的啟動模式下,載入檔案時的路徑寫法是不一樣的,對於local模式下,預設就是讀取本地檔案,而在standlone或者yarn-client,或者cluster模式下,預設讀的都是hdfs檔案系統,這幾種模式下很難讀取本地檔案(這是很顯然的事情,但你可以通過指定節點的檔案服務曲線救國)。

下面的**在local模式下有效,在其它模式下無效:

var thep1 = sc.textfile("file:///usr/test/people.json")  //讀取本地

var thep2 = sc.textfile("hdfs:") //讀取hdfs檔案

下面的**在非local模式下,都是讀取的hdfs,file://模式無效.

var thep1 = sc.textfile("/usr/test/people.json") 

var thep2 = sc.textfile("/user/root/test/test/people.json")

下面這個語句在幾種模式下都有效

var thep2 = sc.textfile("hdfs:") //讀取hdfs檔案

在非local模式下等同於

var thep2 = sc.textfile("/user/root/test/test/people.json")



Python學習 檔案讀取

coding utf 8 created on sat jul 27 16 00 57 2019 author cc 檔案操作 開啟當前目錄下檔案 with會在不需要訪問檔案後將其關閉,避免使用close 關閉 rstrip 函式用於刪除多餘的換行符 with open digits.txt as ...

Spark讀取檔案

spark預設讀取的是hdfs上的檔案。如果讀取本地檔案,則需要加file usr local spark readme.md。測試時候發現,本地檔案必須在spark的安裝路徑內部或者平行 讀取hdfs檔案,可以這樣指定路徑 hdfs ns1 tmp test.txt。如果不指定任何字首,則使用hd...

Spark讀取檔案

spark預設讀取的是hdfs上的檔案。如果讀取本地檔案,則需要加file usr local spark readme.md。測試時候發現,本地檔案必須在spark的安裝路徑內部或者平行 讀取hdfs檔案,可以這樣指定路徑 hdfs ns1 tmp test.txt。如果不指定任何字首,則使用hd...