Hive 对视图的权限未在 Spark 中继承

Hive permissions on view not inherited in Spark

我已经在 Hive 中创建了镶木地板 table test_table。其中一个分区的位置是 '/user/hive/warehouse/prod.db/test_table/date_id=20210701'

基于此创建视图 table:

create view prod.test_table_vw as
select date_id, src, telephone_number, action_date, duration from prod.test_table

然后授予某些角色select特权:

GRANT SELECT ON TABLE prod.test_table_vw TO ROLE data_analytics;

然后具有此角色的用户尝试使用来自 pyspark 的 spark.sql() 查询此数据:

sql = spark.sql(f"""SELECT DISTINCT phone_number
            FROM prod.test_table_vw
            WHERE date_id=20210701""")
sql.show(5)

此代码 returns 权限被拒绝错误:

Py4JJavaError: An error occurred while calling o138.collectToPython.
: org.apache.hadoop.security.AccessControlException: Permission denied: user=keytabuser, access=READ_EXECUTE, inode="/user/hive/warehouse/prod.db/test_table/date_id=20210701":hive:hive:drwxrwx--x

我无法授予此 table 的 select 权限,因为其中包含一些敏感字段,这就是我创建列列表有限的视图的原因。

问题:

为什么 Spark 忽略 Hive 的 select 视图权限?以及如何解决这个问题?

这是 Spark 的限制:

When a Spark job accesses a Hive view, Spark must have privileges to read the data files in the underlying Hive tables. Currently, Spark cannot use fine-grained privileges based on the columns or the WHERE clause in the view definition. If Spark does not have the required privileges on the underlying data files, a SparkSQL query against the view returns an empty result set, rather than an error.

引用link.