开源大数据技术社区召集令
引子 Hadoop生态技术已经俨然成为大数据事实标准,为了给广大同学、朋友提供一些交流学习的环境,沉淀大数据技术相关的资料,特别发起此次关注活动。 社群 技术交流钉钉大群 阿里云 HBase+Spark社区 【强烈推荐!】 群内每周进行群直播技术分享及问答 加入方式1:点击link申请加入 https://dwz.cn/Fvqv066s 加入方式2:钉钉扫码加入:
坑一:改变字段类型后更新数据不成功
关于hive插入数据的一个小坑,今天插入一个表中数据,插入时写的是常数,比如0.01 ,表中的字段也是DECIMAL(5,2)
按照常理插入的应该是0.01,但是插入后查询是0,为甚!
就分析呀,看语句没问题啊,上网查,上hive官网查,呀~ 发现了原因哦
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types#LanguageManualTypes-Decimals
发现在插入分区表时会出现这种情况,此时需要对之前的分区处理下~:
那就测试一下 按照官网的说法:
先建表:
| CREATE TABLE `tb_dw_cu_mimsg_fbi_servdt_day1`( `mimsg_serv` int COMMENT '微信服务量') PARTITIONED BY ( `statis_date` varchar(8)) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' ; |
然后插入数据:
| insert overwrite table tb_dw_cu_mimsg_fbi_servdt_day1 partition (statis_date=20160501) values(1.02); |
然后查询:
| hive> select * from tb_dw_cu_mimsg_fbi_servdt_day1; OK 1 20160501 |
发现结果跟想象中的一样~
然后修改表字段:
| ALTER TABLE tb_dw_cu_mimsg_fbi_servdt_day1 REPLACE COLUMNS (mimsg_serv DECIMAL(5,2)) |
然后再次插入数据:
| insert overwrite table tb_dw_cu_mimsg_fbi_servdt_day1 partition (statis_date=20160501) values(1.02); |
查询:
| hive> select * from tb_dw_cu_mimsg_fbi_servdt_day1; OK 1 20160501 |
发现有问题啦!
那么按照官网处理:
| Determine what precision/scale you would like to set for the decimal column in the table. For each decimal column in the table, update the column definition to the desired precision/scale using the ALTER TABLE command:
If the table is not a partitioned table, then you are done. If the table has partitions, then go on to step 3. If the table is a partitioned table, then find the list of partitions for the table:
Each existing partition in the table must also have its DECIMAL column changed to add the desired precision/scale. This can be done with a single ALTER TABLE CHANGE COLUMN by using dynamic partitioning (available for ALTER TABLE CHANGE COLUMN in Hive 0.14 or later, with HIVE-8411):
|
这里对表作如下处理:
| ALTER TABLE tb_dw_cu_mimsg_fbi_servdt_day1 PARTITION (statis_date) CHANGE COLUMN mimsg_serv mimsg_serv DECIMAL(5,2); |
再次插入数据:
| insert overwrite table tb_dw_cu_mimsg_fbi_servdt_day1 partition (statis_date=20160501) values(1.02); |
然后查询:
| hive> select * from tb_dw_cu_mimsg_fbi_servdt_day1; OK 1.02 20160501 Time taken: 0.066 seconds, Fetched: 1 row(s) |
发现结果跟想象中的一样了。这个坑算是过去了~
坑二:增加字段后更新数据不成功
还是上面的例子那张表,再增加一个字段:
| alter table tb_dw_cu_mimsg_fbi_servdt_day1 add COLUMNS (prov_code varchar(5)) |
然后查询
| hive> select * from tb_dw_cu_mimsg_fbi_servdt_day1; OK 1.02 NULL 20160501 Time taken: 0.082 seconds, Fetched: 1 row(s) |
发现新增的字段默认的值是NULL,现在我重新覆盖一下元数据,给增加的字段一个值:
| insert overwrite table tb_dw_cu_mimsg_fbi_servdt_day1 partition(statis_date=20160501) values (2.01,0371); |
然后查询:
| hive> select * from tb_dw_cu_mimsg_fbi_servdt_day1; OK 2.01 NULL 20160501 |
发现还是NULL
不是我们想象的结果,查看一下官方文档说明发现了问题的所在:
| ALTER TABLE ADD or REPLACE COLUMNS CASCADE will override the table partition's column metadata regardless of the table or partition's protection mode. Use with discretion. |
那就这样处理:
| alter table tb_dw_cu_mimsg_fbi_servdt_day1 replace COLUMNS (mimsg_serv decimal(5,2),prov_code varchar(5)) CASCADE; |
直接查询,发现数据显示的数据已经发生了变化了~
| hive> select * from tb_dw_cu_mimsg_fbi_servdt_day1; OK 2.01 0371 20160501 |
综上发现,我们是按照Oracle这样的标准在考虑H-SQL,但是通过阅读官方文档发现二者之间还是有很大不同的,通过这次踩坑发现,仔细阅读官方文档的重要性!!!
微信关注我们
转载内容版权归作者及来源网站所有!
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。
Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。
Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。
Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。