20191011
20191010
hive 中数值类型
和字符串类型string
运算数值类型
可以和和字符串类型string
运算,其中字符串为纯数字类型
,都转为了浮点类型double
.若字符串不为纯数字类型
,计算结果则为NULL
.select 3 * '2'
6.0
select 3 * '2.2'
6.6
select '3' * '2'
6.0
20191010
hive中使用联结union all
union all
中的子查询要求相同的列数
,对应字段类型相同
或可以隐式转化为同一种类型
20191010
hive中int
double
float
转string
出现科学计数法int , float , double
这些数值类型在存储大额度数字
时,在前端展现上总是使用科学计数法
来表示,其实无论是普通的表示方式还是科学计数法表示,只是一个习惯问题,结果都是一样的。数值类型
转化成字符串类型
以后hive竟然把数值转换成了科学计数法表示的字符串
而非数值本身的字符串
处理方法参考下面链接,整数
直接先转成bigint
,若是小数
需要特殊处理
参考1-hive中科学计数法
create table test_table(bignumstr string)
sql
语句select 123456789101112;
123456789101112
select 123456789101112.0;
1.23456789101112E14
--或
123456789101112.0
select 123456789101111
union all
select 123456789101112.0;
1.23456789101111E14
1.23456789101112E14
-- 或
123456789101111.0
123456789101112.0
insert
insert into table test_table
select 123456789101111;
select * table test_table;
123456789101112
insert into table test_table
select 123456789101112.0;
select * table test_table;
1.23456789101112E14
union all
insert overwrite table test_hjy
select 123456789101111
union all
select 123456789101112.0;
select * table test_table;
1.23456789101111E14
1.23456789101112E14
select cast(123456789101111 as string)
union all
select 123456789101112.0;
1.23456789101111E14
1.23456789101112E14
-- 或
123456789101111.0
123456789101112.0
insert overwrite table test_hjy
select cast(123456789101111 as string)
union all
select 123456789101112.0;
select * table test_table;
1.23456789101111E14
1.23456789101112E14
insert overwrite table test_hjy
select cast(123456789101111 as string)
union all
select 1 * '123456789101112';
select * table test_table;
1.23456789101111E14
1.23456789101112E14
原因在于hive在联结union all时,可以进行隐式转换,先都转换为同一种类型,
string
可以转换为double
,见参考2.
原文:https://www.cnblogs.com/damahuhu/p/11675553.html