You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pig.apache.org by "Daniel Dai (JIRA)" <ji...@apache.org> on 2013/01/09 07:44:13 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=13547697#comment-13547697 ] 

Daniel Dai commented on PIG-3110:
---------------------------------

Here is the code introduce the issue:
{code}
			try {
				return Long.parseLong(str);
			} catch (NumberFormatException e) {
				try {
					Double d = Double.valueOf(str);
					// Need to check for an overflow error
					if (d.doubleValue() > mMaxLong.doubleValue() + 1.0) {
						LogUtils.warn(CastUtils.class, "Value " + d
								+ " too large for long",
								PigWarning.TOO_LARGE_FOR_INT, mLog);
						return null;
					}
					return Long.valueOf(d.longValue());
				}
                         }
{code}
Not sure why we still try double, seems adding more confusion. Shall we change?
                
> 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