立即注册 登录
About云-梭伦科技 返回首页

sbrui的个人空间 https://www.aboutyun.com/?60855 [收藏] [复制] [分享] [RSS]

日志

Hive中Boolean值转为Int值的一些问题纪录

已有 1461 次阅读2017-6-12 12:38 |个人分类:hive| hive, 类型转换, alter

1.首先建立一个有分区的外部表
create external table `test_boolean`(
`id` int,
`bool` boolean )partitioned by (
`year` int,
`month` int,
`day` int)
location 'hdfs://...../test_boolean';
2.往分区表中插入值
insert into table test_boolean partition(year=2017,month=4,day=1) values(1,1);
结果 显示: 1 ture 2017 4 1
3. alter table  test_boolean change  bool bool  int;
结果 展示: 1 1 2017 4 1
4.
再往同样的 分区表 插入值
insert into table test_boolean partition(year=2017,month=4,day=1) values(2,1);
结果 显示: 1 1 2017 4 1
                    2 null 2017 4 1
在另一个分区表 插入值
insert into table test_boolean partition(year=2017,month=4,day=2) values(3,1);
结果 显示: 1  1   2017 4  1
                   2  null 2017 4 1
                   3   1    2017 4 2
5.执行 alter table  test_boolean change  bool bool   boolean cascade;
结果显示 :1   ture  2017 4 1
                  2 null 2017 4 1
                  3 null 2017 4 1
6.执行alter table  test_boolean change  bool bool   int cascade;
结果显示:  1  null 2017 4 1
                    2  1 2017 4  1
                    3   1 2017 4 2

总结:boolean 类型的alter 操作
不像 string 与 int 历史数据和新增数据可以保持一致 有值的
                    
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL

路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

关闭

推荐上一条 /2 下一条