Apache pig script delete a folder if exists

时间:2016-08-31 12:15:56

标签: apache-pig sh

I want to delete the output folder of the previous execution through the apache pig script. This command works fine.

sh [ -e  /home/LocalPig/test ] && rm -rf /home/LocalPig/test

but if I write

sh OutpuFile=/home/LocalPig/test
sh [ -e OutputFile] && rm -rf OutputFile 

I got the error about OutputFile!

ERROR 2997: Encountered IOException. org.apache.pig.tools.parameters.ParameterSubstitutionException: Undefined parameter : OutputFile

Does anybody have any idea?

Thanks

2 个答案:

答案 0 :(得分:1)

希望这可以解决问题。它只是.pig脚本文件中的以下命令。您不必编写任何shell命令。可以使用内置的fs命令在Pig环境中完成此操作。

例如,如下所示在您的Pig脚本中添加一条语句,由于该文件夹不存在,它也不会出错。它将删除该语句是否存在或正常存在。

fs -rm -f -r -R /user/horton/denver_total;

当然,您也可以在猪的外部进行很多工作,但是在控制数据创建的脚本中执行任何删除操作非常有用。跟踪创建和销毁该文件的沿袭,使工作变得更加简单。

答案 1 :(得分:0)

参考:Parameter Substituion

%declare OutputFile '/home/LocalPig/test'
sh [ -e '$OutputFile' ] && rm -rf '$OutputFile'
相关问题