spark-sql中数据类型比较(double vs decimal)

为什么80%的码农都做不了架构师?>>>   hot3.png

1、创建表,数据类型是double和decimal

create external table tmp.tmp_test(
amt1 double,
amt3 decimal(20,8)
)
STORED AS parquet
location 'hdfs://reh/user/hive/dev/tmp_dev/tmp_test';

2、测试数据为“111111.1232”,查询显示正常:

spark-sql> insert overwrite table tmp.tmp_test
> select 111111.1232 as amt1,111111.1232 as amt3 from test limit 1;
Time taken: 22.219 seconds 
spark-sql> select * from tmp.tmp_test;
111111.1232 111111.1232
Time taken: 0.269 seconds, Fetched 1 row(s)

3、测试数据为“11111111.12”,查询显示异常(科学计数法):

spark-sql> insert overwrite table tmp.tmp_test
> select 11111111.12 as amt1,11111111.12 as amt3 from dtp.dtp_company_staff_deal_flow where dt = '2017-04-25' limit 1;
Time taken: 24.505 seconds 
spark-sql> select * from tmp.tmp_test;
1.111111112E7 11111111.12
Time taken: 5.769 seconds, Fetched 1 row(s)

转载于:https://my.oschina.net/data99/blog/887519

你可能感兴趣的:(spark-sql中数据类型比较(double vs decimal))