2017-07-05 31 views
1

我有這個代碼:曲下載到HDFS

curl -o fileName.csv url | xargs hdfs dfs -moveFromLocal $1 /somePath/ 

當我執行這個代碼,嫋嫋把值從內fileName.csv請求時,文件被移動到HDFS。我想知道是否可以,在內存中保持curl輸出,發送到管道,然後在HDFS中寫入值?

像這樣(的作品):

curl url | xargs hdfs dfs -put $1 /somePath 

回答

4

hdfs dfs -put命令可從標準輸入接受文件的輸入,使用指定-熟悉的成語標準輸入的意思是:

> curl -sS https://www.google.com/robots.txt | hdfs dfs -put - /robots.txt 
> hdfs dfs -ls /robots.txt 
-rw-r--r-- 3 cnauroth supergroup  6880 2017-07-06 09:07 /robots.txt 

另一種選擇是使用shell process substitution允許將curl(或者您真正選擇的任何命令)的stdout視爲輸入到另一個命令的文件:

> hdfs dfs -put <(curl -sS https://www.google.com/robots.txt) /robots.txt 
> hdfs dfs -ls /robots.txt 
-rw-r--r-- 3 cnauroth supergroup  6880 2017-07-05 15:07 /robots.txt 
+2

'put'可以使用'-'讀取stdin。 – philantrovert

+1

@philantrovert,是的,謝謝!非常棒。我忘了這件事。我們只是沒有像'-appendToFile'那樣清楚地記錄下'-put'。我糾正了答案。 –

+0

謝謝你們,完美的作品。 – eduardo