【发布时间】:2017-07-20 09:46:54
【问题描述】:
我在 HDFS 中的文件夹路径结构是这样的:
/data/topicname/year=2017/month=02/day=28/hour=00
/data/topicname/year=2017/month=02/day=28/hour=01
/data/topicname/year=2017/month=02/day=28/hour=02
/data/topicname/year=2017/month=02/day=28/hour=03
在这些路径中,我有许多小尺寸的 json 文件。我正在编写一个 shell 脚本,它可以根据路径将所有这些单独目录中存在的所有文件合并为一个单独的文件名。
例子:
/data/topicname/year=2017/month=02/day=28/hour=00 中的所有 JSON 到一个合并文件 full_2017_02_28_00.json 中
/data/topicname/year=2017/month=02/day=28/hour=01 中的所有 JSON 到一个合并文件 full_2017_02_28_01.json 中
/data/topicname/year=2017/month=02/day=28/hour=02 内的所有 JSON 合并到一个合并文件 full_2017_02_28_02.json 等。
保持上述模式中的文件名是我将尝试实现的次要工作。目前我可以硬编码文件名。
但是,目录路径结构内的递归连接并没有发生。
到目前为止,我已经尝试过:
hadoop fs -cat /data/topicname/year=2017/* | hadoop fs -put - /merged/test1.json
错误:-
cat: `/data/topicname/year=2017/month=02/day=28/hour=00': Is a directory
cat: `/data/topicname/year=2017/month=02/day=28/hour=01': Is a directory
cat: `/data/topicname/year=2017/month=02/day=28/hour=02': Is a directory
上述尝试中没有发生递归猫
hadoop fs -ls /data/topicname/year=2017/month=02 | find /data/topicname/year=2017/month=02/day=28 -name '*.json' -exec cat {} \; > output.json
错误:-
find: ‘/data/topicname/year=2017/month=02/day=28’: No such file or directory
在上述尝试中,它是在本地 FS 而不是 HDFS 中查找
for i in `hadoop fs -ls -R /data/topicname/year=2017/ | cut -d' ' -f19` ;do `hadoop fs -cat $i/* |hadoop fs -put - /merged/output.json`; done
错误:-
cannot write output to stream message is repeated multiple times
file /merged/output.json is repeated a few times
这是如何实现的?我不想使用 Spark。
【问题讨论】: