Hive中的DECIMAL类型

(Decimal)小数点

Hive中的DECIMAL类型与Java的Big Decimal格式相同。它用于表示不变的任意精度。语法和示例如下:

  •  
DECIMAL(precision, scale)decimal(10,0)

 

https://mp.weixin.qq.com/s/BUk8Y7-rOiBzUnseekqmGg

1、 基本类型

 

这里我们对DECIMAL类型做两点说明:
1)DECIMAL(9,8)代表最多9位数字,后8位是小数。此时也就是说,小数点前最多有1位数字,如果超过一位则会变成null。
2)如果不指定参数,那么默认是DECIMAL(10,0),即没有小数位,此时0.82会变成1。

 

这里我们通过一个SQL来进行说明:

创建表:

create table if not existsdatatype_test1(id int,col1 decimal,col2 decimal(9,8)) row format delimited fields terminated by ',';

我们从txt中读取数据:​​​​​​​

load data local inpath '/Users/meituan_sxw/Downloads/test1.txt' into table datatype_test1;
#txt中的内容1,0.82,83.22,1.06,9.22

接下来查看hive中的数据:

 select * from datatype_test1;

 

类型转换:

https://cwiki.apache.org/confluence/display/Hive/Tutorial

The Types are organized in the following hierarchy (where the parent is a super type of all the children instances):

  • Type
    • Primitive Type

      • Number

        • DOUBLE

          • FLOAT

            • BIGINT

              • INT

                • SMALLINT

                  • TINYINT

          • STRING

      • BOOLEAN

This type hierarchy defines how the types are implicitly converted in the query language. Implicit conversion is allowed for types from child to an ancestor. So when a query expression expects type1 and the data is of type2, type2 is implicitly converted to type1 if type1 is an ancestor of type2 in the type hierarchy. Note that the type hierarchy allows the implicit conversion of STRING to DOUBLE.

Explicit type conversion can be done using the cast operator as shown in the #Built In Functions section below.

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值