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 allunion 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
insertinsert 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 allinsert 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