gpt4 book ai didi

java - Hive jdbc - 无法从我自己的表中选择

转载 作者:可可西里 更新时间:2023-11-01 14:33:51 26 4
gpt4 key购买 nike

我登录为 pawel 用户。在 hive shell 中,我在数据库中创建了一个数据库 pawel_db 和一个 test_table 并用一行数据填充它。这是 ls 向我显示的内容:

[pawel@sandbox ~]$ hadoop fs -ls /apps/hive/warehouse
Found 6 items
drwxr-xr-x - pawel hdfs 0 2014-07-14 07:29 /apps/hive/warehouse/pawel_db.db
[...]

在外壳中:

[pawel@sandbox ~]$ hive -e "use pawel_db; select * from test_table"

Logging initialized using configuration in file:/etc/hive/conf.dist/hive-log4j.properties
OK
Time taken: 9.926 seconds
OK
777
Time taken: 5.243 seconds, Fetched: 1 row(s)

一切似乎都很好。当我想通过 jdbc 进行一些查询时,问题就开始了:

Connection con = DriverManager.getConnection("jdbc:hive2://" + hiveHostAddress + ":" + hiveHostPort + "/pawel_db", "pawel", "");
Statement stmt = con.createStatement();
stmt.execute("select * from test_table");

抛出异常:

Caused by: java.sql.SQLException: Error while compiling statement: FAILED: HiveAccessControlException Permission denied. Principal [name=pawel, type=USER] does not have following privileges on Object [type=TABLE_OR_VIEW, name=pawel_db.test_table] : [SELECT]

但是,在hive中执行后:

grant SELECT on table test_table to user pawel;

也不异常(exception)。我真的需要向数据库所有者手动授予选择权限吗?这似乎不符合逻辑。

最佳答案

先决条件为了使用 Hive 授权,需要在 hive-site.xml 中设置两个参数:

<property>
<name>hive.security.authorization.enabled</name>
<value>true</value>
<description>enable or disable the hive client authorization</description>
</property>

<property>
<name>hive.security.authorization.createtable.owner.grants</name>
<value>ALL</value>
<description>the privileges automatically granted to the owner whenever a table gets created.
An example like "select,drop" will grant select and drop privilege to the owner of the table</description>
</property>

关于java - Hive jdbc - 无法从我自己的表中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24739758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com