1

在设置外部表以查看 Hive 中的一些 Avro 文件时,我遇到了一个有趣的权限问题。

Avro 文件位于此目录中:

drwxr-xr-x   - myserver hdfs          0 2017-01-03 16:29 /server/data/avrofiles/

服务器可以写入此文件,但普通用户不能。

作为数据库管理员,我在 Hive 中创建了一个引用此目录的外部表:

hive> create external table test_table (data string) stored as avro location '/server/data/avrofiles';

现在作为普通用户,我尝试查询表:

hive> select * from test_table limit 10;
FAILED: HiveException java.security.AccessControlException: Permission denied: user=regular.joe, access=WRITE, inode="/server/data/avrofiles":myserver:hdfs:drwxr-xr-x
        at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:319)

很奇怪,我只是想使用 hive 读取文件的内容,而不是尝试写入它。

奇怪的是,当我像这样对表进行分区时,我没有遇到同样的问题:

作为数据库管理员:

hive> create external table test_table_partitioned (data string) partitioned by (value string) stored as avro;
OK
Time taken: 0.104 seconds
hive> alter table test_table_partitioned add if not exists partition (value='myvalue') location '/server/data/avrofiles';
OK

作为普通用户:

hive> select * from test_table_partitioned where value = 'some_value' limit 10;
OK

谁能解释一下?

我注意到的一件有趣的事情是,两个表的 Location 值不同并且具有不同的权限:

hive> describe formatted test_table;
Location:               hdfs://server.companyname.com:8020/server/data/avrofiles

$ hadoop fs -ls /apps/hive/warehouse/my-database/
drwxr-xr-x   - myserver hdfs          0 2017-01-03 16:29 /server/data/avrofiles/

用户不能写

hive> describe formatted test_table_partitioned;
Location:               hdfs://server.companyname.com:8020/apps/hive/warehouse/my-database.db/test_table_partitioned

$ hadoop fs -ls /apps/hive/warehouse/my-database.db/
drwxrwxrwx   - database_admin         hadoop          0 2017-01-04 14:04 /apps/hive/warehouse/my-database.db/test_table_partitioned

任何人都可以做任何事情:)

4

0 回答 0