如何将带有空格的命令行参数传递给 apache pig 脚本? [英] How can I pass command-line parameters with whitespace to an apache pig script?
问题描述
我想编写一个将过滤条件作为命令行参数的猪脚本.从命令行我想输入如下内容:
I want to write a pig script that takes a filter condition as a command line parameter. From the command line I want to type something like:
pig -p "MY_FILTER=field1 == 0 and field2 == 5" myscript.pig
在我的脚本中有一行:
my_filtered_data = filter my_data by $MY_FILTER;
当 MY_FILTER
没有空格并且我在我的值周围传递引号时,这会按预期工作;因此,如果我在命令行输入 MY_FILTER=\"field1==0\"
,shell 将传递带有值的引号,而 pig 进行我想要的扩展.但是,如果我像 MY_FILTER=\"field1 == 0\"
This works as expected when MY_FILTER
has no spaces and I pass quotes around my value; So if I type MY_FILTER=\"field1==0\"
at the command line the shell will pass the quotes with the value and pig does the expansion I want. However, the parameter will fail to expand if I supply it like MY_FILTER=\"field1 == 0\"
我尝试了很多不同的引用技术,甚至尝试直接从 python 的 subprocess 模块运行命令以确保我的 shell 没有做一些奇怪的事情.
I've tried a bunch of different quoting techniques and even tried running the command directly from python's subprocess module to ensure my shell wasn't doing something weird.
推荐答案
您使用哪个版本的 Pig?我使用 0.9.2,以下命令对我有用:
Which version of Pig do you use? I use 0.9.2 and the following command works for me:
pig -p "F='field1 == 3 AND field2 == 5'" test.pig
但它不适用于 0.8.1.
But it doesn't work with 0.8.1.
这篇关于如何将带有空格的命令行参数传递给 apache pig 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!