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)
奇妙なことに、ハイブを使用してファイルの内容を読み込もうとしているだけで、書き込もうとはしていません。
奇妙なことに、次のようにテーブルを分割すると、同じ問題は発生しません。
database_admin として:
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
誰でもこれを説明できますか?
私が気付いた興味深い点の 1 つは、2 つのテーブルの 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
誰でも何でもできます:)