[
https://issues.apache.org/jira/browse/HIVE-15416?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Pavel Benes updated HIVE-15416:
-------------------------------
Comment: was deleted
(was: [~daijy] Thanks for your reply, I can confirm the approach you describe
works. I have however two comments to it:
- It does not look like a proper solution, but rather workaround. The user
may not be aware of those UDF/GenericUDF subtleties and even in case he is, he
still needs to treat the DECIMAL columns differently than other types, that can
be cast to string without problems.
- is the VARCHAR size 38 enough to contain even the largest decimal values,
possibly also including minus sign and decimal separator?)
> 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
> Assignee: Daniel Dai
>
> 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)