若在Hive中执行INSERT OVERWRITE重写同一个表的数据时,有可能会造成数据丢失。

如 INSERT OVERWRITE TABLE table_name SELECT * FROM table_name


一、新建一张分区表

create table test_chj_cols (id string, name string, age string) partitioned by (ds string) stored as textfile;

二、插入一条记录

insert into test_chj_cols partition (ds='20181224') values ('1','chj','18');

三、确认表数据及结构

> select * from test_chj_cols;
OK
test_chj_cols.id test_chj_cols.name test_chj_cols.age test_chj_cols.ds
1 chj 18 20181224 > desc formatted test_chj_cols partition (ds='20181224');
OK
col_name data_type comment
# col_name data_type comment id string
name string
age string # Partition Information
# col_name data_type comment ds string # Detailed Partition Information
Partition Value: [20181224]
Database: hduser05db
Table: test_chj_cols
CreateTime: Mon Dec 24 19:35:28 CST 2018
LastAccessTime: UNKNOWN
Protect Mode: None
Location: hdfs://bdphdp02/user/hive/warehouse/hduser05/hduser05db.db/test_chj_cols/ds=20181224
Partition Parameters:
COLUMN_STATS_ACCURATE true
numFiles 1
numRows 1
rawDataSize 8
totalSize 17
transient_lastDdlTime 1545651329 # Storage Information
SerDe Library: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
InputFormat: org.apache.hadoop.mapred.TextInputFormat
OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
Compressed: No
Num Buckets: -1
Bucket Columns: []
Sort Columns: []
Storage Desc Params:
serialization.format 1
Time taken: 0.099 seconds, Fetched: 37 row(s)

四、在表中间新增字段

alter table test_chj_cols replace columns (id string, name string, money string, age string);

> desc formatted test_chj_cols;
OK
col_name data_type comment
# col_name data_type comment id string
name string
money string
age string # Partition Information
# col_name data_type comment ds string # Detailed Table Information
Database: hduser05db
Owner: hadoop
CreateTime: Mon Dec 24 19:34:46 CST 2018
LastAccessTime: UNKNOWN
Protect Mode: None
Retention: 0
Location: hdfs://bdphdp02/user/hive/warehouse/hduser05/hduser05db.db/test_chj_cols
Table Type: MANAGED_TABLE
Table Parameters:
last_modified_by hadoop
last_modified_time 1545651722
transient_lastDdlTime 1545651722 # Storage Information
SerDe Library: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
InputFormat: org.apache.hadoop.mapred.TextInputFormat
OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
Compressed: No
Num Buckets: -1
Bucket Columns: []
Sort Columns: []
Storage Desc Params:
serialization.format 1
Time taken: 0.051 seconds, Fetched: 36 row(s)

五、重写数据

insert overwrite table test_chj_cols partition (ds='20181224') select id,name,age,name from

test_chj_cols;

六、age字段数据丢失

> select * from test_chj_cols;
OK
test_chj_cols.id test_chj_cols.name test_chj_cols.age test_chj_cols.money test_chj_cols.ds
1 chj NULL NULL 20181224

