You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pig.apache.org by "Cheolsoo Park (JIRA)" <ji...@apache.org> on 2012/09/11 02:18:07 UTC

[jira] [Commented] (PIG-2810) Error parsing special character during parameter substitution in embedded Python

    [ https://issues.apache.org/jira/browse/PIG-2810?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13452607#comment-13452607 ] 

Cheolsoo Park commented on PIG-2810:
------------------------------------

This is because '=' is a special character in the ParamLoader grammar. ('=' is the <EQUALS> token that splits strings of the form key=value.) As can be seen below, if the first token following <EQUALS> is an <IDENTIFIER> (e.g. a or x), <OTHER> tokens are expected to follow. But '=' is not an <OTHER>, resulting that the rest of chars are not consumed.

{code}
id=<IDENTIFIER>
<EQUALS>
(
    val=<OTHER> { pc.processOrdLine(id.image , val.image);}
    |
    val=<IDENTIFIER> 
    {s = val.image;}
    (
         val =<OTHER>
         {s += val.image;}
    )?
    {pc.processOrdLine(id.image , s);}
    |
    val=<SHELLCMD>  { pc.processShellCmd(id.image , val.image);}
    |
    val=<LITERAL> { s = unquote(val.image); pc.processOrdLine(id.image , s); }
)
{code}

Obvious workarounds are:
- Escape '=' with a backslash. E.g. a \=\= x, x \=\= a, etc.
- Surround the whole expression with parentheses. E.g. (a == x), (x == a), etc.

Given that we have obvious workarounds, I think that it is OK to just document this in the Pig manual.

Please let me know if anyone has a better suggestion. Thanks!
                
> Error parsing special character during parameter substitution in embedded Python
> --------------------------------------------------------------------------------
>
>                 Key: PIG-2810
>                 URL: https://issues.apache.org/jira/browse/PIG-2810
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.9.2, 0.10.0
>            Reporter: Brian Tan
>
> === 1.txt ===
> a, aa
> b, bb
> === 1.pig ===
> a = load '1.txt' using PigStorage(',') as (x:chararray, y);
> b = filter a by $PREDICATE;
> dump b;
> === 1.py ===
> from org.apache.pig.scripting import Pig
> compiled = Pig.compileFromFile('1.pig')
> bound = compiled.bind({
>     'PREDICATE' : r"\'a\' == x"
> })
> results = bound.runSingle()
> The only thing that works is shown above, i.e. \'a\' == x
> If you do any of the following
> a == x
> x == a
> x == 'a'
> x == \'a\'
> Pig will throw syntax error.
> It's getting only the part that's before ==
> i.e. if you have x == a
> then pig instantiates the following code:
> b = filter a by x;

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira