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/25 08:07:07 UTC

[jira] [Updated] (PIG-2931) $ signs in the replacement string make parameter substitution fail

     [ https://issues.apache.org/jira/browse/PIG-2931?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Cheolsoo Park updated PIG-2931:
-------------------------------

    Status: Patch Available  (was: Open)
    
> $ signs in the replacement string make parameter substitution fail
> ------------------------------------------------------------------
>
>                 Key: PIG-2931
>                 URL: https://issues.apache.org/jira/browse/PIG-2931
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.10.0
>            Reporter: Cheolsoo Park
>            Assignee: Cheolsoo Park
>             Fix For: 0.11
>
>         Attachments: PIG-2931.patch
>
>
> To reproduce the issue, use the following pig script:
> {code:title=test.pig}
> a = load 'data';
> b = filter by $FILTER;
> {code}
> and run the following command:
> {code}
> pig -x local -dryrun -f test.pig -p FILTER="(\$0 == 'a')"
> {code}
> This generates the following script:
> {code:title=test.pig.substituted}
> a = load 'data';
> b = filter by ($FILTER == 'a');
> {code}
> However this should be:
> {code}
> a = load 'data';
> b = filter by ($0 == 'a');
> {code}
> This is because Pig calls replaceFirst() with a replacement string that include a $ sign as follows:
> {code}
> "$FILTER".replaceFirst("\\$FILTER", "($0 == 'a')"));
> {code}
> To treat $ signs as literals in the replacement string, we must escape them. Please see the [Java doc|http://docs.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html#replaceFirst(java.lang.String)] for Matcher class for explanation:
> {quote}
> Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string.
> {quote}

--
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