hive-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Dai (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HIVE-15416) CAST to string does not work for large decimal numbers
Date Wed, 21 Dec 2016 19:29:58 GMT

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

Daniel Dai commented on HIVE-15416:
-----------------------------------

You should use the following statement instead:
select CAST(decimal_col AS VARCHAR(38)) from test_hive_bug30;
The reason is UDFToString inherits UDF rather than GenericUDF. According to https://cwiki.apache.org/confluence/download/attachments/27362075/Hive_Decimal_Precision_Scale_Support.pdf,
UDF does not support decimal with precision/scale and always assume maximum precision and
scale. GenericUDFToVarchar address precision and scale gracefully.

> CAST to string does not work for large decimal numbers
> ------------------------------------------------------
>
>                 Key: HIVE-15416
>                 URL: https://issues.apache.org/jira/browse/HIVE-15416
>             Project: Hive
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>            Reporter: Pavel Benes
>
> The cast of large decimal values to string does not work and produces NULL values. 
> Steps to reproduce:
> {code}
> hive> create table test_hive_bug30(decimal_col DECIMAL(30,0));
> OK
> {code}
> {code}
> hive> insert into test_hive_bug30 VALUES (123), (99999999999999999999999999999), (999999999999999999999999999999),(9999999999999999999999999999999);
> Query ID = benesp_20161212135717_5d16d7f4-7b84-409e-ad00-36085deaae54
> Total jobs = 1
> Launching Job 1 out of 1
> Status: Running (Executing on YARN cluster with App id application_1480833176011_2469)
> --------------------------------------------------------------------------------
>         VERTICES      STATUS  TOTAL  COMPLETED  RUNNING  PENDING  FAILED  KILLED
> --------------------------------------------------------------------------------
> Map 1 ..........   SUCCEEDED      1          1        0        0       0       0
> --------------------------------------------------------------------------------
> VERTICES: 01/01  [==========================>>] 100%  ELAPSED TIME: 7.69 s
> --------------------------------------------------------------------------------
> Loading data to table default.test_hive_bug30
> Table default.test_hive_bug30 stats: [numFiles=1, numRows=4, totalSize=68, rawDataSize=64]
> OK
> Time taken: 8.239 seconds
> {code}
> {code}
> hive> select CAST(decimal_col AS STRING) from test_hive_bug30;
> OK
> 123
> NULL
> NULL
> NULL
> Time taken: 0.043 seconds, Fetched: 4 row(s)
> {code}
> The numbers with 29 and 30 digits should be exported, but they are converted to NULL
instead. 
> The values are stored correctly as can be seen here:
> {code}
> hive> select * from test_hive_bug30;
> OK
> 123
> 99999999999999999999999999999
> 999999999999999999999999999999
> NULL
> Time taken: 0.447 seconds, Fetched: 4 row(s)
> {code}
> The same issue does not exists for smaller numbers (e.g. DECIMAL(10)).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message