Hive重写表数据丢失风险记录的更多相关文章

  1. 单表60亿记录等大数据场景的MySQL优化和运维之道

    此文是根据杨尚刚在[QCON高可用架构群]中,针对MySQL在单表海量记录等场景下,业界广泛关注的MySQL问题的经验分享整理而成,转发请注明出处. 杨尚刚,美图公司数据库高级DBA,负责美图后端数据 ...

  2. 【转】单表60亿记录等大数据场景的MySQL优化和运维之道 | 高可用架构

    此文是根据杨尚刚在[QCON高可用架构群]中,针对MySQL在单表海量记录等场景下,业界广泛关注的MySQL问题的经验分享整理而成,转发请注明出处. 杨尚刚,美图公司数据库高级DBA,负责美图后端数据 ...

  3. [转载] 单表60亿记录等大数据场景的MySQL优化和运维之道 | 高可用架构

    原文: http://mp.weixin.qq.com/s?__biz=MzAwMDU1MTE1OQ==&mid=209406532&idx=1&sn=2e9b0cc02bdd ...

  4. 单表60亿记录等大数据场景的MySQL优化和运维之道 | 高可用架构

    015-08-09 杨尚刚 高可用架构 此文是根据杨尚刚在[QCON高可用架构群]中,针对MySQL在单表海量记录等场景下,业界广泛关注的MySQL问题的经验分享整理而成,转发请注明出处. 杨尚刚,美 ...

  5. mysql在线修改表结构大数据表的风险与解决办法归纳

    整理这篇文章的缘由: 互联网应用会频繁加功能,修改需求.那么表结构也会经常修改,加字段,加索引.在线直接在生产环境的表中修改表结构,对用户使用网站是有影响. 以前我一直为这个问题头痛.当然那个时候不需 ...

  6. Hive metastore表结构设计分析

    今天总结下,Hive metastore的结构设计.什么是metadata呢,对于它的描述,可以理解为数据的数据,主要是描述数据的属性的信息.它是用来支持如存储位置.历史数据.资源查找.文件记录等功能 ...

  7. Mycat读写分离、主从切换、分库分表的操作记录

    系统开发中,数据库是非常重要的一个点.除了程序的本身的优化,如:SQL语句优化.代码优化,数据库的处理本身优化也是非常重要的.主从.热备.分表分库等都是系统发展迟早会遇到的技术问题问题.Mycat是一 ...

  8. R语言读取Hive数据表

    R通过RJDBC包连接Hive 目前Hive集群是可以通过跳板机来访问 HiveServer, 将Hive 中的批量数据读入R环境,并进行后续的模型和算法运算. 1. 登录跳板机后需要首先在Linux ...

  9. Hive中小表与大表关联(join)的性能分析【转】

    Hive中小表与大表关联(join)的性能分析 [转自:http://blog.sina.com.cn/s/blog_6ff05a2c01016j7n.html] 经常看到一些Hive优化的建议中说当 ...

随机推荐

  1. OpenCV学习:OpenCV文件一览

    了解一些OpenCV代码整体的模块结构后,再重点学习自己感兴趣的部分,会有一种一览众山小的感觉~ Come on! C:\OpenCV\opencv\build\include文件夹下包含两个文件夹: ...

  2. linux环境中,查询网卡的速度(带宽)

    需求描述: 今天一同事要整理测试环境的主机硬件配置信息,需要提供网卡的速度的信息, 所以,就查询了下,在此记录下. 操作过程: 1.首先通过ip a命令查询主机的网口名称 [root@redhat6 ...

  3. 第四章 Spring.Net 如何管理您的类___对象、对象工厂和应用程序上下文

    在前面一章我们介绍了依赖注入,控制反转的概念,以及自己动手搭建了一下Spring.Net的环境.通过这些操作,我们知道了Spring.Net 的核心是使用依赖注入或控制反转这种思想来管理业务对象,降低 ...

  4. 获取form表单数据

    var modelObj = {}; var modelFieldsArray = $('#AddMusic').serializeArray(); $.each(modelFieldsArray, ...

  5. 【RF库Collections测试】Dictionaries Should Be Equal

    Name:Dictionaries Should Be EqualSource:Collections <test library>Arguments:[ dict1 | dict2 | ...

  6. Python cookielib 模块

    什么是 cookie : 指某些网站为了辨别用户身份,进行 session 跟踪而储存在用户本地终端上的数据,通常以 txt 文件形式存储.比如你登录了淘宝,浏览器就会保存 cookie 信息,这样我 ...

  7. combobox组合框

    最近在改BUG的时候发现,combobox组合框如果选择的是Dropdown模式在初始化combobox对象时候有如下操作 1.SetDlgItemInt(IDC_WB_FONTSIZECOMBOX, ...

  8. php array key 的存储规则

    刚刚写程序遇到php数组取值的问题,发现字符串和数字取出来的是一样的. key 可以是 integer 或者string.value 可以是任意类型. 此外 key 会有如下的强制转换: 包含有合法整 ...

  9. Linux性能监控——CPU,Memory,IO,Network

    版权声明:本文由刘爽原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/107 来源:腾云阁 https://www.qclou ...

  10. Eclipse '<>' operator is not allowed for source level below 1.7

    '<>' operator is not allowed for source level below 1.7 解决方法: