hive可以drop所有表的bug fix

简介:

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

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

解决方法:
可以通过设置

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

这个值默认是true,

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

)来解决。

1
2
3
4
5
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会报错

1
2
3
4
5
6
7
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则不会报错

1
2
3
4
5
6
7
8
9
10
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相关类的路径为:

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

对应的方法是analyzeDropTable:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@@ - 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));

  


本文转自菜菜光 51CTO博客,原文链接:http://blog.51cto.com/caiguangguang/1558885,如需转载请自行联系原作者

相关文章
|
3月前
|
SQL 存储 HIVE
Hive中的表是如何定义的?请解释表的结构和数据类型。
Hive中的表是如何定义的?请解释表的结构和数据类型。
34 0
|
4月前
|
SQL 消息中间件 数据处理
DataX读取Hive Orc格式表丢失数据处理记录
DataX读取Hive Orc格式表丢失数据处理记录
128 0
|
5月前
|
SQL HIVE
49 Hive修改表
49 Hive修改表
19 0
49 Hive修改表
|
7月前
|
SQL 存储 分布式计算
Hive性能优化之表设计优化1
Hive性能优化之表设计优化1
37 1
|
10天前
|
SQL 数据库 HIVE
Hive【基础知识 05】常用DDL操作(数据库操作+创建表+修改表+清空删除表+其他命令)
【4月更文挑战第8天】Hive【基础知识 05】常用DDL操作(数据库操作+创建表+修改表+清空删除表+其他命令)
21 0
|
2月前
|
SQL 消息中间件 Kafka
Flink部署问题之hive表没有数据如何解决
Apache Flink是由Apache软件基金会开发的开源流处理框架,其核心是用Java和Scala编写的分布式流数据流引擎。本合集提供有关Apache Flink相关技术、使用技巧和最佳实践的资源。
|
3月前
|
SQL 分布式计算 关系型数据库
Sqoop数据导入到Hive表的最佳实践
Sqoop数据导入到Hive表的最佳实践
|
8月前
|
SQL 存储 分布式计算
Hive学习---5、分区表和分桶表
Hive学习---5、分区表和分桶表
|
4月前
|
SQL 存储 HIVE
❤️Hive的基本知识(二)Hive中的各种表❤️
❤️Hive的基本知识(二)Hive中的各种表❤️
30 0
|
9月前
|
SQL 存储 安全
Hive 内部表(管理表)和外部表的区别【重点】
Hive 内部表(管理表)和外部表的区别【重点】
273 1