2017-07-05 29 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