若在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. css文字超出自动显示省略号

    只针对单行文本有效: 01.针对块状元素 ul li{ width: 180px; text-overflow: ellipsis; white-space: nowrap;/*禁止自动换行*/ ov ...

  2. 关于java之socket输入流输出流可否放在不同的线程里进行处理

    2014年2月20日到叫(黑土)(人士)的公司去面试,一家新成立的公司.刚去公司是他们新聘请的猎头A来面试我的,A面试完之后是一个号称X总的年轻人来面试我,初一见此人有点邋遢,穿着西装. X:&quo ...

  3. Strut2------获取界面返回的session,application,parameter

    1.Action类下的代码 public class ServletActionDemo extends ActionSupport { @Override public String execute ...

  4. Ini操作类

    using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...

  5. oc中的各种遍历(迭代)方法

    转载自文顶顶老师的博客:http://www.cnblogs.com/wendingding/p/5251937.html 说明: 1)该文简短介绍在ios开发中遍历字典.数组和集合的集中常见方式 2 ...

  6. laravel 模版赋值

    1)一般赋值是直接用view助手函数返回的 return view('Index/index', ['key'=>'value']); 2)一般做系统时,我们都会有一个共同控制器,其他控制器继承 ...

  7. 连接oracle服务器超慢--原因分析

    连接oracle服务器超慢:有如下原因可能会影响. 网络不好:oracle服务器跟本地网络不好. oracle服务器内存不足:导致反应超慢 监听日志listener.log太大:导致响应超慢. 所以对 ...

  8. C++11新特性之一——Lambda表达式

    C++11新特性总结可以参考:http://www.cnblogs.com/pzhfei/archive/2013/03/02/CPP_new_feature.html#section_6.8 C++ ...

  9. PyQt4将窗口放在屏幕中间

    以下脚本显示了将窗口放在屏幕中间位置的方法. #!/usr/bin/python # -*- coding:utf-8 -*- import sys from PyQt4 import QtGui c ...

  10. ajax返回值传给js全局变量

    1. $.ajaxSetup({ async : false //设置ajax为同步方式,异步方式的话在赋值时数据还未提取出来 });var t = ""; var enginee ...