You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pig.apache.org by "Prashant Kommireddi (JIRA)" <ji...@apache.org> on 2013/03/19 00:15:15 UTC

[jira] [Commented] (PIG-3110) pig corrupts chararrays with trailing whitespace when converting them to long

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

Prashant Kommireddi commented on PIG-3110:
------------------------------------------

I think the difference between Double and Integer/Long behavior here is that the former handles whitespaces. Here is a snippet from Double.java

{code}
    public static FloatingDecimal
    readJavaFormatString( String in ) throws NumberFormatException {
        boolean isNegative = false;
        boolean signSeen   = false;
        int     decExp;
        char    c;

    parseNumber:
        try{
            in = in.trim(); // don't fool around with white space.
{code}

Another reason we use Double is for conversion from floating points.

Is there a reason other than these we use Double? I think case 1 (whitespace) could be handled in pig code rather than having to use Double and then converting it back to Integer/Long. PIG-2835 added sanityCheckIntegerLong(String s) for performance reasons. Trimming whitespace in addition to that should handle the issue described in this JIRA.
                
> pig corrupts chararrays with trailing whitespace when converting them to long
> -----------------------------------------------------------------------------
>
>                 Key: PIG-3110
>                 URL: https://issues.apache.org/jira/browse/PIG-3110
>             Project: Pig
>          Issue Type: Bug
>          Components: data
>    Affects Versions: 0.10.0
>            Reporter: Ido Hadanny
>
> when trying to convert the following string into long, pig corrupts it. data:
> 1703598819951657279 ,44081037
> data1 = load 'data' using CSVLoader as (a: chararray ,b: int);
> data2 = foreach data1 generate (long)a as a;
> dump data2;
> (1703598819951657216)    <--- last 2 digits are corrupted
> data2 = foreach data1 generate (long)TRIM(a) as a;
> dump data2;
> (1703598819951657279)    <--- correct

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