You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Iván de Prado <iv...@gmail.com> on 2008/09/19 13:08:01 UTC

QuotedString and escaping Quotes

Hello, 

I am having a problem when giving parameters to a load function that
loads data from a database. It receives a SQL query as parameter.
Something like that:

A = LOAD 'dbparams.cfg' USING  DBPigStorage('select if(field is null,
\'null\',field) from table');

But I am having a problem with quotes. I don't know how to escape quotes
in order to insert them into a quotedString. 

I have taken a look to the grammar file:

<quotedstring> := "'"<string>"'"

But doesn't say nothing about string and escaping. Can I escape the
quotes in a quotedstring using "\'"? 

If they are not any escaping in quoted strings, I propose to add
java-like escaping with "\". 

Any other solution?

Thanks, 
Iván de Prado Alonso
www.ivanprado.es



Re: QuotedString and escaping Quotes

Posted by Iván de Prado <iv...@gmail.com>.
Many thanks!

Iván de Prado Alonso	
www.ivanprado.es

El vie, 19-09-2008 a las 10:38 -0700, Alan Gates escribió:
> Alright, I stand corrected.  We did commit a patch to fix this a little 
> while ago.  Do you have the latest stuff from top of trunk.  The 
> definition is now:
> 
> TOKEN : { <QUOTEDSTRING :  "'"
> (   (~["'","\\","\n","\r"])
>   | ("\\"
>       ( ["n","t","b","r","f","\\","'"] )
>     
> )                                                                          
>   | ("\\u"
>         ["0"-"9","A"-"F","a"-"f"]
>         ["0"-"9","A"-"F","a"-"f"]
>         ["0"-"9","A"-"F","a"-"f"]
>         ["0"-"9","A"-"F","a"-"f"]
>     )
> )*     
> "'"> }
> 
> so \' should work.
> 
> Alan.
> 
> Alan Gates wrote:
> > At this point the pig scanner does not escape strings.  If you want to 
> > add backslash escaping I think that would be great.
> >
> > Alan.
> >
> > Iván de Prado wrote:
> >> Hello,
> >> I am having a problem when giving parameters to a load function that
> >> loads data from a database. It receives a SQL query as parameter.
> >> Something like that:
> >>
> >> A = LOAD 'dbparams.cfg' USING  DBPigStorage('select if(field is null,
> >> \'null\',field) from table');
> >>
> >> But I am having a problem with quotes. I don't know how to escape quotes
> >> in order to insert them into a quotedString.
> >> I have taken a look to the grammar file:
> >>
> >> <quotedstring> := "'"<string>"'"
> >>
> >> But doesn't say nothing about string and escaping. Can I escape the
> >> quotes in a quotedstring using "\'"?
> >> If they are not any escaping in quoted strings, I propose to add
> >> java-like escaping with "\".
> >> Any other solution?
> >>
> >> Thanks, Iván de Prado Alonso
> >> www.ivanprado.es
> >>
> >>
> >>   


Re: QuotedString and escaping Quotes

Posted by Alan Gates <ga...@yahoo-inc.com>.
Alright, I stand corrected.  We did commit a patch to fix this a little 
while ago.  Do you have the latest stuff from top of trunk.  The 
definition is now:

TOKEN : { <QUOTEDSTRING :  "'"
(   (~["'","\\","\n","\r"])
  | ("\\"
      ( ["n","t","b","r","f","\\","'"] )
    
)                                                                          
  | ("\\u"
        ["0"-"9","A"-"F","a"-"f"]
        ["0"-"9","A"-"F","a"-"f"]
        ["0"-"9","A"-"F","a"-"f"]
        ["0"-"9","A"-"F","a"-"f"]
    )
)*     
"'"> }

so \' should work.

Alan.

Alan Gates wrote:
> At this point the pig scanner does not escape strings.  If you want to 
> add backslash escaping I think that would be great.
>
> Alan.
>
> Iván de Prado wrote:
>> Hello,
>> I am having a problem when giving parameters to a load function that
>> loads data from a database. It receives a SQL query as parameter.
>> Something like that:
>>
>> A = LOAD 'dbparams.cfg' USING  DBPigStorage('select if(field is null,
>> \'null\',field) from table');
>>
>> But I am having a problem with quotes. I don't know how to escape quotes
>> in order to insert them into a quotedString.
>> I have taken a look to the grammar file:
>>
>> <quotedstring> := "'"<string>"'"
>>
>> But doesn't say nothing about string and escaping. Can I escape the
>> quotes in a quotedstring using "\'"?
>> If they are not any escaping in quoted strings, I propose to add
>> java-like escaping with "\".
>> Any other solution?
>>
>> Thanks, Iván de Prado Alonso
>> www.ivanprado.es
>>
>>
>>   

Re: QuotedString and escaping Quotes

Posted by Alan Gates <ga...@yahoo-inc.com>.
At this point the pig scanner does not escape strings.  If you want to 
add backslash escaping I think that would be great.

Alan.

Iván de Prado wrote:
> Hello, 
>
> I am having a problem when giving parameters to a load function that
> loads data from a database. It receives a SQL query as parameter.
> Something like that:
>
> A = LOAD 'dbparams.cfg' USING  DBPigStorage('select if(field is null,
> \'null\',field) from table');
>
> But I am having a problem with quotes. I don't know how to escape quotes
> in order to insert them into a quotedString. 
>
> I have taken a look to the grammar file:
>
> <quotedstring> := "'"<string>"'"
>
> But doesn't say nothing about string and escaping. Can I escape the
> quotes in a quotedstring using "\'"? 
>
> If they are not any escaping in quoted strings, I propose to add
> java-like escaping with "\". 
>
> Any other solution?
>
> Thanks, 
> Iván de Prado Alonso
> www.ivanprado.es
>
>
>