HiveAccessControlException权限被拒绝。 [关于pyhs2]

时间:2015-06-01 07:14:51

标签: python-2.7 hadoop hive hortonworks-data-platform

我试图通过写一个select查询来通过pyhs2访问数据。

import pyhs2

with pyhs2.connect(host='localhost',
               port=10000,
               authMechanism="PLAIN",
               user='hue',
               password='',
               database='default') as conn:

with conn.cursor() as cur:
    print cur.getDatabases()

    cur.execute("select * from orders")
    print cur.getSchema()

    for i in cur.fetch():
        print i

这给了我一个错误:

  

pyhs2.error.Pyhs2Exception:'编译语句时出错:FAILED:HiveAccessControlException权限被拒绝。 Principal [name = hue,type = USER]对Object [type = TABLE_OR_VIEW,name = default.orders]没有以下权限:[SELECT]'

使用以下建议的答案很少:

 grant SELECT on table orders to user hue

这再次给我一个错误:

  

yhs2.error.Pyhs2Exception:'处理语句时出错:FAILED:执行错误,从org.apache.hadoop.hive.ql.exec.DDLTask返回代码1。没有权限。 Principal [name = hue,type = USER]对Object [type = TABLE_OR_VIEW,name = default.orders]没有以下权限:[SELECT with grant]'

1 个答案:

答案 0 :(得分:0)

在授予特权之前,请确保您具有管理员角色:

show current roles;

用户仅具有 public 角色是不够的。您可以通过以下命令设置管理员角色:

set role admin; 

请参阅Apache Hive Wiki:

https://cwiki.apache.org/confluence/display/Hive/SQL+Standard+Based+Hive+Authorization

For Hive 0.14 and Newer
Set the following in hive-site.xml:
hive.users.in.admin.role to the list of comma-separated users who need to be added to admin role. Note that a user who belongs to the admin role needs to run the "set role" command before getting the privileges of the admin role, as this role is not in current roles by default.