卷曲下载到HDFS

edu*_*rdo 4 curl hadoop hdfs

我有这个代码:

curl -o fileName.csv url | xargs hdfs dfs -moveFromLocal $1 /somePath/
Run Code Online (Sandbox Code Playgroud)

当我执行这段代码时,curl将请求中的值放在fileName.csv中,文件被移动到HDFS.我想知道我是否可以,保留内存中的curl输出,发送到管道,只是在HDFS中写入值?

像这样的东西(有效):

curl url | xargs hdfs dfs -put $1 /somePath
Run Code Online (Sandbox Code Playgroud)

Chr*_*oth 5

hdfs dfs -put命令可以接受来自stdin的文件输入,使用熟悉的惯用语义-来表示stdin:

> 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
Run Code Online (Sandbox Code Playgroud)

另一种选择是使用shell 进程替换来允许处理stdout curl(或者你选择的任何命令),就像它是另一个命令的文件输入一样:

> 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
Run Code Online (Sandbox Code Playgroud)