hive可以drop所有表的bug fix

之前遇到的一个drop table的小问题,默认任何人都可以有使用drop db.table的权限
这是一个bug,

bugid:https://issues.apache.org/jira/browse/HIVE-2817

解决方法:
可以通过设置

set hive.exec.drop.ignorenonexistent=false(Do not report an error if DROP TABLE/VIEW specifies a non-existent table/view,

这个值默认是true,

DROPIGNORESNONEXISTENT("hive.exec.drop.ignorenonexistent", true)

)来解决。

Workaround:
set hive.exec.drop.ignorenonexistent=false.
Before that,
we need to check all the "drop" sqls and change to drop if exists.
we need to remove all "drop table db.table" syntax to "use db; drop table if exists table;"

但是如果设置了hive.exec.drop.ignorenonexistent=false,如果表xxx不存在,drop table xxx会报错

hive> set hive.exec.drop.ignorenonexistent=false;
hive> drop table tt;                           
FAILED: SemanticException [Error 10001]: Table not found tt
hive> set hive.exec.drop.ignorenonexistent=true;
hive> drop table tt;                          
OK
Time taken: 0.055 seconds

另外,drop  db.table这种语法也会报错,如果设置hive.exec.drop.ignorenonexistent为true则不会报错

hive> set hive.exec.drop.ignorenonexistent=true;
hive> drop table cdnlog.ttt;
FAILED: SemanticException [Error 10001]: Table not found cdnlog.ttt
hive> use cdnlog;drop table ttt;
OK
Time taken: 0.042 seconds
OK
set hive.exec.drop.ignorenonexistent=true;
hive> drop table cdnlog.ttt;
OK

因为更改etl sql的代价比较大,因此只能把hive.exec.drop.ignorenonexistent设置为true,另外需要fix这个bug
drop table是ddl操作,对应的analyzer相关类的路径为:

ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java

对应的方法是analyzeDropTable:

@@ -721,13 +716,30 @@
   private void analyzeDropTable(ASTNode ast, boolean expectView)
       throws SemanticException {
     String tableName = getUnescapedName((ASTNode) ast.getChild(0));
     boolean ifExists = (ast.getFirstChildWithType(HiveParser.TOK_IFEXISTS) != null);
     // we want to signal an error if the table/view doesn‘t exist and we‘re
     // configured not to fail silently
     boolean throwException =
         !ifExists && !HiveConf.getBoolVar(conf, ConfVars.DROPIGNORESNONEXISTENT);
     try {
- Table tab = db.getTable(db.getCurrentDatabase(), tableName, throwException);
+ // to fix the drop table bug
+ String tableName2 = "";
+ if (tableName.contains(".")) {
+ try {
+ tableName2 = tableName.split("\\.")[1];
+ } catch (Exception e) {
+ // do nothing if tableName can‘t be splitted
+ tableName2 = tableName;
+ }
+ } else {
+ tableName2 = tableName;
+ }
+ Table tab = db.getTable(db.getCurrentDatabase(), tableName2, throwException);
+
+ // Table tab = db.getTable(db.getCurrentDatabase(), tableName, throwException);
+
       if (tab != null) {
         inputs.add(new ReadEntity(tab));
         outputs.add(new WriteEntity(tab));
时间: 2024-07-31 14:23:20

hive可以drop所有表的bug fix的相关文章

hive0.13权限bug fix

最近线上的hive升级到了0.13,遇到不少问题.权限上面,设置了hive.security.authorization.createtable.owner.grants 在hive0.13中,用户自己创建的表也没有权限.通过对源码的分析和debug找到了rc并fix,下面记录下. 1.首先在hive0.11中和hive0.13中分别做建表测试,通过查看数据库中的元数据,发现在hive0.11中如果设置了owner的参数在表创建之后,用户会有这个表的all的权限(具体可以分析db_privs ,

hive 创建/删除/截断 表(翻译自Hive wiki)

这里罗列常用操作,更多参考 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-Create%2FDrop%2FTruncateTable 简单的创建表 create table table_name ( id int, dtDontQuery string, name string ) 创建有分区的表 create table table_name ( id int, dtD

hive与hbase关联表

关于 hbase 和 hive 关联表 详细介绍: hive 创建 关联hbase表有2种形式: 第一种:hive> create table hive(id string,name string, age int) > stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' > with serdeproperties ("hbase.columns.mapping" = ":key,cf:

hive与hbase关联表的创建,外表方式

1.在Hive里面创建一个表: hive> create table wyp(id int,    > name string,    > age int,    > tele string)    > ROW FORMAT DELIMITED    > FIELDS TERMINATED BY '\t'    > STORED AS TEXTFILE;OKTime taken: 0.759 seconds 2.这样我们就在Hive里面创建了一张普通的表,现在给这

Hive的数据库和表

本文介绍一下Hive中的数据库(Database/Schema)和表(Table)的基础知识,由于篇幅原因,这里只是一些常用的.基础的. Hive的数据库和表 先看一张草图: Hive结构 从图上可以看出,Hive作为一个"数据库",在结构上积极向传统数据库看齐,也分数据库(Schema),每个数据库下面有各自的表组成. 1.  Hive在HDFS上的默认存储路径 Hive的数据都是存储在HDFS上的,默认有一个根目录,在hive-site.xml中,由参数hive.metastore

hive join 优化 --小表join大表

1.小.大表 join 在小表和大表进行join时,将小表放在前边,效率会高,hive会将小表进行缓存. 2.mapjoin 使用mapjoin将小表放入内存,在map端和大表逐一匹配,从而省去reduce. 例子: select /*+MAPJOIN(b)*/ a.a1,a.a2,b.b2 from tablea a JOIN tableb b ON a.a1=b.b1 在0.7版本后,也可以用配置来自动优化 set hive.auto.convert.join=true;

Oracle Flashback Technologies - 闪回被drop的表

在oracle10g中,drop一个表后,表没有真正被删除,支持被rename后放在recyclebin中. #新建一个表y2,用来测试 SQL> create table y2 as select * from all_tables; Table created. SQL> select count(*) from y2; COUNT(*) ---------- 3598 #删除表 SQL> show recyclebin SQL> drop table y2; Table dr

Hive分区与桶表

1.分区 在hive中使用select查询一般会扫描整个表的内容,从而降低降低查询的效率.引入分区的概念,使得查询时只扫描表中关心的部分数据. 一个表中可以有一个或多个分区,每个分区以文件夹的形式单独存在表文件夹的目录下. 1.1分区建表分为单分区和双分区建表: 单分区建表语句:create table sample_table (id int, value string) partitioned by (age int) row format delimited fields terminat

创建hive整合hbase的表总结

[Author]: kwu 创建hive整合hbase的表总结,如下两种方式: 1.创建hive表的同步创建hbase的表 CREATE TABLE stage.hbase_news_company_content(key string comment "流水号", news_id string comment "新闻id", news_content string comment "文章内容") STORED BY 'org.apache.ha