概述
sql
INSERT OVERWRITE TABLE log.test PARTITION(day=20210623) values ('1','1','1','1','1')
执行计划
Plan not optimized by CBO.
Stage-3
Stats-Aggr Operator
Stage-0
Move Operator
partition:{"day":"20210623"}
table:{"name:":"log.test","input format:":"org.apache.hadoop.mapred.TextInputFormat","output format:":"org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat","serde:":"org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"}
Stage-2
Dependency Collection{}
Stage-1
Map 1
File Output Operator [FS_9163]
compressed:false
Statistics:Num rows: 1 Data size: 10 Basic stats: COMPLETE Column stats: NONE
table:{"name:":"log.test","input format:":"org.apache.hadoop.mapred.TextInputFormat","output format:":"org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat","serde:":"org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"}
Select Operator [SEL_9162]
outputColumnNames:["_col0","_col1","_col2","_col3","_col4"]
Statistics:Num rows: 1 Data size: 10 Basic stats: COMPLETE Column stats: NONE
TableScan [TS_9161]
alias:values__tmp__table__2
Statistics:Num rows: 1 Data size: 10 Basic stats: COMPLETE Column stats: NONE
重点关注Move Operator
org.apache.hadoop.hive.ql.exec.MoveTask.java
FileSystem fs = sourcePath.getFileSystem(conf);
if (isDfsDir) {
// Just do a rename on the URIs, they belong to the same FS
String mesg = "Moving data to: " + targetPath.toString();
String mesg_detail = " from " + sourcePath.toString();
console.printInfo(mesg, mesg_detail);
// if source exists, rename. Otherwise, create a empty directory
if (fs.exists(sourcePath)) {
Path deletePath = null;
// If it multiple level of folder are there fs.rename is failing so first
// create the targetpath.getParent() if it not exist
if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_INSERT_INTO_MULTILEVEL_DIRS)) {
deletePath = createTargetPath(targetPath, fs);
}
if (!Hive.moveFile(conf, sourcePath, targetPath, fs, true, false)) {
try {
if (deletePath != null) {
fs.delete(deletePath, true);
}
} catch (IOException e) {
LOG.info("Unable to delete the path created for facilitating rename"
+ deletePath);
}
throw new HiveException("Unable to rename: " + sourcePath
+ " to: " + targetPath);
}
} else if (!fs.mkdirs(targetPath)) {
throw new HiveException("Unable to make directory: " + targetPath);
}
}
逻辑 :将源目录中的old文件移动到父目录,然后将新生成的new文件移动到源目录了,最后删除old文件
这里的删除是直接从hdfs中删除的
,数据没有进入垃圾箱
补充
1、垃圾桶机制概述
每一个文件系统都会有垃圾桶机制,便于将删除的数据回收到垃圾桶里面去,避免某些误操作删除一些重要文件。回收到垃圾桶里里面的资料数据,都可以进行恢复。
2、垃圾桶机制配置
HDFS的垃圾回收的默认配置属性为0,也就是说,如果你不小心误删除了某样东西,那么这个操作是不可恢复的。
修改core-site.xml:
那么可以按照生产上的需求设置回收站的保存时间,这个时间以分钟为单位,如 1440=24h=1天。
<property>
<name>fs.trash.interval</name>
<value>1440</value>
</property>
<property>
<name>fs.trash.checkpoint.interval</name>
<value>1440</value>
</property>
3、shell操作
(1)删除命令
hadoop fs -rm -r file_path
(2)恢复命令
hadoop fs -mv trash_path recover_path
(3)使用skipTrash选项彻底删除文件
该选项不会将文件发送到垃圾箱。它将从HDFS中完全删除。
hadoop fs -rm -r -skipTrash 文件名
4、Java操作 FileSystem类下的delete\deleteOnExit删除都是不经过回收站的
当通过Java API进行文件删除时,默认是不进入垃圾桶的,如果仍想要删到垃圾桶中,代码如下:
//删除文件至垃圾桶中
//创建垃圾桶
Trash trash = new Trash(fileSystem,fileSystem.getConf());
//将文件放在回收站中
trash.moveToTrash(new Path("/dir1/file1"));
//直接删除
fileSystem.delete(new Path("/dir1/file1"),true);
3、圾桶机制验证
如果启用垃圾箱配置,dfs命令删除的文件不会立即从HDFS中删除。相反,HDFS将其移动到垃圾目录(每个用户在/user/<username>/.Trash 下都有自己的垃圾目录)。只要文件保留在垃圾箱中,件可以快速恢复。
使用skipTrash选项删除文件,该选项不会将文件发送到垃圾箱。它将从DFS中完全删除。
总结
INSERT OVERWRITE 操作对应moveTask,直接删除hfds上数据,不会进入垃圾箱,慎用!!!
代码删除,不进入回收站,插件删除也不进回收站,只有从客户端登录删除才会进入回收站,如果想恢复,执行hfds的mv指令即可
参考
https://segmentfault.com/a/1190000039077572
网友评论