蜂巢的十进制精度

时间:2016-03-29 10:09:54

标签: hadoop hive

我想添加要为值设置的小数精度

示例:

select 1*1.00000;

输出:1.0

甚至尝试使用演员

select cast(cast(1*1.0000 as double) as decimal(5,2))

输出:1

我希望结果显示为1.000。有没有办法在蜂巢中这样做?

1 个答案:

答案 0 :(得分:3)

创建一个表并对其进行测试。如果我们给出十进制函数中提到的精确精度值,它就有效。

create table test1_decimal (b decimal (5,3));

INSERT INTO test1_Decimal values(1.000); //This will shrink it to 1 as the total digits is not five.

INSERT INTO test1_Decimal values(123.12345); //This results in NULL as it exceeds the total digits(5).

INSERT INTO test1_Decimal values(12.123); //This will give you exact result as the precision and number of digits fits. Ouputs as 12.123

因此,如果该值与十进制函数匹配,则它会正确显示,否则会收缩或转换为NULL。