在我的 hadoop 环境中,输出目录是动态创建的。因此,我想动态地读取输出目录,如果存在路径或文件,则执行此操作,否则执行此操作。那么有什么方法可以检查 pig 脚本中的“路径或文件是否存在”??
最佳答案
在 Pig 中,您可以运行 shell 命令来测试路径是否存在,如果存在则返回该路径,否则返回其他始终可用的空数据路径。然后依赖Pig的参数替换。
例如:
%declare emptyPath '/user/me/emptyData.csv'
%declare requestedPath '/user/me/realData.csv'
%declare actualPath `sh -c "hdfs dfs -test -e '$requestedPath '; if [ \\$? -eq 0 ]; then echo '$requestedPath '; else echo '$emptyPath '; fi"`
a = load '$actualPath' using PigStorage(',') as (line:chararray);
关于hadoop - 有没有办法在 pig 脚本中检查 "Path or file exists",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25659202/