Search code examples
hadoopapache-pighadoop2

Escaping parenthesis in Pig declare statement


enter image description herePIG VERSION: 0.12.0-cdh5.10.1

I am fairly new in using pig. I learned that there are several ways to define parameters in pig. One of them is 'declare' statement. Just wanted to know, if we can use characters like "(" and ")" (parenthesis) in the parameter value. I am trying to save few(variable for different feeds) lookup values in the declare statement which might contain "(" and ")" characters due to which it is throwing error. I also tried to escape these characters using "\" and "\\" but it does not seem to work For example, On running below statement in pig:

%declare DESC 'Joe\\(s URL'

Getting below error on trying to read the same using below command:

sh echo $DESC

ERROR:

2018-02-25 10:11:55,692 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1000: Error during parsing. Lexical error at line 8, column 13.  Encountered: "(" (40), after : ""

But, this approach of escaping is working fine for characters like "%" and "=" which are mentioned on the below page:

https://wiki.apache.org/pig/ParameterSubstitution

Is there any way to escape such characters like "(" and ")" in the declare statement? I noticed the same case is with " ' " also.


Solution

  • It seems as though parentheses don't require escaping in Pig declare statements. See this toy example:

    %declare DESC 'Joe(s URL'
    A = LOAD ...
    B = LIMIT A 2;
    C = FOREACH B GENERATE '$DESC' AS var;
    dump;
    
    (Joe(s URL)
    (Joe(s URL)
    

    I was also able to pass parameters with parentheses to Pig through the command line, e.g.:

    pig -f temp.pig -p DESC='Joe(s URL'